1

With rundll32 it is possible to call simple APIs into DLLs.

Two questions:

  • for this usage, should be the entry point use the __cdecl calling convention, or some other calling convention?
  • is it possible to pass only numeric args or also strings?
IInspectable
  • 46,945
  • 8
  • 85
  • 181
Massimo
  • 3,171
  • 3
  • 28
  • 41
  • 1
    But see [What's the guidance on when to use rundll32? Easy: Don't use it](https://blogs.msdn.microsoft.com/oldnewthing/20130104-00/?p=5643). – Harry Johnston Aug 17 '16 at 01:29

2 Answers2

3

Don't use rundll32.exe. I can't word it any better than Raymond Chen did: What’s the guidance on when to use rundll32? Easy: Don’t use it.

If you read through the blog entry, and are still convinced, that this is the solution you need, here is the deal: The entry point must follow the __stdcall calling convention:

void CALLBACK
EntryPointW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow);

The trailing W is important, so that the lpszCmdLine argument is passed as Unicode (UTF-16LE). EntryPoint is a placeholder, it can be any legal symbol.

As an example, you can export a symbol called MyFunctionW, and pass an arbitrary command line using:

rundll32.exe MyDll.dll,MyFunction 132 C:\WINDOWS\INF\SHELL.INF

But really, you should evaluate other options (e.g. PowerShell). Convenience doesn't come for free.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
IInspectable
  • 46,945
  • 8
  • 85
  • 181
2

The entry point must use the __stdcall calling convention:

  void CALLBACK
  EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);

This is covered in the following documentation:

NFO: Windows Rundll and Rundll32 Interface

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
RbMm
  • 31,280
  • 3
  • 35
  • 56