小弟我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;
}

解决方案 »

  1.   

    procedure enc_account_pin(khzh: pchar;srcpswd: pchar;dstpswd: pchar);stdcall;external 'eaicrypt.dll';
    这是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写的?
      

  2.   

    恩,是的enc_account_pin是eaicrypt.dll的函数.是用delphi写的
    procedure enc_account_pin(khzh: pchar;srcpswd: pchar;dstpswd: pchar);stdcall;external 'eaicrypt.dll'; 
     khzh 和srcpwd 是输入的两个参数,dstpswd是返回的值.如果用void 返回的值返回不了啊
      

  3.   

    char * deststr=NULL;  这个你从来没有分配实际空间 当然取不到返回值了 相当于向一个空指针里拷东西 
    程序会报错
      

  4.   

    Delphi里的procedure就相当于Vc下的void
      

  5.   

    char * deststr=NULL; 
    ZeroMemory(&deststr,sizeof(deststr)); 改成 char deststr[50] = "\0";