Hi, I'm trying to wrap a function of BASS sound library so I can learn how it works. My code is:
#{. emit: """#include "bass.h" """ .} type dword {. importc: "DWORD" .} = uint32 type hwnd {. importc: "HWND" .} = uint32 type guid {. importc: "struct GUID" .}= object type cbool {. importc: "BOOL" .} = uint32
proc BASS_Init* (device: cint, frequency, flags: cuint, win: hwnd, guid: ptr guid): cbool {. importc, cdecl, header: "bass.h" .} echo $int(BASS_Init(-1, 44100, 0, 0, nil))
The function I'm wrapping is:
BOOL BASSDEF(BASS_Init)(int device, DWORD freq, DWORD flags, HWND win, const GUID *dsguid);
The reason I'm passing a nil pointer in the call to BASS_Init is because BASS will use the default value if it's null. Any hints?
I have wrapped plenty of C programs with Nim. My experience is that sig faults are caused by some thing simple ... like me not understanding the parameters.
An equivalent C program should crash with a sig fault there too. I bet BASS_Init(-1, 44100, 0, 0, nil) would crash in C as well.
Here's what BASS_Init looks like in the wrapper I made some years ago.
proc BASS_Init(device: cint; freq: DWORD; flags: DWORD; win: DWORD; dsguid: pointer): BOOL {...}{.
stdcall, importc: "BASS_Init", dynlib: dynlibbass.}
Bass will need stdcall on Windows.