小弟我vc++,和 delphi都不懂(汗颜) ,但最近要做一vc++ dll 调用delphi 的 dll 参数方面始终弄不明白,程序出错,老大们帮小弟看看,非常感谢.delphi dll 如下:
procedure enc_account_pin(khzh: pchar;srcpswd: pchar;dstpswd: pchar);stdcall;external 'eaicrypt.dll';自己搞的vc++ dll入下:
问题是到connectDESPWD_API char* fnDESPWD(char *src)
{
char * cdno=NULL;
char * pwd=NULL;
char * deststr=NULL;
char *f = NULL; char strcdno[100];
char strpwd[100]; memset(strcdno, 0, sizeof(strcdno));
memset(strpwd, 0, sizeof(strpwd));
ofstream fout;
fout.open("output.txt");
typedef char* (CALLBACK* enc_account_pin)(char* cdno,char *pwd, char *deststr); //src:2222222|33333 ZeroMemory(&deststr,sizeof(deststr));
f=strstr(src , "|");
if (f!=NULL)
strncpy(strcdno,src,strlen(src)-strlen(f));
f++;
strncpy(strpwd,f,strlen(f)); fout << "strcdno is : " << strcdno << "\n";
HINSTANCE hinstDLL=NULL;
hinstDLL=LoadLibrary("eaicrypt.dll");
if(hinstDLL!=NULL)
{
enc_account_pin connect;
connect = (enc_account_pin)GetProcAddress (hinstDLL,"enc_account_pin");
//下面过不去了,我估计是我参数有问题,但不知道怎么转换
connect(strcdno,strpwd,deststr);
FreeLibrary(hinstDLL);
}
fout << "despwd is : " << deststr << "\n";
fout << flush;
fout.close();
return deststr;
}
procedure enc_account_pin(khzh: pchar;srcpswd: pchar;dstpswd: pchar);stdcall;external 'eaicrypt.dll';自己搞的vc++ dll入下:
问题是到connectDESPWD_API char* fnDESPWD(char *src)
{
char * cdno=NULL;
char * pwd=NULL;
char * deststr=NULL;
char *f = NULL; char strcdno[100];
char strpwd[100]; memset(strcdno, 0, sizeof(strcdno));
memset(strpwd, 0, sizeof(strpwd));
ofstream fout;
fout.open("output.txt");
typedef char* (CALLBACK* enc_account_pin)(char* cdno,char *pwd, char *deststr); //src:2222222|33333 ZeroMemory(&deststr,sizeof(deststr));
f=strstr(src , "|");
if (f!=NULL)
strncpy(strcdno,src,strlen(src)-strlen(f));
f++;
strncpy(strpwd,f,strlen(f)); fout << "strcdno is : " << strcdno << "\n";
HINSTANCE hinstDLL=NULL;
hinstDLL=LoadLibrary("eaicrypt.dll");
if(hinstDLL!=NULL)
{
enc_account_pin connect;
connect = (enc_account_pin)GetProcAddress (hinstDLL,"enc_account_pin");
//下面过不去了,我估计是我参数有问题,但不知道怎么转换
connect(strcdno,strpwd,deststr);
FreeLibrary(hinstDLL);
}
fout << "despwd is : " << deststr << "\n";
fout << flush;
fout.close();
return deststr;
}
这是Delphi中的导入函数方式,是从'eaicrypt.dll'导入enc_account_pin这个函数如果你在VC下也要从'eaicrypt.dll'导入enc_account_pin这个函数的话
应该把
typedef char* (CALLBACK* enc_account_pin)(char* cdno,char *pwd, char *deststr);
改成
typedef void (WINAPI* enc_account_pin)(char* cdno,char *pwd, char *deststr);但我没看出来你是要在VC下调用Delphi写的dll,难道'eaicrypt.dll'是Delphi写的?
procedure enc_account_pin(khzh: pchar;srcpswd: pchar;dstpswd: pchar);stdcall;external 'eaicrypt.dll';
khzh 和srcpwd 是输入的两个参数,dstpswd是返回的值.如果用void 返回的值返回不了啊
程序会报错
ZeroMemory(&deststr,sizeof(deststr)); 改成 char deststr[50] = "\0";