RE: How to access C# library from a C++ client.
From: Tor Bådshaug (TorBdshaug_at_discussions.microsoft.com)
Date: 11/17/04
- Previous message: Tor Bådshaug: "RE: Use DLL in Windows app problem"
- In reply to: Ghanashyam: "How to access C# library from a C++ client."
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 17 Nov 2004 15:24:02 -0800
What happens in your case when a type library is to be generated for your
assembly, is that you are relying on a COM interop mechanism that
automatically generates an interface that defines all the public members of
your class. According to MS, this default mechanism should work, but I've
tried the same as you (that is, relying on the default mechanism) and got the
same "problems".
MS states that " it is far better to provide explicit interfaces", as I've
done in my code sample below (and I can confirm that this actually causes the
created type library to be a lot more useful)
With the type library in place, the following sample may be helpful :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcominteropsamplecomclientnetserver.asp
You also need to choose whether the assembly containing the
classes/interfaces you want to expose to COM should be private or shared
assemblies -
Private assemblies are available only to clients in the same directory
structure as the assembly; shared assemblies are available to any local COM
application
To create a shared assembly, strong name it using sn -k and register it in
the Global Assembly Cache using gacutil.
Hope this helps.
Modified code sample with explicit interface:
using System;
namespace COMExposePOC
{
public class Class1 : ICOMVisiblePOC
{
public Class1()
{
}
public void HelloWorld()
{
//Implementation of ICOMVisiblePOC.HelloWorld
}
}
public interface ICOMVisiblePOC
{
void HelloWorld();
}
}
Tor Bådshaug
tor.badshaug [//at\\] bekk.no
- Previous message: Tor Bådshaug: "RE: Use DLL in Windows app problem"
- In reply to: Ghanashyam: "How to access C# library from a C++ client."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|