就是我现在有一个DLL及源代码,想用DELPHI来调用,但我写的内容在执行后有问题,出错为可能是越界操作,但我不太明白,大家可下载DLL源代码及我写的调用方式先试一下,看看有什么问题

解决方案 »

  1.   

    把你的DLL中函数的C++声明抄来,最好相关的实现部分也抄来。
      

  2.   

    如果SetHook()返回的不是布尔值或整型值,就有可能出错!测试一下此函数的实际返回值。
      

  3.   

    DLL源代码位置:
    http://alin.heha.net/vnchooks.zipDLL的声明
    #if !defined(_VNCHOOKS_DLL_)
    #define _VNCHOOKS_DLL_#include <windows.h>/////////////////////////////////////////////////////////////////////////////
    // Define the import/export tags#define DllImport __declspec(dllimport)
    #define DllExport __declspec(dllexport)/////////////////////////////////////////////////////////////////////////////
    //
    // Functions used by WinVNCextern "C"
    {
    // DLL functions:
    DllExport BOOL SetHook(
    HWND hWnd,
    UINT UpdateMsg,
    UINT CopyMsg,
    UINT MouseMsg
    ); // Set the hook
    DllExport BOOL UnSetHook(HWND hWnd); // Remove it DllExport BOOL SetKeyboardFilterHook(BOOL activate);
    // Control keyboard filtering
    DllExport BOOL SetMouseFilterHook(BOOL activate);
    // Control mouse filtering
    }#endif // !defined(_VNCHOOKS_DLL_)
      

  4.   

    function UnSetHook(hWnd:HWND):Boolean;stdcall;external 'VNCHooks.dll';
                                          ~~~~~~~\可能这儿错了。
      

  5.   

    你应该这样声名输出函数
    DllExport BOOL __stdcall UnSetHook(HWND hWnd); 
                   ~~~~~~~~~
      

  6.   

    halfdream:stdcall为按C方式参数传递,去掉后一样出错
    zengyfeng:照你的方法,DELPHI指出找不到相应的输出函数,DELPHI中应怎样省明
    另:
      按我原来的方式,
    if SetHook(Handle,MWM_UpdateMsg,MWM_CopyMsg,MWM_MouseMsg) then
        ShowMessage('OK');
    其实OK已经正常显示,应该说HOOK安装正确,出错报
    Access Vialation at address 000000500 .read at address FFFFFFF
    是在StdCtrls单元下面的内容里
    procedure TButtonControl.WndProc(var Message: TMessage);
    begin
      case Message.Msg of
        WM_LBUTTONDOWN, WM_LBUTTONDBLCLK:
          if not (csDesigning in ComponentState) and not Focused then
          begin
            FClicksDisabled := True;
            Windows.SetFocus(Handle);
            FClicksDisabled := False;
            if not Focused then Exit;
          end;
        CN_COMMAND:
          if FClicksDisabled then Exit;
      end;
      inherited WndProc(Message);
    end;  //在这里报错
    不知什么原因,请高手指点
      

  7.   

    用cdecl代替stdcall,因为在你的C函数定义中没有定为stdcall。为什么能正确调用:因为cdecl和stdcall的参数压栈方式相同。
    为什么错误出现在调用后:因为cdecl有调用者清栈,stdcall有被调者清栈,因此你用stdcall方式去调用cdecl的函数将导致堆栈多弹出了有用数据,导致访问违例。