This is my C++ call
Code:
reinterpret_cast< Error ( __cdecl*)(int,int)> (GetProcAddress(Mydll::GetInstance()->ReturnDLLInstance(), "add"))(1,10)
Code:
Error __cdecl add(int,int);
|
Newbie Member
|
|
| 24May2011,05:06 | #1 |
|
I want to call a pure C style function from a dll in my C++ program. I tried casting my function pointer using reinterpret_cast to __cdecl and still the calling convention of _stdcall seems to be preserved. I am new to Windows C++ programming.
This is my C++ call Code:
reinterpret_cast< Error ( __cdecl*)(int,int)> (GetProcAddress(Mydll::GetInstance()->ReturnDLLInstance(), "add"))(1,10) Code:
Error __cdecl add(int,int); |
|
Mentor
|
![]() |
| 24May2011,12:09 | #2 |
|
Usually to call C from C++ you just need to extern "C" the prototype:
Code:
extern "C"
{
Error add(int,int);
}
|
|
Newbie Member
|
|
| 24May2011,21:59 | #3 |
|
Thanks! But what if I cannot work with the C code.I just have it as a dll. In that case is there a work around??
|
|
Mentor
|
![]() |
| 25May2011,04:42 | #4 |
|
extern "C" is C++ code, not C code. This is what you put in the C++ code to make it call the function in the DLL. You still need a prototype, and you extern "C" it to stop the compiler mangling the names, then the linker resolves the call.
|