-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenalCppConsole.cpp
More file actions
92 lines (79 loc) · 2.43 KB
/
OpenalCppConsole.cpp
File metadata and controls
92 lines (79 loc) · 2.43 KB
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
// OpenalCppConsole.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <vector>
#include <sstream>
#include <string>
#include <windows.h>
/**
* Device's extended specifier string.
*
* If device handle is NULL, it is instead a null-character separated list of
* strings of known extended device specifiers (list ends with an empty string).
*/
#define ALC_ALL_DEVICES_SPECIFIER 0x1013
/**
* Capture device specifier string.
*
* If device handle is NULL, it is instead a null-character separated list of
* strings of known capture device specifiers (list ends with an empty string).
*/
#define ALC_CAPTURE_DEVICE_SPECIFIER 0x310
typedef void* (*_GetProcAddress) (const char*);
_GetProcAddress _alGetProcAddress;
typedef const char* (*_GetString)(void*, int);
_GetString _alcGetString;
void parse_device_list(const char* sourceList, std::vector<std::string>& deviceList);
void show_device_list();
void parse_device_list(const char* sourceList, std::vector<std::string>& deviceList)
{
std::string str;
int index = 0;
bool canContinue = true;
while (canContinue) {
auto ch = *(sourceList + index);
if (ch == '\0') {
if (str.empty())
break;
else {
deviceList.push_back(str);
str = "";
++index;
}
}
else {
str += ch;
++index;
}
}
}
void show_device_list()
{
std::vector<std::string> deviceList;
auto allPlayingDevices = _alcGetString(nullptr, ALC_ALL_DEVICES_SPECIFIER);
parse_device_list(allPlayingDevices, deviceList);
auto allCaptureDevices = _alcGetString(nullptr, ALC_CAPTURE_DEVICE_SPECIFIER);
parse_device_list(allCaptureDevices, deviceList);
for (auto& deviceName : deviceList)
std::cout << deviceName << std::endl;
}
int main() {
HMODULE hLib = LoadLibrary(L"OpenAL32.dll");
if (!hLib)
throw;
_alGetProcAddress = (_GetProcAddress)GetProcAddress(hLib, "alGetProcAddress");
if (!_alGetProcAddress)
throw;
_alcGetString = (_GetString)GetProcAddress(hLib, "alcGetString");
if (!_alcGetString)
throw;
while (true)
{
std::string line;
std::getline(std::cin, line);
if (line == "exit")
break;
else if (line == "show")
show_device_list();
}
}