Joachim said:
Do I have to use COM or is there another way? I feel the use of COM forces
the user of the dll to write so much more extra code and it is not the way
that I want it.
No, there is not. Talking about COM interop from VB, there is no "extra"
code to write, all you need to do is create an instance of the object and
call it's methods and properties. From C++, you have to write some extra
code, but this is more like template code,basically what you need is
initialize COM, create an instance of the object and call it's methods,
basically not more complex than calling a C++ class methods complex, really.
Sure you need to take care about data marshaling, but this is something
you'll have to do anyway when exchanging data across disparate systems.
Herewith a simple sample illustrating the process...
// interface
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid("...................................")]
public interface IFoo{
void Run();
}
// C#
// class implementing IFoo
[ClassInterface(ClassInterfaceType.None)]
[Guid("................................................")]
[ProgId("someNamespace.Foo")]
[ComVisible(true)]
public sealed class Foo: IFoo {
public Foo() {}
public void Run()
{
....
}
}
// C++ client
// Import the typelib produced by running the regasm utility on your .NET
assembly.
#import "myDotNetLib.tlb" no_namespace
// Init COM for mutithreaded access ...
HRESULT hres = CoInitializeEx(0, COINIT_MULTITHREADED);
...
// Create an instance of Foo, using VC++ COM smart pointer support
IFooPtr m_ptrFoo(__uuidof(Foo));
// call it's meyhods
m_ptrFoo->Run();
....
// unitialize COM when done with it
CoUninitialize();
Willy.