I'm definitely not a Nim vet, but here is something that works.
Calling Nim proc from VB6 application.
Nim DLL (compile with nim c --cpu:i386 --app:lib --nomain):
{.passc:"-m32"}
{.passl:"-m32"}
import winim,os
proc TestFunc(a: cint):cint {.exportc, stdcall, dynlib.} =
echo "function called!"
a + 5
when defined(vcc):
{.emit: "N_LIB_EXPORT N_CDECL(void, NimMain)(void);".}
else:
proc NimMain() {.cdecl, importc.}
proc DllMain(hModule: HINSTANCE, reasonForCall: DWORD, lpReserved: LPVOID): WINBOOL {.exportc, dynlib, stdcall.} =
case reasonForCall:
of DLL_PROCESS_ATTACH:
when defined(vcc):
{.emit: "NimMain();".}
else:
NimMain()
AllocConsole()
discard stdout.reopen("CONOUT$", fmWrite)
discard execShellCmd("chcp 65001")
echo "Hello from Nim Code!"
else:
discard
return TRUE
VB6:
Private Declare Function TestFunc Lib "nim.dll" Alias "TestFunc@4" (ByVal a As Long) As Long
Private Sub Form_Load()
Caption = CStr(TestFunc(5))
End Sub