By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,260 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

__cdecl callback function with P/Invoke

P: n/a
Hi!
I have a .dll library, with some exported function, which looks something
like this:

extern "C" {
int exported_f (int (__cdecl *callback) (int a, int b)) ;
}

now, I want to invoke this function wihtin the managed code and supply my
managed delegate function poiter as callback. I use DllImport, we know how
to do this ;)
The problem is that: when the function pointer parameter in exported
function is __stdcall, everythig works just fine. But how can I use
delegates for __cdecl callback function pointers ?..
I found CallingConventions, but this is only valid for imported function
itself, not for its parameters :((
Please, help me ! (sorry for my poor english ;)

--
Pawel

Jul 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

You can not do this in C#/VB.NET. An option might be to write a MC++ wrapper
for the library function and then let the MC++ callback call to your
delegate.

Hope this helps
--
Chris Taylor
http://dotnetjunkies.com/WebLog/chris.taylor/
"pawel" <pa************@interia.pl> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi!
I have a .dll library, with some exported function, which looks something
like this:

extern "C" {
int exported_f (int (__cdecl *callback) (int a, int b)) ;
}

now, I want to invoke this function wihtin the managed code and supply my
managed delegate function poiter as callback. I use DllImport, we know how
to do this ;)
The problem is that: when the function pointer parameter in exported
function is __stdcall, everythig works just fine. But how can I use
delegates for __cdecl callback function pointers ?..
I found CallingConventions, but this is only valid for imported function
itself, not for its parameters :((
Please, help me ! (sorry for my poor english ;)

--
Pawel

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.