Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ DLL calling a function implemented in the consuming application
    primarykey
    data
    text
    <p>How to call a post-implemented function (e.g., function pointers or virtual functions implemented in the consuming application) with a complex return type from a DLL function?</p> <p>I tried the following scheme but got errors.</p> <p>Test.h:</p> <pre><code>#ifdef _DLL_IMPL #define DLL_EXPORT __declspec(dllexport) #else #define DLL_EXPORT __declspec(dllimport) #endif typedef string (*test)(void); extern DLL_EXPORT test __test; DLL_EXPORT int launch(); </code></pre> <p>Test.cpp:</p> <pre><code>#define _DLL_IMPL #include "Test.h" test __test = 0; int launch() { string a = __test(); return 0; } </code></pre> <p>And the consuming application goes like:</p> <p>Main.cpp:</p> <pre><code>#include "Test.h" #pragma comment(lib, "Test.lib") string test_impl() { string a = "test"; return a; } int main(int args, char** argv) { __test = &amp;test_impl; return launch(); } </code></pre> <p>And I got a subsequent error message:</p> <pre><code>Windows has triggered a breakpoint in TestRun.exe. This may be due to a corruption of the heap, which indicates a bug in TestRun.exe or any of the DLLs it has loaded. This may also be due to the user pressing F12 while TestRun.exe has focus. The output window may have more diagnostic information. </code></pre> <p>I don't know what exactly was going on. Error also occurred when I tried a return type of a char pointer, which would be created in the consuming application using a new operator and would be freed in a DLL function using a delete[] operator.</p> <p>Can someone explain the reason why the error happens and suggest me some solution to this scheme? Thank you!</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.
 

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