MFC调用一个DLL

来源:百度知道 编辑:UC知道 时间:2024/07/02 20:06:20
我有个dll是在VC下使用的
现在我的一个MFC程序也想使用它

我把TickerApi.dll文件放到了Debug下面了
因为我是在这里面编译的

然后我确认了文件名字没有错误

char szPath[MAX_PATH];
szPath[MAX_PATH-1] = 0;
::GetModuleFileName(NULL, szPath, MAX_PATH-1);
char *pDest = strrchr(szPath, '\\');
*pDest = 0;
_snprintf(szPath, MAX_PATH-1, "%s\\TickerApi.dll", szPath);

HINSTANCE hInstTApiLib;
if ((hInstTApiLib = LoadLibrary (szPath)) == NULL)
{
MessageBox("can,t");
}
但是问题依旧 还是hInstTApiLib=NULL啊
我都有一点小崩溃了
调用.dll和一般的配置文件.ini是不是一样的啊

szPath确认无误?把TickerApi.dll文件放到了Debug下面了还用这么复杂干嘛?直接if ((hInstTApiLib = LoadLibrary (L"TickerApi.dll")) == NULL) 或者
if ((hInstTApiLib = LoadLibrary ("TickerApi.dll")) == NULL)不就结了?我这样用过没什么问题。

楼主确认路径对吗?前面取路径的部分感觉很诡异。。。

用CString吧
char szPath[MAX_PATH];
::GetModuleFileName(NULL, szPath, MAX_PATH);
CString strPath = szPath;
strPath = strPath.Left(strPath.Find('\\'));
strPath = strPath + "\\TickerApi.dll";
...

应该就行了,反正也用了MFC了

MFC不行
有心无力