Llamando Win32 DLL desde C ++
Soy nuevo en el mundo DLL. Me han dado una DLL de Win32 que tiene muchas funciones. Necesito llamar a estas funciones DLL desde C ++
quiero llamarCreateNewScanner
que crea un nuevo objeto de escáner y obtiene los resultados en C ++. La función mencionada en la DLL es:
BOOL CreateNewScanner(NewScanner *newScan);
yNewScanner
es unstruct
, como a continuación,
// Structure NewScanner is defined in "common.h" .
typedef struct{
BYTE host_no; // <- host_no =0
LONG time; // <- command timeout (in seconds)
BYTE status; // -> Host adapter status
HANDLE obj; // -> Object handle for the scanner
}NewScanner;
¿Cómo llamaré a esta función? Comencé con C ++ y aquí es lo que manejé,
#include <iostream>
#include <windows.h>
using namespace std;
int main(){
HINSTANCE hInstance;
if(!(hInstance=LoadLibrary("WinScanner.dll"))){
cout << "could not load library" << endl;
}
/* get pointer to the function in the dll*/
FARPROC handle = GetProcAddress(HMODULE(hInstance), "CreateNewScanner");
if(!handle){
// Handle the error
FreeLibrary(hInstance);
return "-1";
}else{
// Call the function
//How to call here??
}
}