开发者

How do I pass a string to a DLL using the Win32 API?

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 co开发者_JAVA百科ntent) {

  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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜