#define QMPLUGIN_API extern "C" __declspec(dllexport)
typedef int (*QMPLUGIN_HANDLER)(char *lpszParamList, char *lpszRetVal);
typedef struct {
    char *m_lpszCommandName;
    char *m_lpszCommandDescription;
     QMPLUGIN_HANDLER m_pHandlerFunction;
     UINT m_nParamNumber;
} QMPLUGIN_CMD_INFO;
typedef QMPLUGIN_CMD_INFO* (*CommandFunc)(int iCommandNum);     HINSTANCE thDll;
     thDll = LoadLibrary("xxxxxplugin.dll");     if (thDll != NULL)
    { 
         CommandFunc someFunc = (CommandFunc)GetProcAddress(thDll, "GetCommand"); 
        if (someFunc != NULL) 
        {
             QMPLUGIN_CMD_INFO* abc = someFunc(0);
            printf("the function description is %s\n", abc->m_lpszCommandDescription); 
        }else
        {
            printf("Load Function Error\n");
        }         FreeLibrary(thDll);
    }else{
        printf("Load DLL Error\n");
    } 
谢谢了!

解决方案 »

  1.   

    type QMPLUGIN_HANDLER=function(lpszParamList,lpszRetVal:PChar):integer;stdcall;
    type
      QMPLUGIN_CMD_INFO= record
        m_lpszCommandName,
        m_lpszCommandDescription:Pchar;
         m_pHandlerFunction:QMPLUGIN_HANDLER;
        m_nParamNumber:Cardinal;
      end;
      pQMPLUGIN_CMD_INFO=^QMPLUGIN_CMD_INFO;type CommandFunc= function (iCommandNum:integer):pQMPLUGIN_CMD_INFO;var
        thDll:HINSTANCE;
        someFunc:  CommandFunc;
    begin
        thDll := LoadLibrary('xxxxxplugin.dll');
        if (thDll <>nil)  then
        begin
             someFunc:= GetProcAddress(thDll, 'GetCommand');
            if (someFunc<>nil) then begin
                QMPLUGIN_CMD_INFO* abc = someFunc(0);
                printf('the function description is %s', abc->m_lpszCommandDescription);
                end
            else
                printf('Load Function Error');
            FreeLibrary(thDll);
            end
        else
            printf('Load DLL Error');
    end;
      

  2.   

    to mmzmagic :
    谢谢兄弟,不过好像有点问题,请问你在Delphi里面能用吗?
    var 
        thDll:HINSTANCE; 通不过
        someFunc:  CommandFunc; 
    begin 
        thDll := LoadLibrary('xxxxxplugin.dll'); 
        if (thDll <>nil)  then (改成hwnd后通不过)
        begin 
            someFunc:= GetProcAddress(thDll, 'GetCommand'); 
            if (someFunc <>nil) then begin  (通不过)
                QMPLUGIN_CMD_INFO* abc = someFunc(0); (通不过)
                printf('the function description is %s', abc->m_lpszCommandDescription); (通不过,不过不重要)
                end 
            else 
                printf('Load Function Error'); 
            FreeLibrary(thDll); 
            end 
        else 
            printf('Load DLL Error'); 
      

  3.   

    type QMPLUGIN_HANDLER=function(lpszParamList,lpszRetVal:PChar):integer;stdcall; 
    type 
      QMPLUGIN_CMD_INFO= record 
        m_lpszCommandName, 
        m_lpszCommandDescription:Pchar; 
        m_pHandlerFunction:QMPLUGIN_HANDLER; 
        m_nParamNumber:Cardinal; 
      end; 
      pQMPLUGIN_CMD_INFO=^QMPLUGIN_CMD_INFO; type CommandFunc= function (iCommandNum:integer):pQMPLUGIN_CMD_INFO; var 
        thDll:THANDLE; 
        someFunc:  CommandFunc; 
    begin 
        thDll := LoadLibrary('xxxxxplugin.dll'); 
        if (thDll <>0)  then 
        begin 
            someFunc:= GetProcAddress(thDll, 'GetCommand'); 
            if (someFunc <>nil) then begin 
                result = someFunc(0); 
                ..
                end 
            else 
                ... 
            FreeLibrary(thDll); 
            end 
        else 
            ... 
    end; 
      

  4.   

    someFunc<>nil   通不过
    原文:
    在自己的程序中调用按键精灵的插件 末看了一下按键精灵的使用方法,关注了一下它里面提到的插件编写方法。 
    它的插件套路是这样的, 你使用他们提供的一个插件模板编写一个DLL,
    这样编译完你的DLL就默认支持4个基本接口
    (使用dumpbin /exports随便一个插件DLL就可以看到)
    ordinal hint RVA      name        1    0 00001032 GetCommand
            2    1 00001014 GetCommandCount
            3    2 00001023 GetFormatVersion
            4    3 0000102D GetPluginDescription假设你要在按键精灵里面调用插件ABC.DLL里面的say方法,
    那么脚本这样写:
    Plugin ABC.say()
    按键精灵会加载ABC.DLL,然后通过GetCommand,GetCommandCount这样的方法对插件进行轮询,
    直到找到一个叫Say的commmand入口,然后调用之。我不知道按键精灵对这些别人写的插件是怎么进行验证的, 如果没有源码级别的检查, 那插件里面包含木马应该很难避免。知道了插件的接口,不想通过按键精灵, 想自己在程序里面直接调用这些插件方法也很EASY了,
    下面是一个简单的例子:
     
    #define QMPLUGIN_API extern "C" __declspec(dllexport)
    typedef int (*QMPLUGIN_HANDLER)(char *lpszParamList, char *lpszRetVal);
    typedef struct {
        char *m_lpszCommandName;
        char *m_lpszCommandDescription;
         QMPLUGIN_HANDLER m_pHandlerFunction;
         UINT m_nParamNumber;
    } QMPLUGIN_CMD_INFO;
    typedef QMPLUGIN_CMD_INFO* (*CommandFunc)(int iCommandNum);     HINSTANCE thDll;
         thDll = LoadLibrary("xxxxxplugin.dll");     if (thDll != NULL)
        { 
             CommandFunc someFunc = (CommandFunc)GetProcAddress(thDll, "GetCommand"); 
            if (someFunc != NULL) 
            {
                 QMPLUGIN_CMD_INFO* abc = someFunc(0);
                printf("the function description is %s\n", abc->m_lpszCommandDescription); 
            }else
            {
                printf("Load Function Error\n");
            }         FreeLibrary(thDll);
        }else{
            printf("Load DLL Error\n");
        } 
     
     
     
     
      

  5.   

    @someFunc:= GetProcAddress(thDll, 'GetCommand'); 
      

  6.   

    呵呵 怪我懒 随手翻译的没有测试。
    以下是偶测试过的,可编译通过type QMPLUGIN_HANDLER = function(lpszParamList, lpszRetVal: PChar): integer; stdcall;
    type
      QMPLUGIN_CMD_INFO = record
        m_lpszCommandName,
          m_lpszCommandDescription: Pchar;
        m_pHandlerFunction: QMPLUGIN_HANDLER;
        m_nParamNumber: Cardinal;
      end;
      pQMPLUGIN_CMD_INFO = ^QMPLUGIN_CMD_INFO;type CommandFunc = function(iCommandNum: integer): pQMPLUGIN_CMD_INFO;var
      thDll: Cardinal;
      someFunc: CommandFunc;
      abc: pQMPLUGIN_CMD_INFO;
    begin
      thDll := LoadLibrary('xxxxxplugin.dll');
      if (thDll <> 0) then begin
        someFunc := GetProcAddress(thDll, 'GetCommand');
        if Assigned(someFunc) then begin
          abc := someFunc(0);
          ShowMessage(Format('the function description is %s', [abc^.m_lpszCommandDescription]));
        end
        else
         ShowMessage('Load Function Error');
        FreeLibrary(thDll);
      end
      else
       ShowMessage('Load DLL Error');
    end;
      

  7.   

    to mmzmagic :
    谢谢了啊老大!
    本来是打算调用按键精灵的dll插件的,可是奈何自己的功力太差了,用上面的代码也没办法进入到那些个DLL里面去,郁闷ing....
    结帐,面壁去!老大你一会要是有时间,心情不错能帮忙完成一下调用按键精灵的DLL的功能不,3Q!