Nim
Nim copied to clipboard
exported DllMain not working
Description
I tried to load a dynamic library (dll), when I made it from Linux with the exported DllMain like this
import winim/lean
proc NimMain() {.cdecl,importc.}
proc DllMain(hinstDLL: HINSTANCE, fdwReason: DWORD, lpvReserved: LPVOID) : BOOL
{.stdcall, exportc, dynlib.} =
if fdwReason == DLL_PROCESS_ATTACH:
NimMain()
MessageBox(0, "Hello, world !", "Nim is Powerful", 0)
return true
it worked just fine
but when I compile it from Windows directly, when I export the DllMain, it does not work (when I just put a simple function in the dll it works, but so when I try to export DllMain, the dll cannot be loaded anymore)
I compile it like this:
nim c --app=lib --nomain .\dll_test.nim
this is the program (main.nim)
import winim/lean
import dynlib
const dll = "./dll_test.dll"
proc main() =
let hlib = loadLib(dll)
if hlib == nil:
echo "could not import: ", dll
unloadLib(hlib)
main()
Nim Version
nim -v Nim Compiler Version 1.9.1 [Windows: amd64] Compiled at 2023-02-03 Copyright (c) 2006-2023 by Andreas Rumpf
active boot switches: -d:release
Current Output
could not import: ./dll_test.dll
Expected Output
(MessageBox showing Hello World)
Possible Solution
No response
Additional Information
with the same code, cross compiling from Linux it works.