0

I am trying to pass a string (or char*) from Rundll32 to a DLL built (with MinGW) using this source:

#include <windows.h>

__declspec( dllexport ) int hello(LPSTR content) {

  MessageBox( NULL, content, "Message", MB_OK );
  return 0;

}

When running this I get random crashes. This is how I run it.

C:\workspace>c:\MinGW\bin\gdb.exe rundll32 -ex "run program1.dll,hello test"

I tried setting a breakpoint at hello() and it seems that "content" is pretty random. Am I passing the argument from rundll32 in the wrong way?

It works fine if I don't have arguments.

Janus Troelsen
  • 20,267
  • 14
  • 135
  • 196

1 Answers1

2

rundll32 entry points need to be declared in a very specific way. Check out this article which explains what to do. One thing I've noticed is that, for a symbol called "EntryPoint", the function name passed to rundll32 should be "_EntryPoint@16" for 32-bit DLLs, and just "EntryPoint" for 64-bit DLLs.

vanza
  • 9,715
  • 2
  • 31
  • 34
  • Yes I tried this earlier. Doesn't seem to work though. I'm using this function definition: "void CALLBACK hello(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);". When I call rundll32.exe I get a message box with "Missing Entry: _hello@16". I am on 32-bit x86 / Windows 7. I read that there is a tool called "depends.exe" that can list entry points, but I can only find it for WinXP. Maybe objdump can do the same? – Janus Troelsen May 02 '11 at 23:02
  • [Dependency Walker](http://www.dependencywalker.com) runs just fine on Windows 7. – Ben Voigt May 02 '11 at 23:07
  • Okay, using Dependency Walker I found out that the entry point was named "hello@16" (without underscore). Works now :) – Janus Troelsen May 02 '11 at 23:11
  • 1
    Don't forget that rundll32 is 100% undocumented and is subject to change without notice from Microsoft. – Larry Osterman May 03 '11 at 04:48