[英]Using Nim to generate a DLL for use in C#/VB6
After many hours of trying to figure out this problem I'm wondering if there even is a way of doing it.经过几个小时的尝试解决这个问题,我想知道是否有办法做到这一点。
I need to be able to export functions that are called from VB6 (yes you read that correctly, not VB.NET) and I'm at a loss.我需要能够导出从 VB6 调用的函数(是的,你没看错,不是 VB.NET),但我不知所措。 I got as far as generating a DLL that should have worked;我已经生成了一个应该可以工作的 DLL; it worked when being called from C at least, but nothing further.它至少在从 C 调用时起作用,但仅此而已。
Maybe some Nim vet can steer me in the right direction.也许一些 Nim 兽医可以引导我朝着正确的方向前进。 I would be immensely greatful.我会非常伟大。
I'm definitely not a Nim vet, but here is something that works.我绝对不是 Nim 兽医,但这里有一些有效的方法。
Calling Nim proc from VB6 application.从 VB6 应用程序调用 Nim proc。
Nim DLL (compile with nim c --cpu:i386 --app:lib --nomain): Nim DLL(使用 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: 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.