How to build dll?

Jack jckj33 at gmail.com
Wed Dec 2 19:42:37 UTC 2020


D code:

>import core.sys.windows.dll;
>
> mixin SimpleDllMain;
>
>version(Windows) extern(C) export
>int foo() { return 42; }

compiled with:
> dmd -ofmydll.dll -shared -m32 dll.d

called from:

>typedef int (__cdecl *MYPROC)(void);
> 
>int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
>               PWSTR szCmdLine, int CmdShow)
>{
>    HINSTANCE hinstLib;
>    MYPROC ProcAdd;
>    BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
> 
>    // Get a handle to the DLL module.
> 
>    hinstLib = LoadLibrary(TEXT("mydll.dll"));


but hinstLib is NULL and GetLastError() = 193:

> ERROR_BAD_EXE_FORMAT 193 (0xC1)
> %1 is not a valid Win32 application.

What am I missing?


More information about the Digitalmars-d-learn mailing list