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?

Signature
MICHAEL CARR
Robert Jordan - 03 Sep 2004 21:29 GMT
Hi Mike,
> 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.
[quoted text clipped - 7 lines]
>
> I then created a C# dll with the interface:
The [ComImport]-attribute is missing. When you regasm the assembly,
the original ITestExec registry settings get overwritten, which
is not always harmless.
> [InterfaceType(ComInterfaceType.InterfaceIsIDispatch),
> Guid("...")]
> public interface ITestExec
> {
> int sendTestStop();
> }
[...]
> 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
Mike Carr - 07 Sep 2004 18:57 GMT
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?

Signature
MICHAEL CARR
> Hi Mike,
>
[quoted text clipped - 31 lines]
> bye
> Rob