473,387 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

__cdecl callback function with P/Invoke

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
1 5212
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Sagar Choudhary | last post by:
I m using a library function which need to be passed a function as parameter. If i declare the function as int (void *, int, char **, char **) it throws an error cannot convert parameter from...
3
by: vinu_gt | last post by:
Hi All, I had a question about stdcall and cdecl calling convention related to Visual Studio 6.0 I have a console project and in Project->setting->C++->Code Generation The "calling...
4
by: H.B. | last post by:
Hi, I successfully implement a static callback function for my dll usign delegates. Now, I need to use member function instead of static function. How can I make that (in Managed C++). Hugo
2
by: David | last post by:
Hi all, I am new to .Net environment. I have created a flat non-COM DLL from Visual C++ 6.0. It stores up a function pointer from caller, create a worker thread via WIN32 API, and then call...
2
by: pawel | last post by:
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...
5
by: Maxwell | last post by:
Hello, Newbie question here. I have a VS.NET 2003 MC++ (not C++/cli) project where I have a managed class reference in a unmanaged class...simple enough. To keep things short I am for the most...
5
by: archana | last post by:
Hi all, I am having one confusion regarding invoking method through threading. I have delcared one delegate. and i have one class which has parameter of type delegate which i declared. I...
5
by: sajin | last post by:
Hi All.. We are using VB .Net 2005 for implementing an API. API needs to generate events. For this client wants us to use Windows Callback (delegate implementation). The intention of using...
6
by: Ole Nielsby | last post by:
VC has a __cdecl specifier which allows functions and methods to be called with varying parameter count. (I understand this is the default for functions in general but in VC, instances use...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.