zoukankan      html  css  js  c++  java
  • Using RUNDLL32.exe to call a function within a dll

    Using RUNDLL32.exe to call a function within a dll
            
    Rundll32 is a utility included with Windows that allows you to execute an exported DLL-function from a command line.
    Consider the following (exported) function in a DLL:

    #include <windows.h>

    extern "C" __declspec (dllexport) void __cdecl rdl (
       HWND hwnd,        // handle to owner window
       HINSTANCE hinst,  // instance handle for the DLL
       LPTSTR lpCmdLine, // string the DLL will parse
       int nCmdShow      // show state
    )
    {
      ::MessageBox(0,lpCmdLine,0,0);
    }

    BOOL APIENTRY DllMain( HANDLE hModule,
                           DWORD  ul_reason_for_call,
                           LPVOID lpReserved)
    {
        return TRUE;
    }

    The function rdl within the dll can now be called using rundll32:

    rundll32 c:path odll dl.dll,rdl hallo

    Note: the function rdl is specified with __declspec (dllexport). This is needed in order to export the function such that its address can be gotten with GetProcAddress. rundll32 used GetProcAddress. Also, the function rdl is specified with extern "C" and __cdecl so that rdl is not name-mangled (in case it is compiled with a c++ compiler).
    Printing an HTML document

    rundll32.exe %windir%system32mshtml.dll,PrintHTML "C:x.html"

    Note, the document name (at least on my system) needs to be enclosed in quotes.

  • 相关阅读:
    delphi private public protected
    delphi 程序流程控制
    TTrayIcon-Delphi系统托盘组件
    如果没有你-莫文蔚
    ShellExecute 调用bat文件
    delphi ShellExecute使用
    delphi 测试ping
    centos7 安装redis
    my.cnf 基础配置
    Delphi的类和对象(七)- 继承
  • 原文地址:https://www.cnblogs.com/honeynm/p/4695885.html
Copyright © 2011-2022 走看看