我是新来的DLL世界。我得到了一个Win32 DLL,它有很多功能。需要从C++调用这些DLL函数从C++调用Win32 DLL
我想调用CreateNewScanner
,它创建一个新的扫描器对象并以C++获取结果。在DLL中提到 功能是:
BOOL CreateNewScanner(NewScanner *newScan);
和NewScanner
是struct
,如下,
// 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++,这里是我管理的,
#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??
}
}
我编辑了这个问题只是添加更好的文本格式。 –