How to pass delegate to unmanaged function from MC++ ?

  • Thread starter Thread starter Alexander Arlievsky
  • Start date Start date
A

Alexander Arlievsky

Hi,
I have mixed mode dll, which contains files with managed objects written in
MC++, and files with regular "C" functions.
One of those functions receives function pointer as parameter. I want to
pass to it delegate to managed object method.
I know how to do it from C# - DllImport etc. I suspect I can declare "stub"
method using those attributes, so it will actually reference "C" method, and
call this stub, letting marshaler to do the job. This will require to make
this "C" function exported. Is there another way to do it without simulating
C# way ?

--
==============================
Alexander Arlievsky
(e-mail address removed)
"The best tools for debugging are brains"
==============================
 
Hi Alex,

As far as I know - the official answer is no.

The method "similar" to c# method (that you don't want to use) can be
viewed here:
http://msdn.microsoft.com/library/d...ry/en-us/cpguide/html/cpconcallbacksample.asp

BUT, though bit controversal, there is a method, in such you
can switch between clr calling convention and other calling
conventions: http://www.codeproject.com/managedcpp/cbwijw.asp

Don't foget to keep the delegate reference alive ...

Also if it helps you, you can use the "#pragma managed/unmanaged"
directive
to break code into managed/unmanaged parts.

Igal.
 
Back
Top