function BASS_WINAMPVIS_CreateVis(f: PChar; module, flags: DWORD; AppHandle: DWORD; AppHDC: boolean; VisCounter: integer): HVIS;
stdcall;
var
mbi: MEMORY_BASIC_INFORMATION;
winampVisGetHeader:
function: PWinampVisHeader;
cdecl;
begin
Result := 0;
// Winamp Emulator Fenster HWND
VisDllHandle := 0;
// Wenn True Plugin in der Applikation
// oder eigenen Skin visualisieren
AppParenthDC := AppHDC;
// Voller Pfad des Plugin
FileName := StrPas(f);
// HWND von der ausführenden Application
AppParentHandle := AppHandle;
if (
not FileExists(PChar(FileName)))
then
begin
BassFuncs^.SetError(BASS_ERROR_FILEOPEN);
Exit;
end;
if VisCounter = 0
then
VisWinCounter := VisCounter;
try
GetMem(VisInfo[VisCounter], SizeOf(TWinampVisInfo));
ZeroMemory(VisInfo[VisCounter], SizeOf(TWinampVisInfo));
except
BassFuncs^.SetError(BASS_ERROR_MEM);
Exit;
end;
try
SetCurrentDirectory(PChar(FileName));
VisDllHandle := LoadLibrary(PChar(FileName));
except
if (VisDllHandle <> 0)
then
FreeLibrary(VisDllHandle);
FreeMem(VisInfo[VisCounter]);
BassFuncs^.SetError(BASS_ERROR_START);
Exit;
end;
if (VisDllHandle = 0)
then
begin
FreeMem(VisInfo[VisCounter]);
BassFuncs^.SetError(BASS_ERROR_START);
Exit;
end;
@winampVisGetHeader := GetProcAddress(VisDllHandle, '
winampVisGetHeader');
if (@winampVisGetHeader =
nil)
then
begin
FreeLibrary(VisDllHandle);
FreeMem(VisInfo[VisCounter]);
BassFuncs^.SetError(BASS_ERROR_HANDLE);
Exit;
end;
VisInfo[VisCounter]^.VisHeader := winampVisGetHeader;
if (VisInfo[VisCounter]^.VisHeader =
nil)
then
begin
FreeLibrary(VisDllHandle);
FreeMem(VisInfo[VisCounter]);
BassFuncs^.SetError(BASS_ERROR_START);
Exit;
end;
VisInfo[VisCounter]^.VisModule := VisInfo[VisCounter]^.VisHeader^.getModule(module);
if (VisInfo[VisCounter]^.VisModule =
nil)
then
begin
FreeLibrary(VisDllHandle);
FreeMem(VisInfo[VisCounter]);
BassFuncs^.SetError(BASS_ERROR_START);
Exit;
end;
// Überprüfe ob eine neue Instanz erstellt werden soll
VisInfo[VisCounter]^.Init := ((flags
and BASS_VIS_NOINIT) <> BASS_VIS_NOINIT);
VisInfo[VisCounter]^.DllInstance := VisDllHandle;
if (VisInfo[VisCounter]^.Init)
then
begin
VisWinCounter := VisCounter;
VisInfo[VisWinCounter]^.VisInfoCount := VisWinCounter;
// Neuen Thread erstellen
ThreadHandle := BeginThread(
nil, 0, @WinampVisWin, VisInfo[VisWinCounter], 0, ThreadId);
// DLL aus Speicher entfernen wenn ThreadHandle = 0
if (ThreadHandle = 0)
then
begin
FreeLibrary(VisDllHandle);
FreeMem(VisInfo[VisWinCounter]);
BassFuncs^.SetError(BASS_ERROR_INIT);
Exit;
end;
// Thread schließen
CloseHandle(ThreadHandle);
end;
VirtualQuery(VisInfo[VisCounter]^.VisHeader.description, mbi, SizeOf(MEMORY_BASIC_INFORMATION));
VisInfo[VisCounter]^.PluginId := DWORD(mbi.AllocationBase);
W_AppendHandle(DWORD(VisInfo[VisCounter]));
BassFuncs^.SetError(BASS_OK);
Result := DWORD(VisInfo[VisCounter]);
end;