@PMunch Thanks, it was actually as simple as that. You do however still need to add a DllMain and specify --noman in the compiler
Example:
import winim
import os
proc NimMain() {.cdecl, importc.}
proc DllMain(hinstDLL: HINSTANCE, fdwReason: DWORD, lpvReserved: LPVOID) : BOOL {.stdcall, exportc, dynlib.} =
NimMain()
return true
proc entry(): void {.stdcall, exportc, dynlib.} =
AllocConsole()
discard stdout.reopen("CONOUT$", fmWrite)
stdout.write "TEST!"
while GetAsyncKeyState(VK_END) == 0:
sleep(500)
stdout.close()
FreeConsole()
I am having another problem, the entire reason to use a different entrypoint as opposed to DllMain was that I needed to use threads in my Dll, but whenever I compile the dll with --threads:on it won't work (I guess problems with the LoadLibrary underneath, any suggestions how to use threads with dll's?
import winim
import os
var chan: Channel[string]
proc thread1() =
chan.send("This is some data")
proc thread2() =
var msg = chan.recv()
stdout.write msg
proc NimMain() {.cdecl, importc.}
proc DllMain(hinstDLL: HINSTANCE, fdwReason: DWORD, lpvReserved: LPVOID) : BOOL {.stdcall, exportc, dynlib.} =
NimMain()
return true
proc entry(): void {.stdcall, exportc, dynlib.} =
AllocConsole()
discard stdout.reopen("CONOUT$", fmWrite)
stdout.write "TEST!"
var worker1: Thread[void]
var worker2: Thread[void]
chan.open()
createThread(worker1, thread1)
createThread(worker2, thread2)
worker2.joinThread()
chan.close()
while GetAsyncKeyState(VK_END) == 0:
sleep(500)
stdout.close()
FreeConsole()
compiled with nim c --app:lib --nomain --os:windows --cpu:amd64 --threads:on