Click here to Skip to main content
14,767,338 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I put a C# app together that calls some functions from a DLL. This is my function declaration:
[DllImport("c:\\users\\auror\\source\\repos\\dll1\\debug\\Dll1.dll")] public static extern int MM_HELPABOUTME();

Within my C# app, I can call a messagebox from a DLL routine, no problems. BUT, when I click the 'ok' button, the C# app terminates. I thought the C# app is suppose to keep going, but it terminates. What's going on?? Can anyone provide an answer why. Thanks.

====== Moved from solution:

Just a simple C# routine.
private void button1_Click(object sender, EventArgs e)
{
int ic;

ic = MM_HELPABOUTME();
/// ic = MM_ABOUTDLL();
}

My DLL function declaration:
[DllImport("c:\\users\\auror\\source\\repos\\dll1\\debug\\Dll1.dll")]
public static extern int MM_HELPABOUTME();

I'm learning from these problems, cause I have more dll function calls to be placed in this C# app.

Thanks. Is this what you are looking for??

What I have tried:

I just rewrote the DLL to avoid name mangling and the DLL rebuild ok. I'm just trying to marry the C# app and the DLL file together and make it work. Any help, sure would be helpful.
Posted
Updated 28-Jan-20 18:15pm
v3
Comments
MadMyche 28-Jan-20 21:28pm
   
The actual code for the routine would be helpful
Rob Philpott 30-Jan-20 7:44am
   
Is this still a problem? If so, could you post the C++ prototype - it might be a calling convention mismatch.

1 solution

Chances are that an exception is thrown somewhere on the way.

Try putting the call inside a try-catch - C# Reference | Microsoft Docs[^] and catch all exceptions. Use the debugger to investigate what kind of exception is thrown, if any.

This should get you more information about the problem.

Of course one thing is to, using debugger, double check that no additional code is run after this call. For example if you have wired the click event twice, the other code block could close the application.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900