I am using an audio library called BASS for my Windows application. It is written in C, but it is available as an external library in the form of a DLL file. A Pascal unit is provided to interact with the DLL, and while it is targeted for Delphi, it works fine with FreePascal, except for one method that is causing me issues:
function BASS_WASAPI_Init(device:Integer; freq,chans,flags:DWORD; buffer,period:Single; proc:WASAPIPROC; user:Pointer): BOOL; stdcall; external basswasapidll;
The method
BASS_WASAPI_Init requires me to provide a
WASAPIPROC function in the
proc parameter. The function is defined as such:
type
WASAPIPROC = function(buffer:Pointer; length:DWORD; user:Pointer): DWORD; stdcall;
However, BASS also allows for a "special WASAPIPROC" named WASAPIPROC_BASS. It is defined as such:
const
WASAPIPROC_BASS = Pointer(-1);
For the needs of my project, I need to use
WASAPIPROC_BASS. Thus, I write:
Mixer := BASS_Mixer_StreamCreate(48000, 2, BASS_STREAM_DECODE or BASS_SAMPLE_FLOAT or BASS_MIXER_NONSTOP);
BASS_WASAPI_Init(-1, 48000, 2, BASS_WASAPI_EXCLUSIVE, 0.03, 0, WASAPIPROC_BASS, Pointer(Mixer));
This works fine on Delphi, but fails on Lazarus with the following error:
Error: Incompatible type for arg no. 7: Got "Pointer", expected "<procedure variable type of function(Pointer;LongWord;Pointer):DWord;StdCall>"
A possible workaround is to use the
{$mode Delphi} directive, but I wanted to know if there was any way to solve this issue with the default
{$mode ObjFPC} directive.