I'm guessing you probably didn't want to post your code as a solution but never mind. There are a few odd things here but I don't know for sure if any of them are the cause of the error message you're seeing.
You're using Dynamic/Late/Runtime/Explicit loading of the Dll in this code which is fine, it means that you should be able to run the code in Debug and set a Breakpoint to stop execution before the error occurs. If you can do this there's a very good chance of solving the problem.
The first thing is that
hGetProcIDDLL
needs to be checked to see if you actually managed to load the Dll, given that you say the Dll is called 'MyDll' and the file name you've tried to load is 'libCppApplication_1' I would say that's unlikely.
Once the Dll is loaded there's the call to
GetProcAddress
. Your way of casting is slightly unconventional and may cause confusion. I prefer the long hand explicit C++ cast for these scenarios especially for test code.
FARPROC lpfnGetProcessID = GetProcAddress( reinterpret_cast< HMODULE >(hGetProcIDDLL),"demo");
There's one further issue with this related to calling convention. Your code comments state that the function uses
__stdall
Pascal convention. Confusingly this is stated as for maximum compatability, unfortunately
__stdcall
has very poor compatability especially between Microsoft and Borland compilers. If the Dll does in fact export this function as
__stdcall
then the name is likely but not certain to have an "_" automatically prepended to it making it "_demo" or even "__demo". This depends on which compiler you're using on the back end of Netbeans and if it's GCC what options Netbeans is passing through to it.
To avoid these horrible "_" issues either change the Dll to use
__cdecl
'C' calling convention or examine the Dll binary with a tool like depends to determine exactly what name the compiler has exported.
Once you get this far and actually have a function pointer for your function the rest should go smoothly. If you get into any trouble remember the simple rule.
The module that allocates must be the module that frees In other words don't allocate anything, then pass it, then free it in the module it was passed into.
Happy
Dll
ing