khchen / wNim

Nim's Windows GUI Framework
MIT License
327 stars 17 forks source link

Runtime error when trying to run under InnoSetup #25

Closed PMunch closed 4 years ago

PMunch commented 5 years ago

I'm trying to use a Nim compiled DLL to create a custom page in InnoSetup to be able to more easily add functionality without having to struggle with PascalScript. Now using something like this with winim works fine:

import winim/lean

proc MyMessageBox(hwnd: cint) {.exportc, cdecl, dynlib.} =
  MessageBox(cast[HWND](hwnd), "Hello, world !", "Nim is Powerful", 0)

But trying to modify that to use wNim instead is proving difficult (I trimmed it down so it's only trying to create a frame):

import wNim
from winim import HWND

proc MyMessageBox(hwnd: cint) {.exportc, cdecl, dynlib.} =
  let app = App()
  let frame = Frame(owner = Window(cast[HWND](hwnd)), title="Hello world", size=(400,300))

  frame.center()
  frame.show()
  app.mainLoop()

This leaves me with this error message on Windows:

Runtime Error (at 6:392):

Floating point overflow.

And under Wine on Linux I see this error while the program just hangs:

0063:err:seh:setup_exception_record stack overflow 2752 bytes in thread 0063 eip 7bc61392 esp 00230870 stack 0x230000-0x231000-0x330000

When I abort the procedure the stack track for the SIGINT is:

Traceback (most recent call last)
MyNimDll.nim(6)          MyMessageBox
wWindow.nim(2055)        Window
wPredefined.nim(56)      init
SIGINT: Interrupted by Ctrl-C.

Any idea what I'm doing wrong? Or rather how I can do this correctly?

khchen commented 5 years ago

This code works for me:

# dll.nim
import wNim

proc MyMessageBox(hwnd: int) {.exportc, cdecl, dynlib.} =
  let app = App()
  let frame = Frame(owner = Window(hwnd), title="Hello world", size=(400, 300))

  frame.center()
  frame.show()
  app.mainLoop()

setupForeignThreadGc()
nim c --app:lib --passL:-static --threads:on --tlsEmulation:off dll