This repository has been archived by the owner on Dec 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
bassmod.cpp
93 lines (76 loc) · 2.53 KB
/
bassmod.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "bassmod.h"
BOOL (WINAPI* BASSMOD_Init)(int device, DWORD freq, DWORD flags);
BOOL (WINAPI* BASSMOD_MusicLoad)(BOOL mem, void *file, DWORD offset, DWORD length, DWORD flags);
BOOL (WINAPI* BASSMOD_MusicPlay)();
DWORD (WINAPI* BASSMOD_MusicIsActive)();
BOOL (WINAPI* BASSMOD_MusicPause)();
void (WINAPI* BASSMOD_MusicFree)();
void (WINAPI* BASSMOD_Free)();
char szTempFile[MAX_PATH];
HMODULE hBassMod;
BOOL LoadBassmod(LPCSTR lpResName, LPCSTR lpResType)
{
char szTempDir[MAX_PATH];
HANDLE hFile;
HRSRC hRsrc;
LPVOID pData;
DWORD dwSizeofResource;
DWORD dwNumberOfBytesWritten;
GetTempPath(MAX_PATH, szTempDir);
GetTempFileName(szTempDir, "bassmod", 0, szTempFile);
hRsrc = FindResource(NULL, lpResName, lpResType);
if(!hRsrc)
return FALSE;
pData = LoadResource(NULL, hRsrc);
dwSizeofResource = SizeofResource(NULL, hRsrc);
hFile = CreateFile(szTempFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile == INVALID_HANDLE_VALUE)
return FALSE;
WriteFile(hFile, pData, dwSizeofResource, &dwNumberOfBytesWritten, NULL);
CloseHandle(hFile);
hBassMod = LoadLibrary(szTempFile);
if(!hBassMod)
{
DeleteFile(szTempFile);
return FALSE;
}
if(
!(BASSMOD_Init = (BOOL (WINAPI*)(int, DWORD, DWORD))GetProcAddress(hBassMod, "BASSMOD_Init")) ||
!(BASSMOD_MusicLoad = (BOOL (WINAPI*)(BOOL, void*, DWORD, DWORD, DWORD))GetProcAddress(hBassMod, "BASSMOD_MusicLoad")) ||
!(BASSMOD_MusicPlay = (BOOL (WINAPI*)())GetProcAddress(hBassMod, "BASSMOD_MusicPlay")) ||
!(BASSMOD_MusicIsActive = (DWORD (WINAPI*)())GetProcAddress(hBassMod, "BASSMOD_MusicIsActive")) ||
!(BASSMOD_MusicPause = (BOOL (WINAPI*)())GetProcAddress(hBassMod, "BASSMOD_MusicPause")) ||
!(BASSMOD_MusicFree = (void (WINAPI*)())GetProcAddress(hBassMod, "BASSMOD_MusicFree")) ||
!(BASSMOD_Free = (void (WINAPI*)())GetProcAddress(hBassMod, "BASSMOD_Free"))
)
{
FreeLibrary(hBassMod);
DeleteFile(szTempFile);
return FALSE;
}
if(!BASSMOD_Init(-1, 44100, 0))
{
FreeLibrary(hBassMod);
DeleteFile(szTempFile);
return FALSE;
}
return TRUE;
}
BOOL LoadBassFile(LPCSTR lpResName, LPCSTR lpResType)
{
HRSRC hRsrc;
LPVOID pData;
DWORD dwSizeofResource;
hRsrc = FindResource(NULL, lpResName, lpResType);
if(!hRsrc)
return FALSE;
pData = LoadResource(NULL, hRsrc);
dwSizeofResource = SizeofResource(NULL, hRsrc);
return BASSMOD_MusicLoad(TRUE, pData, 0, dwSizeofResource, BASS_MUSIC_LOOP|BASS_MUSIC_RAMPS|BASS_MUSIC_SURROUND);
}
void FreeBassmod()
{
BASSMOD_Free();
FreeLibrary(hBassMod);
DeleteFile(szTempFile);
}