Delphi写的DLL,用在VC中出现的转换异常..(100分)

  • 主题发起人 主题发起人 tongdings
  • 开始时间 开始时间
T

tongdings

Unregistered / Unconfirmed
GUEST, unregistred user!
/////////// declaration in delphi
procedure PackTime(nSeconds: Longint;var pcTime: PChar;
pSize: PInt);
stdcall;
////////// declaration in vc
#pragma comment( lib, "TimePaser" )
//typedef void (PACKPROC)(long,char*&,int*);
extern "C" __declspec(dllimport) int PackTime(long nSeconds,char*&
pcTime,int* pSize);
//附注:已通过impdef(c++builder)和lib(vc)等工具转换得到timepaser.lib文件.
//link通过,但运行时出现different call convertion异常.
//问下高手,上面两者转换等价吗?谢过
 
sorry,这里写错了.
//typedef void (PACKPROC)(long,char*&,int*);
extern "C" __declspec(dllimport) int PackTime(long nSeconds,char*&
pcTime,int* pSize);
~~~~~
-> void
 
结果还是一样,不管我用显式/隐式调用,一样的错误!为什么阿?
////////////////////////////////////////
typedef void (PACKPROC)(long,char*&,int*);
void CDLLTestDlg::OnButton1()
{
HINSTANCE hInst = NULL;
PACKPROC *pPackProc;
char ch[64] = {0};
char* pc = ch;
int nSize = 64;
hInst = ::LoadLibrary("E://TimePaser.dll");
if (hInst == NULL)
{
TRACE("LoadLibrary fail../n");
return;
}
pPackProc = (PACKPROC*)::GetProcAddress(hInst,"PackTime");
if (pPackProc == NULL)
{
TRACE("GetProcAddress packtime fail../n");
return;
}
UpdateData(TRUE);
pPackProc(m_nSeconds,pc,&nSize);
memcpy(ch,pc,nSize);
m_strTime.Format(ch);
UpdateData(FALSE);
}
 
应该不是stdcall而是cdecl吧
 
to Another_eYes:
you are right.3x
//////////////////////
__cdecl
Home | Overview | Howdo
I
Microsoft Specific —>
This is the default calling convention for C and C++ programs. Because the stack is cleaned up by the caller, it cando
vararg functions. The __cdecl calling convention creates larger executables than __stdcall, because it requires each function call to include stack cleanup code.
 
多人接受答案了。
 
后退
顶部