hi All,
i am trying to get the device count (
http://portaudio.com/docs/v19-doxydocs/querying_devices.html) using the PortAudio library on 64b I found in the uos library.
as per the code below the initialization (
http://www.portaudio.com/docs/v19-doxydocs/initializing_portaudio.html) returns a zero code but the getdevice count returns a -10000 error code.
please advise what i am missing.
thank you
unit manage_portaudio; //use in order to initialize and terminate working with portaudio
{$mode objfpc}{$H+}
interface
uses
{$IFDEF UNIX}cthreads,{$ENDIF}
Classes,
SysUtils,
dynlibs;
function ManagePortAudio(const AFileName: string; ToInitialize, ToTerminate: boolean; out AResult: integer): boolean;
{mapping external function}
type
//may return an error code
TManageLib = function(): integer; stdcall;
implementation
function ManagePortAudio(const AFileName: string; ToInitialize, ToTerminate: boolean; out AResult: integer): boolean;
var
DLLInstance: THandle;
msg: TManageLib;
begin
Result := False;
try
try
DLLInstance := SafeLoadLibrary(AFileName);
if DLLInstance <> NilHandle then
begin
if ToInitialize then
begin
msg := TManageLib(GetProcedureAddress(DLLInstance, 'Pa_Initialize'));
end;
if ToTerminate then
begin
msg := TManageLib(GetProcedureAddress(DLLInstance, 'Pa_Terminate'));
end;
if @msg <> nil then
begin
AResult := msg(); //runs also the function call
if AResult > -1 then
Result := True;
end;
end;
finally
FreeLibrary(DLLInstance);
end;
except
on E: Exception do
begin
AResult := -1;
end;
end;
end;
end.
unit get_device_count;
{$mode objfpc}{$H+}
interface
uses
{$IFDEF UNIX}cthreads,{$ENDIF}
Classes,
SysUtils,
dynlibs
{$IFDEF MSWINDOWS}, Windows{$ENDIF};
function GetDeviceCount(const AFileName: string; out AResult: integer): boolean;
{mapping external function}
type
TDeviceCount = function(): integer; stdcall;
implementation
{$IFDEF MSWINDOWS}
function GetDeviceCount(const AFileName: string; out AResult: integer): boolean;
var
DLLInstance: THandle;
c: TDeviceCount;
begin
Result := False;
try
try
DLLInstance := SafeLoadLibrary(AFileName);
if DLLInstance <> NilHandle then
begin
c := TDeviceCount(GetProcedureAddress(DLLInstance, 'Pa_GetDeviceCount'));
if @c <> nil then
begin
AResult := c(); //runs the external function
end
else
AResult := -1;
end;
finally
FreeLibrary(DLLInstance);
end;
except
on E: Exception do
begin
AResult := -2;
end;
end;
end;
{$ENDIF}
end.
program learn_dlls;
{$mode objfpc}{$H+}
uses
Classes,
SysUtils,
CustApp,
get_device_count,
manage_portaudio;
type
TWorkDLL = class(TCustomApplication)
protected
procedure DoRun; override;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
end;
const
LibPath = 'LibPortaudio-64.dll';
procedure TWorkDLL.DoRun;
var
c: integer;
begin
{$IFDEF MSWINDOWS}
{initialize library}
if ManagePortAudio(LibPath, True, False, c) then
Writeln(IntToStr(c))
else
Writeln('Error initialize: ' + IntToStr(c));
{get the number of audio devices}
if GetDeviceCount(LibPath, c) then
Writeln(IntToStr(c))
else
Writeln('Error device count: ' + IntToStr(c));
{free library}
if ManagePortAudio(LibPath, False, True, c) then
Writeln(IntToStr(c))
else
Writeln('Error terminate: ' + IntToStr(c));
{$ENDIF}
Terminate;
end;
constructor TWorkDLL.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
StopOnException := True;
end;
destructor TWorkDLL.Destroy;
begin
inherited Destroy;
end;
var
Application: TWorkDLL;
begin
Application := TWorkDLL.Create(nil);
Application.Title := 'Test_DLL';
Application.Run;
Application.Free;
end.