Note that there are some explanatory texts on larger screens.

plurals
  1. POPInvoke error when calling unmanaged (C++) function from C#
    primarykey
    data
    text
    <p>I have an unmanged C++ dll that I have written and tested. The unmanged code woks fine when built and run in an unmanged console app. The function declaration is shown below.</p> <pre><code>#ifndef IMPORT_MYLIB # define MYLIB_API __declspec(dllexport) #else # define MYLIB_API __declspec(dllimport) #endif namespace gsod_data_parsing { extern "C" { MYLIB_API int parse_raw_gsod_file_nocb( const char *path, int temp_threshold ); } } </code></pre> <p>I am trying to call this from a managed application. I declare the function in my C# file like this:</p> <pre><code> [DllImport("GSODDLL.dll")] public static extern int parse_raw_gsod_file_nocb( [MarshalAs(UnmanagedType.LPStr)] string path, int temp_threshold ); </code></pre> <p>These functions are then being executed on a couple parallel tasks like shown below:</p> <pre><code>// Start a task - this runs on the background thread... task1 = Task.Factory.StartNew(() =&gt; { int t1 = parse_raw_gsod_file_nocb(filePaths[i], this._frostTemp); return (t1 == 0); }, this._tokenSource.Token); </code></pre> <p>It appears to run fine at first but then (I believe when the function has finished executing) I get the following error.</p> <blockquote> <p>A call to PInvoke function 'Database Creator!Database_Creator.Form1::parse_raw_gsod_file_nocb' 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> <p>I saw a similar question <a href="https://stackoverflow.com/questions/2303533/a-call-to-pinvoke-function-has-unbalanced-the-stack-when-including-a-c-dll-into">here</a> but I don't quite understand the accepted answer.</p> <p>Anyone have any ideas? Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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