我現在需要調用一個別人用Delphi寫好的DLL~
但沒有DLL原始碼~不知道對方怎麼編寫的,只知道
DLL :  SVR.DLL
Class :  A_Security
Function:  GetCode(const AInitCode: WideString): WideString; safecall;
使用時要輸入4個數字~而函式會傳回另外4個數字而我VC++現在call DLL部份程式碼如下:        HINSTANCE loadSVR;
typedef string(*HFUNC)(string);  //C++沒有WideString,那我是要寫string嗎? loadSVR = LoadLibrary("SVR.DLL");
if (loadSVR != NULL)
{
HFUNC handleSVR = (HFUNC)GetProcAddress(loadSVR, "FuncTest"); 
if (handleSVR){
handleSVR('1234'); 
printf("OK GetProcAddress \n");
}
else
printf("ERROR on GetProcAddress \n");
FreeLibrary(loadSVR);
}
else
printf("ERROR on LoadLibrary \n");
出現7個ERROR~指向
typedef string(*HFUNC)(string); 
HFUNC handlePSVCB = (HFUNC)GetProcAddress(loadPSVCB, "FuncTest"); 
這兩行~主要錯誤顯示
error C2065: 'HFUNC' : undeclared identifier
error C2100: illegal indirection
error C2501: 'string' : missing storage-class or type specifiers
error C2065: 'handleSVR' : undeclared identifier請問~是我type對應不該用sting的關係嗎?
還是其他問題~又該如何解決??感謝!

解决方案 »

  1.   

    我又重改了~我把原本的Delphi又用Delphi包一層~因為聽說格式不同不能直接轉Delphi部分(使產生DelphiDLL.dll)>>
    uses
      SysUtils,
      Classes;
     function   GetAuthCode(const AInitCode: WideString): WideString; safecall;   external   'SVR.DLL';
      function   GetAuthCodeA(ti:String):   pchar;   stdcall;
      var
          s:string;  
      begin  
        s:=GetAuthCode(ti);
        GetAuthCodeA:=pchar(s);
      end;  
      exports  
        GetAuthCodeA;
       
      begin  
      end.然後VC部分>>
    #include   <windows.h>  
    #include   <stdio.h>  
    typedef   char   *   (__stdcall   *GetAuthCodeA)(char*);  void  main()  
    {  
      GetAuthCodeA   GetCode;  
      HINSTANCE     h=LoadLibrary("DelphiDLL.dll");  
      GetCode=(GetAuthCodeA)GetProcAddress(h,"GetAuthCodeA");  
      char   *t=GetCode("1111");   
      printf("%s\n",t);  
           
      return;
    }我有把DelphiDLL.dll和SVR.DLL都放到VC程式同一目錄下,現在compile部分是過了~但"無法找到程序輸入點(GetAuthCode)"請問該如何解決呢? >___<~急啊!