码迷,mamicode.com
首页 > 其他好文 > 详细

Using RUNDLL32.exe to call a function within a dll

时间:2015-08-02 16:29:56      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

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\to\dll\rdl.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%\system32\mshtml.dll,PrintHTML "C:\x.html"

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

Using RUNDLL32.exe to call a function within a dll

标签:

原文地址:http://www.cnblogs.com/honeynm/p/4695885.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!