Unmanaged C++ Dll, CallingConvention.ThisCall

G

Guest

Hi all!

I am trying to use an unmanaged Dll in C# CF. Most of it is object oriented, and - as constructors can't be invoked with dllimport - I added TestClass* CreateTestClass() and DeleteTestClass(TestClass* obj) functions and used IntPtr in C# to hold the instance.

In .NET Framework, it is possible to call all class methods by passing this IntPtr as first parameter if CallingConvention.ThisCall is specified. This property is not available in CF, does anyone know a workaround? Or will the only solution be to make changes to the DLL?

Any ideas or suggestions are welcome!

Thanks,
claudia
 
C

Chris Tacke, eMVP

You must change the DLL or write another class factory DLL that accepts the
pointer in all methods.

-Chris

Claudia Mitsch said:
Hi all!

I am trying to use an unmanaged Dll in C# CF. Most of it is object
oriented, and - as constructors can't be invoked with dllimport - I added
TestClass* CreateTestClass() and DeleteTestClass(TestClass* obj) functions
and used IntPtr in C# to hold the instance.
In .NET Framework, it is possible to call all class methods by passing
this IntPtr as first parameter if CallingConvention.ThisCall is specified.
This property is not available in CF, does anyone know a workaround? Or will
the only solution be to make changes to the DLL?
 
P

Paul G. Tobey [eMVP]

You're going to be *much* better off to build a suitable C-style interface
to the DLL in unmanaged code, where you have control over everything, than
to try to fake the 'this' pointer in object calls to everything.

Paul T.

Claudia Mitsch said:
Hi all!

I am trying to use an unmanaged Dll in C# CF. Most of it is object
oriented, and - as constructors can't be invoked with dllimport - I added
TestClass* CreateTestClass() and DeleteTestClass(TestClass* obj) functions
and used IntPtr in C# to hold the instance.
In .NET Framework, it is possible to call all class methods by passing
this IntPtr as first parameter if CallingConvention.ThisCall is specified.
This property is not available in CF, does anyone know a workaround? Or will
the only solution be to make changes to the DLL?
 
P

Paul G. Tobey [eMVP]

You'd want to look up '__stdcall' in the eVC 4 help.

Paul T.

Josh Korn said:
Paul:

Is there any documentation you know of that details the calling convention?

Thanx.
Josh

----- Paul G. Tobey [eMVP] wrote: -----

You're going to be *much* better off to build a suitable C-style interface
to the DLL in unmanaged code, where you have control over everything, than
to try to fake the 'this' pointer in object calls to everything.

Paul T.

Claudia Mitsch said:
object
oriented, and - as constructors can't be invoked with dllimport - I added
TestClass* CreateTestClass() and DeleteTestClass(TestClass* obj) functions
and used IntPtr in C# to hold the instance. passing
this IntPtr as first parameter if CallingConvention.ThisCall is specified.
This property is not available in CF, does anyone know a workaround? Or will
the only solution be to make changes to the DLL?
 
G

Guest

Thanks both of you, I already considered the two options. Just wanted to make sure not to overlook the "best practice" for this case :)

sincerely
claudia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top