Best Approach
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.interop.

Post a new message to this list...

Mike Carr
Instaed of throwing all of my problems one-by-one I decided to put down what
I am trying to do and find out the best approach.

There is a common custom Interface that several apps use (these are written
in C++), we will call this interface ITestExec. There is another
application that Proxy's this interface that is written in C++. We will
call this TestExecMarshall.dll.

What I did was added a reference to the TestExecMarshall.tlb

I then created a C# dll with the interface:

[InterfaceType(ComInterfaceType.InterfaceIsIDispatch),
Guid("...")]
public interface ITestExec
{
int sendTestStop();
}

I created a class that inherited the Interface:
[Guid("..."),
ClassInterface(ClassInterfaceType.AutoDual),
ComSourceInterfaces(typeof(ITestExec)),
ProgId("MyTestExec.TestExec")]
public class TestExec : ITestExec
{
public int sendTestStop()
{
MessageBox.Show("sendTestStop() called");
return 0;
}
}

I created a C++ client to test it out:
#import "TestExecMarshal.tlb" no_namespace

::ITestExecPtr m_pTestExec;

CoInitializeEx(NULL,COINIT_MULTITHREADED);

try
{
long hr = m_pTestExec.CreateInstance("MyTestExec.TestExec");
m_pTestExec->sendTestStop();

"Run-Time Check Failure #0 - The value of ESP was not properly saved across
a function call. This is usually a result of calling a function declared
with one calling convention with a function pointer declared with a
different calling convention."

}

but if I import the tlb of c# dll, it works. Any ideas?

--
MICHAEL CARR

Reply to this message...
 
    
Robert Jordan
Hi Mike,

[Original message clipped]

The [ComImport]-attribute is missing. When you regasm the assembly,
the original ITestExec registry settings get overwritten, which
is not always harmless.

[Original message clipped]

[...]

> but if I import the tlb of c# dll, it works. Any ideas?

There is a mismatch between TestExecMarshall.tlb and
your C# interop definition of ITestExec, probably due
to the missing [ComImport].

bye
Rob
Reply to this message...
 
    
Mike Carr
Thanks, that helped, but I still had a problem. I found that my interface
was not in the same order as in the factoryexec.tlb and class. Once I got
everything in order my problems went away. That was fun. Is there an
attritubute that sets the order? Or does it just have to be in the same
order?

--
MICHAEL CARR

"Robert Jordan" <Click here to reveal e-mail address> wrote in message
news:chak7h$udf$04$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.Runtime.InteropServices.ClassInterfaceType
System.Runtime.InteropServices.ComInterfaceType
System.Windows.Forms.MessageBox




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com