Code: Select all
int intMyReturnVal = function1(1, 5);
Code: Select all
#include <cstdlib>
#include <stdio.h>
#include <windef.h>
#include <windows.h>
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
/* get handle to dll */
HINSTANCE hGetProcIDDLL = LoadLibrary("C:\\netbeansWorkSpace\\test2dll\\dist\\Debug\\MinGW-Windows\\libtest2dll.dll");
/* get pointer to the function in the dll*/
FARPROC lpfnGetProcessID = GetProcAddress(HMODULE (hGetProcIDDLL),"function1");
/*
Define the Function in the DLL for reuse. This is just prototyping the dll's function.
A mock of it. Use "stdcall" for maximum compatibility.
*/
typedef int (__stdcall * pICFUNC)( int , int);
pICFUNC function1;
function1 = pICFUNC(lpfnGetProcessID);
/* The actual call to the function contained in the dll */
printf( "got passed before dll value " ) ;
int intMyReturnVal = function1(1, 5);
printf( "got passed retreviing value " ) ;
/* Release the Dll */
FreeLibrary(hGetProcIDDLL);
/* The return val from the dll */
printf( "the number from the dll is = %d" , intMyReturnVal ) ;
return 0;
}
When I created the dll I used this as a header file
Code: Select all
#ifndef DLLHEADER_H
#define DLLHEADER_H
extern "C" {
__declspec(dllexport) int __stdcall function1( int i , int j );
__declspec(dllexport) int __stdcall function2( int i , int j );
__declspec(dllexport) int __stdcall function3(int i , int j) ;
}
#endif /* DLLHEADER_H */
Code: Select all
#include "dllheader.h"
__declspec(dllexport) int __stdcall function1( int i , int j )
{
return i + j ;
}
__declspec(dllexport) int __stdcall function2( int i , int j )
{
return i - j ;
}
__declspec(dllexport) int __stdcall function3( int i , int j )
{
return i * j ;
}
when i try to run the program and call the function in the library using loadlibrary ,...etc
Anybody know?
Is this some cdel or stdcall incompatibility issue because other then the calling convention I don't know what could be going wrong.