473,803 Members | 3,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pinvoke and callbacks

I have created a simple test C# console program that calls an unmanaged C
subroutine in a DLL where one of the arguments is a callback to the C# code.
I noticed that when the callback has no paramaters, it works fine. But when
there are parameters, I get the exception: "Runtime failure check #0: The
value of ESP not properly saved..."

Here are the facts: The delegate declaration:
public delegate int querydlg(IntPtr pEnv, string str);
The signature of the Pinvoke method:
[DllImport("Clip s.DLL", CharSet=CharSet .Ansi)]
public static extern bool EnvAddRouter(qu erydlg queryFunction);
The callback method:

public static int FindTrace(IntPt r pEnv, string logicalName)
{
return logicalName.Com pareTo("wtrace" )==0 ? 1 : 0;
}
the function call within the C# program:
querydlg fnpt = new querydlg(FindTr ace);
EnvAddRouter(fn pt);
The declaration of the the function call setting up the callback:
extern BOOLEAN EnvAddRouter(in t (*queryFunction )(void *,char *));
And the unmanaged call to the callback function inside the c routine:
if ((*currentPtr->query)(theEnv, logicalName) == 1))


where:
void *theEnv;
char *logicalName;

Using the debugger, I saw that the arguments are passed from the unmanaged
code to the callback routine correctly.

I am using version 1.0 of the IDE. Is this a bug in the CLR?

PS This is not my only example, I have other calls with similar problems.

Nov 16 '05 #1
2 2994
Hi,

<snip>

Probely a problem with calling convention, try :

extern BOOLEAN EnvAddRouter( int (__stdcall *queryFunction) (void *,char
*) );

-or- change project properties to use stdcall as default.

HTH,
greetings


And the unmanaged call to the callback function inside the c routine:
if ((*currentPtr->query)(theEnv, logicalName) == 1))


where:
void *theEnv;
char *logicalName;

Using the debugger, I saw that the arguments are passed from the unmanaged
code to the callback routine correctly.

I am using version 1.0 of the IDE. Is this a bug in the CLR?

PS This is not my only example, I have other calls with similar problems.


Nov 16 '05 #2
By making the compiler switch /Gz (__stdcall calling convention), the
callback now returns.

Thanks!
"BMermuys" <so*****@someon e.com> wrote in message
news:pg******** **************@ phobos.telenet-ops.be...
Hi,

<snip>

Probely a problem with calling convention, try :

extern BOOLEAN EnvAddRouter( int (__stdcall *queryFunction) (void *,char
*) );

-or- change project properties to use stdcall as default.

HTH,
greetings


And the unmanaged call to the callback function inside the c routine:
>> if ((*currentPtr->query)(theEnv, logicalName) == 1))


where:
void *theEnv;
char *logicalName;

Using the debugger, I saw that the arguments are passed from the unmanaged code to the callback routine correctly.

I am using version 1.0 of the IDE. Is this a bug in the CLR?

PS This is not my only example, I have other calls with similar problems.


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2298
by: Melissa Wallis | last post by:
I have a class with 5 callbacks. Two of the callbacks work fine but the others don't. The main difference is that the callbacks that don't work are composed of a sequence of structs. I noticed a comment about this same problem on the web but no solution was noted. What makes the callbacks with the sequences so different? It seems that when one of the callbacks with a sequence is called it just hangs. I am talking to a TAO orb from...
7
2349
by: savage | last post by:
hey all i need to convert an unmanaged c++ dll and header to c#, ive done the header structures but having problems with pinvoke signatures method 1: typedef int (_stdcall *pOmniConnect) (char * IpAddress, unsigned int Port, unsigned int Timeout, unsigned char EncryptionKey, HWND NotifyWindow);
5
3247
by: Christopher Jastram | last post by:
I'm a self-taught programmer, so this might be a pretty dumb question. If it is, please point me in the right direction and I shall apologize profusely. I have a question regarding C++ and object members. Can anyone help? I'm writing a C++ wrapper for a fairly old programming interface to a document editing program that has no OOP whatsoever; only tons of structs. This program has different callbacks I'm supposed to implement for...
3
2677
by: John Smith | last post by:
I wrote some code in C in a dll which I would like to call from C#. However I'm stuck because of the strongly typed behavior of C# which makes limitations. Here are the prototypes for two functions which I have trouble mapping: int _SetOption(int nOption, void *pSetting); void *_GetDataField(int nType, int *npLength);
3
3470
by: Brett Robichaud | last post by:
I have created a simple background thread to make one pinvoke call into a DLL I've created. My Winforms app spawns the thread in the form load event then go about it's business. The problem is that my form appears to be blocked while the background thread is running. I am very familir with threads in unmanaged code but am just getting into them in C#. Are there issues I need to be aware of with regards to threading a simple pinvoke...
11
4657
by: Joe Martin | last post by:
Has anyone made use of PKWare's PKCDL.DLL for the Implode and Explode functions? I have been able to successfully define everything correctly and even get the invoked function (Explode) to run properly. This means data is being exploded properly, confirmed with CRC values and reviewing the actual data. However just before the unmanaged function exits, I get a null exception error. I am using:
8
6784
by: promko | last post by:
Hi! I need to call the following unmanged method: HFCI __cdecl FCICreate( void FAR* pv) I have written the next managed declaration: public static extern IntPtr FCICreate( IntPtr pv );
5
2830
by: vertigo | last post by:
Hello I use some win 32 API function for example: HANDLE CreateFile( LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile
1
6665
by: eastlands | last post by:
I need to use an unmanaged c++ dll which uses structs that contain callbacks and also functions. I have included the appropriate c++ definitials and my c# translations below. I first defined the parameters as c# structs, but when I tried the call (to RtcInitialize) I got the following error: MarshalDirectiveException Method's type signature is not PInvoke compatible. I then changed the structs to classes but now I get the following...
0
9703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.