To run a DLL function using Rundll32.exe

Source: Internet
Author: User

We know that the Windows DLL is not able to run independently, but Microsoft has provided rundll32.exe for running DLLs.

Test first: Run "Rundll32.exe shell32.dll,restartdialog" and the restart dialog will pop up. The same way you can turn on other features of Windows systems.

Here's a look at how to define your own DLL to let Rundll32.exe run.

The DLL function prototypes given by Microsoft are as follows:

  void CALLBACK
  EntryPoint (HWND hwnd, HINSTANCE hinst, LPSTR lpszcmdline, int ncmdshow);

   Hwnd-window handle that should is used as the owner window for any
          windows your DLL creates
   hinst-your dll ' s I  Nstance handle
   lpszcmdline-asciiz command line your DLL should parse
   ncmdshow-describes how your DLL ' s windows should be displayed

The custom test DLLs are as follows:

extern "C" _declspec (dllexport) void __cdecl Rundll32dllfun (HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine,

int nCmdShow)
{
MessageBox (NULL, "TEST", LPSZCMDLINE,MB_OK);
Return
}

Generate Dynamic Library Rundll32dll.dll.

Run:

Rundll32.exe "E:\demo\rudll32dll\Release\rudll32dll.dll", Rundll32dllfun

A familiar dialog box pops up, stating that the call was successful.

You can also pass in parameters and run:

Rundll32.exe "E:\demo\rudll32dll\Release\rudll32dll.dll", Rundll32dllfun 888

The dialog box pops up, and 888 shows the dialog box, indicating that the parameters can also be passed, where the parameters are obtained in lpszCmdLine.

Run command description: rundll32.exe "Xxx.dll", dllfun parameter

So that we can develop the DLL as an application to run, only see the rundll32.exe in the process, you need to see through the Process View tool which DLL is running.


rundll32.exe where the location of the 4-bit system is explained:

Windows/system32/rundll32.exe calling a 64-bit DLL

Windows/syswow64/rundll32.exe calling a 32-bit DLL

Microsoft's reference article is as follows: http://support2.microsoft.com/kb/164787

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.