Why can't Marshal::GetDelegateForFunctionPointer() work on C++?

  • Thread starter Thread starter Guest
  • Start date Start date
Hi,

Rory Plaire said:
After searching and experimentation, I found the note in the remarks
section
of the MSDN doc on Marshal::GetDelegateForFunctionPointer
(http://msdn2.microsoft.com/en-us/li...es.marshal.getdelegateforfunctionpointer.aspx)
-

You cannot use this method with function pointers obtained through
C++...

Why not?

I guess the documentation is talking about class function pointers. Native
function pointers and class function pointers are of different size and need
different code to be called so they are not compatible.
 
Rory Plaire said:
After searching and experimentation, I found the note in the remarks
section
of the MSDN doc on Marshal::GetDelegateForFunctionPointer
(http://msdn2.microsoft.com/en-us/li...es.marshal.getdelegateforfunctionpointer.aspx)
-

You cannot use this method with function pointers obtained through
C++...

Why not?

Calling convention, I would guess. That method probably assumes stdcall,
while C++ uses thiscall except for variable length argument lists which use
cdecl.

It also mentions that you can't use a function pointer to a managed method,
and if you compile your C++ code with /clr then chances are your C++
functions are MSIL (managed).
 

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

Back
Top