Dynamicly loading a DLL / C++ / Builder

i have a basic DLL ( generated with C++Builder ) and i want to load that file "dynamicly" without DEF file loading or creating with using LoadLibrary GetProcAddress Casting and FreeLibrary :

// MY DLL Implementation ----
[code]
#include
#include
#include "dllfile.h"

#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}

EXPORT int __stdcall Function( int a, int b) {
std::cout << "Toplam = " << (a+b) << std::endl;
return 0 ;
}
[/code]
// dllfile.h ------
[code]
#define EXPORT extern "C" __declspec( dllexport )
EXPORT int __stdcall Function( int a, int b) ;
[/code]
I have compiled with no error and i have created a DLL successfully. But when i call my function with console C++ application

[code]
typedef int (__stdcall *ptrFunc) (int, int) ;
ptrFunc Func ;

int main(int argc, char* argv[])
{

HINSTANCE handle = LoadLibrary("mydll.dll") ;
Func = static_cast < ptrFunc > ( GetProcAddress(handle,"Function") );
Func(4,5) ;
return 0;

}
[/code]

the casting error occurs;
[b]E2031: Cannot cast from int (__stdcall *)() to "int (__stdcall *)(int, int)[/b]

what can i do ?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories