Using RUNDLL32.exe to call a function within a DLL

Source: Internet
Author: User

Using RUNDLL32.exe to call a function within a DLL

Rundll32 is a utility included with Windows This allows you to execute a 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 would 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 was needed in order to export the function such, its address can gotten with GetProcAddress. Rundll32 used GetProcAddress. Also, the function RDL is specified with extern "C" and __cdecl so the RDL are not name-mangled (in case it is compiled WI Th a C + + compiler).
Printing an HTML document

rundll32.exe%windir%\system32\mshtml.dll,printhtml "C:\x.html"

Note, the document name (at least of the My system) needs to is enclosed in quotes.

Using RUNDLL32.exe to call a function within a DLL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.