峻
峻祁连
Unregistered / Unconfirmed
GUEST, unregistred user!
用VC调用delphi写的dll,想从dll里传出参数供VC调用,可结果发现没有传递出去,不知道是什么问题,VC我不太懂,大家看看哪儿有问题?
delphi写的dll代码如下
//输出函数
function GetEmployeeUser(out userIdchar;out userNamechar):integer;stdcall;
begin
try
frmInnerEmployee := TfrmInnerEmployee.Create(application);
if frmInnerEmployee.ShowModal=mrOK then begin
//test---在这里测试,改变要传出参数的值。
userId:='0';
userName:='testuser';
//test---
end;
result := 0;
except
on e : Exception do begin
showmessage(e.Message);
frmInnerEmployee := nil;
result := -1;
end;
end;
end;
VC的调用代码:
void CDllCallerDlg::OnBtnGetemployee()
{
typedef int (CALLBACK* LPFNDLLFUNC1)(CString userId,CString userName);
HINSTANCE hDLL
// Handle to DLL
LPFNDLLFUNC1 lpfnDllFunc1
// Function pointer
hDLL = LoadLibrary("YCCrm.dll"
if (hDLL != NULL)
{
lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,
"GetEmployeeUser"
if (!lpfnDllFunc1)
{
// handle the error
FreeLibrary(hDLL)
return;
}
else
{
// call the function
//int userId = 1;
char userId[255]="22";
char userName[255];
int result = lpfnDllFunc1(userId,userName);//调用该dll函数
AfxMessageBox(userId);
if(result<0) AfxMessageBox("操作失败!"
}
}
FreeLibrary(hDLL);
}
delphi写的dll代码如下
//输出函数
function GetEmployeeUser(out userIdchar;out userNamechar):integer;stdcall;
begin
try
frmInnerEmployee := TfrmInnerEmployee.Create(application);
if frmInnerEmployee.ShowModal=mrOK then begin
//test---在这里测试,改变要传出参数的值。
userId:='0';
userName:='testuser';
//test---
end;
result := 0;
except
on e : Exception do begin
showmessage(e.Message);
frmInnerEmployee := nil;
result := -1;
end;
end;
end;
VC的调用代码:
void CDllCallerDlg::OnBtnGetemployee()
{
typedef int (CALLBACK* LPFNDLLFUNC1)(CString userId,CString userName);
HINSTANCE hDLL
// Handle to DLL
LPFNDLLFUNC1 lpfnDllFunc1
// Function pointer
hDLL = LoadLibrary("YCCrm.dll"
if (hDLL != NULL)
{
lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,
"GetEmployeeUser"
if (!lpfnDllFunc1)
{
// handle the error
FreeLibrary(hDLL)
return;
}
else
{
// call the function
//int userId = 1;
char userId[255]="22";
char userName[255];
int result = lpfnDllFunc1(userId,userName);//调用该dll函数
AfxMessageBox(userId);
if(result<0) AfxMessageBox("操作失败!"
}
}
FreeLibrary(hDLL);
}