问:关于多语言使用DLL,使用Olevariant做为变参传递.(300分)

  • 主题发起人 主题发起人 bini
  • 开始时间 开始时间
B

bini

Unregistered / Unconfirmed
GUEST, unregistred user!
现在Delphi里.

function GetXxValue(xx1,xx2 : PChar; InstanceIndex: Cardinal;
Var V: OleVariant): BOOL; stdcall;
在delphi里使用是没有问题的.
但在VC中.
VARIANT v_c;
...
VariantInit(&v_c);
fn("X","X",0,v_c);
编译程序,在delphi中调试DLL,会出现给{Var V: OleVariant} V := tmpOleVariant 或改变为其它值是访问错误:access violation at 0x012eee7c: read of address 0xccc0000
V应该是nil.

请各位大侠相助.
 
fn("X","X",0,&v_c);尝试一下
Delphi中 var 参数是按照地址传递的
 
[:)]
已经试过了.但在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."
//*******************************************
 
不好意思,忘加 __stdcall了.[:(!]
 
多人接受答案了。
 
后退
顶部