我用vc写了一个动态连接库,
void encryptstr(LPCTSTR instr,char* outstr, LPCTSTR key)
{
MessageBox(NULL,"haha","hoho",MB_OK);
DES des;
int nLen=strleng((char*)instr); int nNewLen = (nLen+7)/8*8;
strcpy(keyi,key); char* lpBuf = (char*)malloc(nNewLen+1);
memset(lpBuf,'\0',nNewLen+1); memcpy(lpBuf,instr,nLen); des.encrypt (keyi,lpBuf,nNewLen/8); lpBuf[nNewLen]='\0'; memcpy(outstr,lpBuf,nNewLen);

free(lpBuf);
MessageBox(NULL,outstr,"result",MB_OK);
return;
}
以上是代码,可是用delphi调用的时候总是报
“access violation at 0X0000000000:read of address 0X0000000000”的错,
即使是把函数改为
void encryptstr(LPCTSTR instr,char* outstr, LPCTSTR key)
{
MessageBox(NULL,"haha","hoho",MB_OK);
}
也报同样的错,请高手们帮帮忙吧!

解决方案 »

  1.   

    请将DLL加载时的代码写出来!可能是那边错了也有可能的(:
    还有头文件也要:)
      

  2.   

    头文件
    extern "C" void encryptstr(LPCTSTR instr,char* outstr, LPCTSTR key);加载的代码
    procedure encryptstr(instr: string;outstr: string;keyi:string); safecall;
      external 'crypt.dll';调用的代码
    i:string;   setlength(i,9);
       encryptstr(edit1.Text,i,'abcdefgh');
      

  3.   

    你加一个调用约定试试,extern "C" __declspec(dllexport) void __stdcall encryptstr(...)你可以在函数中先不用参数试试
      

  4.   

    唉,这个问题我自己解决了,可是不能给自己分!
    加载的代码
    function encryptstr(instr: string;outstr: string;keyi:string):HResult; safecall;
      external 'crypt.dll';