Add 'auto-decoration' to nimGetProcAddr
Maintainers of win32 DLLs can opt to provide libraries with 'decorated' function names (Google "stdcall name decoration"). To pull a function pointer out of one of these DLLs, you have to pass a decorated name to getProcAddress. This is painful for the authors of NIM DLL wrappers - they have to pass manually-decorated strings to "importc", but only on win32. This commit adds auto-decoration to nimGetProcAddress. This function will probe the DLL for the undecorated name, and if that fails, it will automatically add decoration and try again. That way, the author of the wrapper doesn't have to deal with it.
This commit is contained in:
parent
ebc3438cc2
commit
e8bc19f79c
1 changed files with 6 additions and 1 deletions
|
|
@ -105,7 +105,12 @@ elif defined(windows) or defined(dos):
|
||||||
|
|
||||||
proc nimGetProcAddr(lib: LibHandle, name: cstring): ProcAddr =
|
proc nimGetProcAddr(lib: LibHandle, name: cstring): ProcAddr =
|
||||||
result = getProcAddress(cast[THINSTANCE](lib), name)
|
result = getProcAddress(cast[THINSTANCE](lib), name)
|
||||||
if result == nil: procAddrError(name)
|
if result != nil: return
|
||||||
|
for i in countup(0, 50):
|
||||||
|
var decorated = "_" & $name & "@" & $(i * 4)
|
||||||
|
result = getProcAddress(cast[THINSTANCE](lib), cstring(decorated))
|
||||||
|
if result != nil: return
|
||||||
|
procAddrError(name)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
{.error: "no implementation for dyncalls".}
|
{.error: "no implementation for dyncalls".}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue