有个dll(应该是用vc做的),我要在delphi 6调用,但始终出错,请各位看看毛病在哪?
函数说明(vc调用例程里的)
extern "C" __declspec(dllexport) bool _stdcall OpenDataBase(HWND hMainWnd);   //打开数据源    返回true 成功   返回false 失败我的调用程序如下:
type
TFunc =function(hMainWnd:hwnd):boolean;Cdecl;
var
   th:Thandle;
   Tf:TFunc;
   Tp:TFarProc;
begin
  th:=LoadLibrary('CXK.dll');    {load dll}
  if(th>0) then
  try
   Tp :=GetProcAddress(th,PChar('OpenDataBase'));
 if(Tp <>nil) then
   begin
    Tf :=TFunc(Tp);
    if Tf(th) then    
        ShowMessage('ok.');
   end
  else
     ShowMessage('function not found.');
   finally
  FreeLibrary(th);
end;
函数打开了,但程序运行完毕后弹出一个消息框:access violation at 0x00d537ff:write of address 0x0000001c.哪的问题????

解决方案 »

  1.   

    TFunc =function(hMainWnd:hwnd):boolean;Cdecl;   //CDecl改为stdcall;试试!
      

  2.   

    恩,我也遇到同样的问题了把改为stdcall也不行,我想有可能是我写VC的DLL时内存分配的问题,你也看看,是否可行
      

  3.   

    type
    TFunc =function(hMainWnd:hwnd):boolean;stdcall;var
       th:Thandle;
       Tf:TFunc;
    begin
      th:=LoadLibrary('CXK.dll');    {load dll}
      if(th>0) then
      try
       @Tf :=GetProcAddress(th,PChar('OpenDataBase'));
     if Assigned(@tf) then
       begin
        if Tf(th) then    
            ShowMessage('ok.');
       end
      else
         ShowMessage('function not found.');
       finally
      FreeLibrary(th);
    end;
      

  4.   

    type
    TFunc =function(hMainWnd:hwnd):boolean;stdcall;var
       th:Thandle;
       Tf:TFunc;
    begin
      th:=LoadLibrary('CXK.dll');    {load dll}
      if(th>0) then
      try
       @Tf :=GetProcAddress(th,PChar('OpenDataBase'));
     if Assigned(@tf) then
       begin
        if Tf(^^^^^^^^) then    //这里应该给hMainWnd赋值,直接赋值th是不是不合适?
            ShowMessage('ok.');
       end
      else
         ShowMessage('function not found.');
       finally
      FreeLibrary(th);
    end;