Click to See Complete Forum and Search --> : Wrapping unmanaged C++ dll to use in a Managed C# CF application


Vladimir_Kost
March 1st, 2008, 08:22 AM
Hello everybody.
I have faced the next problem:
I need to use a class written in C++ in a C# client application under Windows Mobile.
The class is stored in a dll. For a desktop solution I suppose the best way is to write a managed C++ wrapper dll as described for example in
http://www.codeguru.com/Cpp/Cpp/cpp_managed/interop/article.php/c6867/

But as CF doesn't support managed C++ this solution can't be used.

Does anybody could advice an alternative? Any suggestion will be appreciated.
The class is rather complex, here is a fragment of its header:

CConnectionManager(IN const IConnectionEventHandler & ConnEventHandler);
~CConnectionManager(void);

virtual ConnectionError Connect(IN const wstring & strAddress, IN const AddressType adrType, IN const SessionType sessType);
virtual ConnectionError Disconnect(void);
virtual ConnectionError Accept(void);

ConnectionError, AddressType and SessionType are simple enumeration types. So I don't think they will pose big problems. The methods aren't static so I suppose I can only use their full decorated names as entrypoints if I use the DllImport attribute. But it seems to be not very aesthetic. Perhaps any other way exists?
The IConnectionEventHandler parameter is also a problem. It realizes an external event handler that I suppose should be converted into delegates. But I'm rather a beginner in .NET and I don't know exactly how to do it.

Any modifications to the native class code are also possible if they aren't too complex and can result in a really good solution. Perhaps I should convert my class into a COM object?

Waiting for your recommendations.

Regards,
Vladimir