Last active
February 10, 2023 16:36
-
-
Save foxoman/d92d44a59bb749947a9db008bcbe4c6e to your computer and use it in GitHub Desktop.
USING NIM TO GENERATE A DLL FOR USE IN C#/VB6-C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{.passc:"-m32"} | |
{.passl:"-m32"} | |
import winim,os | |
#nim c --cpu:i386 --app:lib --nomain | |
# https://www.appsloveworld.com/csharp/100/446/using-nim-to-generate-a-dll-for-use-in-c-vb6 | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment