vc调用动态连接库中多个函数如何做?和调用其中一个函数有什么区别?急用,谢谢!!!

来源:百度知道 编辑:UC知道 时间:2024/06/27 06:16:39
vc下编译正确但是运行会弹出窗口报错
我直接动态加载dll,没使用.h和Lib文件,谢谢,我写的程序编译通过,但运行弹出窗口说是调用函数错误还是内存溢出.
HINSTANCE hInst;
typedef DWORD(* open)(LPCSTR pszName,LPDWORD pdwSessionId);
typedef DWORD(* get)(DWORD dwSessionId,LPDWORD pdwStatus,BOOL bConnectErr);
typedef DWORD(* close)(DWORD dwSessionId);
open OpenSiiPrinterA;
get GetSiiPrinterStatus;
close CloseSiiPrinter;
hInst = LoadLibrary("C:\\WINDOWS\\system32\\SIILTP9API.DLL");

OpenSiiPrinterA=(open)GetProcAddress(hInst,"OpenSiiPrinterA");
GetSiiPrinterStatus=(get)GetProcAddress(hInst,"GetSiiPrinterStatus");
CloseSiiPrinter=(close)GetProcAddress(hInst,"CloseSiiPrinter");

errcd=OpenSiiPrinterA(prtname,hPrinter);

if(errcd)
{

}
else
{

}

FreeLibrary(hInst);

但有网友说"显式链接时不需要使用相应的Lib文件或头文件",
如果需要我没有这些文件只有dll文件,有办法生成吗?谢谢!

你拿到.h文件和Lib文件直接调用就可以;多个函数和一个函数没区别

代码贴出来看

You can only obtain the export ordinal if the DLL you are linking to was built with a module definition (.DEF) file, and if the ordinals are listed with the functions in the EXPORTS section of the DLL's .DEF file.

这是MSDN的原话,意思说你要获得DLL导出函数符号对应的地址必须有.DEF文件,这个文件可以在编译DLL时生成。像你GetProcAddress(hInst,"OpenSiiPrinterA") 中的"OpenSiiPrinterA"就是导出函数的符号,如果没有DEF或者LIB 文件你是得不到OpenSiiPrinterA 这个函数指针的。像你描述的情况你可以看OpenSiiPrinterA这个指针一定是空的,所以才有访问违例错误。