代码如下:数据库方面已经测试,没问题,用的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.
我还是新手,大家帮我一把,谢谢.
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.
我还是新手,大家帮我一把,谢谢.
解决方案 »
- 怎样判断输入的IP地址,网关,子网掩码是否正确?谁有好的方案?
- 请问谁用过下列器件
- 重问NTFS格式中怎样设置文件的摘要?
- 学VC,不想被IDE所累!
- 用ODBC能不能将表的内容复制到另外一个结构相同的表呀?
- 请大家帮帮忙!
- memory allocation error,cannot load command.system halted 是什么原因造成的?
- 给Radio Button(单选)控件设置对应的变量
- 急急 急!!请问“0x00429a6c指令引用的‘0X0000000F’内存,该内存不能为‘READ’”是什么出物?
- VC++数据库连接失败
- 使用FillRect配合CreatePatternBrush,用位图填充一个矩形区域,出现交错问题??各位请看看!!
- 如何获取任务管理器中的进程信息????????
顺便请问这里的typedef void (WINAPI * Insert)(CStringW[],int);中的WINAPI是什么意思
调用约定的问题
WINAPI代表__stdcall,这在VC的头文件中有定义。