0

I have the following codes:

mydll.h:

#include <Windows.h>

__declspec(dllexport) void CALLBACK Entry(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);

mydll.c:

#include "mydll.h"

void CALLBACK Entry(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow) {
    FILE *f;
    f = fopen("C:\\Users\\user\\Desktop\\test.txt", "rw");
    fprintf(f, "test");
    fclose(f);
}

It compiles to mydll.dll.

Then, when I try to do

rundll32.exe mydll.dll,Entry

It gives me the error message

Error in mydll.dll
Missing entry: Entry

What am I missing here?

Edwin Lee
  • 3,540
  • 6
  • 29
  • 36
  • [What's the guidance on when to use rundll32? Easy: Don't use it](http://blogs.msdn.com/b/oldnewthing/archive/2013/01/04/10382242.aspx) – Alex K. Sep 10 '15 at 15:33
  • 1
    The entrypoint won't be "Entry" unless you use a DEF file to rename it from "_Entry@16". – Hans Passant Sep 10 '15 at 15:44
  • As a followup to @HansPassant this Microsoft [knowledge base article](https://support.microsoft.com/en-gb/kb/140485) may help. – Michael Petch Sep 10 '15 at 16:07
  • Thanks! I read about DEF files on MSDN, but my impression from [the article](https://msdn.microsoft.com/en-us/library/900axts6%28v=vs.100%29.aspx) was to use EITHER __declspec(dllexport) or DEF files... – Edwin Lee Sep 10 '15 at 16:14
  • Anyway, after using the DEF file, I no longer get the missing entry error. But now I get a "Windows Host Process (Rundll32) has stopped working". I read somewhere that this happens when the exported function signature is incorrect, but I'm pretty sure mine is correct... – Edwin Lee Sep 10 '15 at 16:20
  • If you aren't pumping messages, windows will think it is hung. – josh poley Sep 10 '15 at 17:04
  • Sorry, please ignore my stupidity... "rw" is NOT a valid mode for fopen... it's working now (changed to "w"). Thanks Hans and Michael for the tips on using DEF file. – Edwin Lee Sep 10 '15 at 17:09

0 Answers0