mfc的dll调用返回后主程序出错,大家帮忙看看
代码如下:数据库方面已经测试,没问题,用的unicode编码.dll和主程序都支持mfc
dll的:
extern "C" __declspec(dllexport) void insert(CStringW val[], int size)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
DBOper o;
o.Insert(val, size);
}
BOOL DBOper::Insert(CStringW val[], int size)
{
CDaoRecordset rTemp(&m_database);
rTemp.Open(AFX_DAO_USE_DEFAULT_TYPE,
L"SELECT * FROM file", 0);
rTemp.AddNew();
for(int i =0;i<size;i++)
{
rTemp.SetFieldValue(i,(LPCTSTR)val[i]);
}
rTemp.Update();
rTemp.Close();
return true;
}
主程序的:
CStringW a[6]={"1","2","3","4","5","6"};
typedef void (WINAPI * Insert)(CStringW[],int);
HINSTANCE hmod;
hmod = ::LoadLibrary (L"DBHelper.dll");
if(hmod==NULL)
{
AfxMessageBox(L"fail");
}
Insert lpproc;
lpproc = (Insert)GetProcAddress (hmod,"insert");
if(lpproc!=(Insert)NULL)
(*lpproc)(a,6);//这里返回后报错
FreeLibrary(hmod);
这是错误信息
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.
我还是新手,大家帮我一把,谢谢.
问题点数:50、回复次数:4Top
1 楼flyelf(空谷清音)回复于 2006-03-14 08:59:17 得分 25
typedef void ( * Insert)(CStringW[],int);Top
2 楼wraith1234()回复于 2006-03-14 09:24:48 得分 0
试了一下,问题解决了.呵呵
顺便请问这里的typedef void (WINAPI * Insert)(CStringW[],int);中的WINAPI是什么意思Top
3 楼DentistryDoctor(不在无聊中无奈,就在沉默中变态)回复于 2006-03-14 19:37:29 得分 25
正说明问题:
调用约定的问题
WINAPI代表__stdcall,这在VC的头文件中有定义。Top
4 楼wraith1234()回复于 2006-03-14 22:20:33 得分 0
哦
自己再看看Top




