[
]
已经试过了.但在DLL改变变参的值返回时就有问题.
代码在:
http://www.ufoit.com/test.zip (47KB)
{ 注: 工具为delphi7.0 vc.net2003. }
Delphi =>DLL, GetXxValue function
{ --------------------------------------------------------- }
function GetXxValue(var V: OleVariant): Boolean; stdcall;
var
tmpValue: OleVariant;
begin
try
tmpValue := 203; { Test }
V := tmpValue;
Result := True;
VariantClear(tmpValue);
except
Result := False;
end;
end;
{ --------------------------------------------------------- }
VC=>EXE, call function GetXxValue() from xx.DLL.
//----------------------------------------------------------
void CVC_TESTDlg::OnBnClickedButton1()
{
HINSTANCE hLibrary;
VARIANT olevar_ss;
//COleVariant ss;
typedef bool (__stdcall *MYPROC)(VARIANT* v); //不好意思啊,忘加__stdcall了.
hLibrary = LoadLibrary("xx.dll");
MYPROC fn = (MYPROC)GetProcAddress(hLibrary,TEXT("GetXxValue"));
long num;
VariantInit(&olevar_ss);
olevar_ss.intVal = 0;
/*******************************
fn(&olevar_ss); * <- Error Message will be shown. *
********************************/
FreeLibrary (hLibrary);
olevar_ss.vt = VT_I4;
num = olevar_ss.intVal;
char* str_tmp="";
itoa(num, str_tmp, 10);
MessageBox(str_tmp,"cc",MB_OK);
}
//----------------------------------------------------------
//*******************************************
ErrorMessage: "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."
//*******************************************