-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
exported DllMain not working #21334
Comments
Move the NimMain inside dllmain proc like this: import winim/lean
proc NimMain() {.cdecl, importc.}
proc DllMain(hinstDLL: HINSTANCE, fdwReason: DWORD,
lpvReserved: LPVOID): BOOL {.stdcall, exportc, dynlib.} =
NimMain()
if fdwReason == DLL_PROCESS_ATTACH:
MessageBox(0, "Hello, world !", "Nim is Powerful", 0)
return true Also check your antivrus because in my system the test did not work first time because the dll was quarantined. |
my antivirus doesn't quarantine my dll and even moving the NimMain() doesn't seem to change, but I found a way to make my code work using |
It seems to me you're basically trying to re-implement what Nim already does for you: offering a DLL entry-point, while generalizing away its low-level implementation. As you found out yourself, this is the functional equivalent of your first attempt import winim/lean
MessageBox(0, "Hello, world !", "Nim is Powerful", 0) So I'd say this is working as intended? |
Just like here https://youtu.be/9fV8tWb2W1M?t=470 and here https://github.com/byt3bl33d3r/OffensiveNim#creating-windows-dlls-with-an-exported-dllmain, it should be possible to create your own entry point for the dll. edit: the project I had to make is finished and work fine, just when I was trying to find a solution I needed the |
I can confirm that nim 2.0+ (tested on 2.0.6) broke the exported DllMain, reverting to version 1.6.10 resolved the issue:
I chose 1.6.10 because any version lower you will come across It was this blog that also claimed nim DLLs were broken on nim 2.0 which lead me confirm if it was true: |
Description
I tried to load a dynamic library (dll), when I made it from Linux with the exported DllMain like this
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)
Nim Version
active boot switches: -d:release
Current Output
Expected Output
Possible Solution
No response
Additional Information
with the same code, cross compiling from Linux it works.
The text was updated successfully, but these errors were encountered: