.NETGURU
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




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification