关于dll代码里LoadLibrary后,运行报错的有关问题
关于dll代码里LoadLibrary后,运行报错的问题?
方法一:
工程中有
EasyUSB3250.h
EasyUSB3250.lib
EasyUSB3250.dll
在“属性-输入-附加依赖项”中增加 EasyUSB3250.lib
打开EasyUSB3250.h中有
int __stdcall LPC3250_ReadData(int siPipeNum, unsigned char *pucRcvBuf, int siReadLen, int siWaitTime);
在代码中
方法二:
工程中有
EasyUSB3250.h
EasyUSB3250.lib
EasyUSB3250.dll
在代码中
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
问题:
方法二中,究竟哪个环节出了问题?
------解决方案--------------------
typedef int (WINAPI *MYPROC) (int, unsigned char *, int, int);
方法一:
工程中有
EasyUSB3250.h
EasyUSB3250.lib
EasyUSB3250.dll
在“属性-输入-附加依赖项”中增加 EasyUSB3250.lib
打开EasyUSB3250.h中有
int __stdcall LPC3250_ReadData(int siPipeNum, unsigned char *pucRcvBuf, int siReadLen, int siWaitTime);
在代码中
- C/C++ code
#include "EasyUSB3250.h" ::LPC3250_WriteData(1, sendbuf, 10, 1000); //通过逻辑端点1的OUT端口发送10字节数据
方法二:
工程中有
EasyUSB3250.h
EasyUSB3250.lib
EasyUSB3250.dll
在代码中
- C/C++ code
typedef int (*MYPROC) (int, unsigned char *, int, int); HINSTANCE hInstLib; MYPROC prod; hInstLib = ::LoadLibrary("EasyUSB3250.dll"); if (NULL != hInstLib) { prod = (MYPROC)GetProcAddress(hInstLib, "LPC3250_WriteData"); prod(1, sendbuf, 10, 1000); //通过逻辑端点1的OUT端口发送10字节数据 ::FreeLibrary(hInstLib); }
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
问题:
方法二中,究竟哪个环节出了问题?
------解决方案--------------------
typedef int (WINAPI *MYPROC) (int, unsigned char *, int, int);