Note that there are some explanatory texts on larger screens.

plurals
  1. POA call to PInvoke function has unbalanced the stack when including a C DLL into C#
    primarykey
    data
    text
    <p>I have written a C DLL and some C# code to test including this DLL and executing functions from it. I am not too familiar with this process, and am receiving a PInvokeStackImbalance exception whenever my DLL function is called from the C# source code. The code is as follows (I have commented most code out to isolate this problem):</p> <p>C# Inclusion code:</p> <pre><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(); } } } </code></pre> <p>C++ DLL Function Code</p> <pre><code>extern "C" __declspec(dllexport) void process( long high, long low ); void process( long high, long low ) { // All code commented out } </code></pre> <p>Visual Studio generated dllmain code (I do not understand this construct, so I am including it)</p> <pre><code>// dllmain.cpp : Defines the entry point for the DLL application. #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; } </code></pre> <p>The details of the exception are:</p> <blockquote> <p>A call to PInvoke function 'TestConsoleGrids!TestConsoleGrids.Program::process' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload