Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2004

Tip: Looking for answers? Try searching our database.

Best Approach

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike Carr - 03 Sep 2004 19:16 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.