用VC调用C写的DLL出错!

mudboy 2003-08-25 05:38:26
C的DLL我已在C下测试过,没问题,调用的原型如下:
SLogResult * getLogResult(char whereclause[300])

SLogResult * CLogPickDlg::LoadDLLGetLog(CString filter)
{
typedef UINT (CALLBACK* LPFNGETLOG)(char fi[300]);

HINSTANCE hInstance1;
LPFNGETLOG lpSquartRoot1;
hInstance1 = ::LoadLibrary("getlog.exe");
if (hInstance1 != NULL)
{

lpSquartRoot1 = (LPFNGETLOG)::GetProcAddress(hInstance1,"getLogResult");
if(!lpSquartRoot1)
{
::FreeLibrary(hInstance1);
AfxMessageBox("定位动态链接库方法出错!!!");
}
else
{
char fil[300];
const char *fil1=NULL;
fil1=(LPCTSTR)filter;
strcpy(fil,fil1);
strcat(fil,"\0");
this->p_logfromc=(SLogResult *)lpSquartRoot1(fil);//err
this->getLogFromC();

}
::FreeLibrary(hInstance1);
}
return p_logfromc;
}


但运行时总是出错(Debug error,the value of ESP was not properly saved across a function call....)
可我的参数信息没错呀,专家指导一下!·
...全文
107 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
mudboy 2003-08-29
  • 打赏
  • 举报
回复
已经得到解决,是我的DLL内存管理有问题,但是我用C调用该DLL时并没有出问题。不知道这是为什么?
mudboy 2003-08-27
  • 打赏
  • 举报
回复
我这样写可以调用过去,可是过去以后就出错了(到调用者函数的结尾处)这应该跟栈有关。
希望大家多多帮助!

void CLogPickDlg::LoadDLLGetLog(CString filter)
{


typedef SLogResult * (LPFNGETLOG)(char[]);
HINSTANCE hInstance1;
LPFNGETLOG *lpSquartRoot1;
hInstance1 = ::LoadLibrary("win32dll.dll");
if (hInstance1 != NULL)
{

lpSquartRoot1 = (LPFNGETLOG *)::GetProcAddress(hInstance1,"getLogResult");
if(!lpSquartRoot1)
{
::FreeLibrary(hInstance1);
AfxMessageBox("定位动态链接库方法出错!!!");
return;
}
else
{
CString tempstr;
char fil[300];
const char *fil1=NULL;
fil1=(LPCTSTR)filter;
strcpy(fil,fil1);
this->p_logfromc=lpSquartRoot1(fil);

while((p_logfromc[i].id!="")&&(i<MAXRESULT))
{

}
::FreeLibrary(hInstance1);
}
return;

}
Zark 2003-08-27
  • 打赏
  • 举报
回复
把这个函数
SLogResult * getLogResult(char whereclause[300]);
贴出来,同时把SLogResult的定义贴出来.
Cline 2003-08-27
  • 打赏
  • 举报
回复
谁分配的内存,就让它提供一个释放内存的函数,用完后调用之!
shaojichibang 2003-08-27
  • 打赏
  • 举报
回复
up
mudboy 2003-08-26
  • 打赏
  • 举报
回复
我另外一个方法是没有参数的,这样用不会有问题,
也就是说,问题的关键在于参数。
mudboy 2003-08-26
  • 打赏
  • 举报
回复
不行,还是出同样的错误!
njtu 2003-08-26
  • 打赏
  • 举报
回复
typedef UINT (CALLBACK* __stdcall LPFNGETLOG)(char fi[300]);

//不知行不行。

和这个问题相关大家来看看。

http://expert.csdn.net/Expert/topic/2138/2138152.xml?temp=.4941675
mudboy 2003-08-26
  • 打赏
  • 举报
回复
kingzai(kingzai)
那你说该怎么办呢?
whoo 2003-08-26
  • 打赏
  • 举报
回复
Extern "C" 函数定义
Zark 2003-08-26
  • 打赏
  • 举报
回复
这一句是不是要检查一下?

typedef UINT (CALLBACK* LPFNGETLOG)(char fi[300]);
kingzai 2003-08-25
  • 打赏
  • 举报
回复
This error is most commonly called by mixing __stdcall and
__cdecl.

In one definition, you specify __stdcall. In the other you don't,
and the function defaults to __cdecl. __stdcall and __cdecl
calling conventions have different rules regarding parameter
passing and stack cleanup. The debugger is telling you that
your code has messed up the stack.

15,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧