I wrote a C DLL and some C # code for testing, including this DLL and the execution of functions from it. I am not very good at this process and get a PInvokeStackImbalance exception when my DLL function is called from C # source code. The code is as follows (I commented on most of the code to isolate this problem):
C # inclusion code:
using System;
using System.Runtime.InteropServices;
using System.IO;
namespace TestConsoleGrids
{
class Program
{
[DllImport("LibNonthreaded.dll", EntryPoint = "process")]
public unsafe static extern void process( long high, long low);
static void Main(string[] args)
{
System.Console.WriteLine("Starting program for 3x3 grid");
process( (long)0, (long)0 );
System.Console.ReadKey();
}
}
}
C ++ DLL Function Code
extern "C" __declspec(dllexport) void process( long high, long low );
void process( long high, long low )
{
}
Visual Studio generated the dllmain code (I do not understand this construct, so I enable it)
#include "stdafx.h"
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
Exception Details:
PInvoke 'TestConsoleGrids! TestConsoleGrids.Program:: process' . , , PInvoke . , PInvoke .