-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoyCtrlTest.cpp
More file actions
109 lines (100 loc) · 2.67 KB
/
BoyCtrlTest.cpp
File metadata and controls
109 lines (100 loc) · 2.67 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// BoyCtrlTest.cpp : This file contains the 'main' function. Program execution begins and ends there.
#include <iostream>
#include <string>
#include <sstream>
#include <Windows.h>
#include "BoyCtrl.h"
using namespace std;
#define BOYCTRLTEST_X64
void __stdcall speakCompleteCallback(int reason)
{
cerr << "reason = " << reason << endl;
}
int main()
{
#ifndef BOYCTRLTEST_X64
auto dllHandle = LoadLibrary(L"BoyCtrl.dll");
#else
auto dllHandle = LoadLibrary(L"x64/BoyCtrl-x64.dll");
#endif
if (!dllHandle)
{
#ifndef BOYCTRLTEST_X64
cerr << "Failed to load BoyCtrl.dll error = " << GetLastError() << endl;
#else
cerr << "Failed to load BoyCtrl-x64.dll error = " << GetLastError() << endl;
#endif
return 1;
}
auto initFunc = (decltype(BoyCtrlInitialize)*)GetProcAddress(dllHandle, "BoyCtrlInitialize");
if (!initFunc)
{
cerr << "Failed to get BoyCtrlInitialize" << endl;
FreeLibrary(dllHandle);
return 1;
}
auto uninitFunc = (decltype(BoyCtrlUninitialize)*)GetProcAddress(dllHandle, "BoyCtrlUninitialize");
if (!uninitFunc)
{
cerr << "Failed to get BoyCtrlUninitialize" << endl;
FreeLibrary(dllHandle);
return 1;
}
auto err = initFunc(L"boyCtrl.log");
if (err != e_bcerr_success)
{
cerr << "init failed error = " << err << endl;
FreeLibrary(dllHandle);
return 1;
}
cout << "ready" << endl;
/* 加载读取输出函数 */
auto speakFunc = (decltype(BoyCtrlSpeak)*)GetProcAddress(dllHandle, "BoyCtrlSpeak");
if (!speakFunc)
{
cerr << "Failed to get BoyCtrlSpeak" << endl;
uninitFunc();
FreeLibrary(dllHandle);
return 1;
}
auto speakU8Func = (decltype(BoyCtrlSpeakU8)*)GetProcAddress(dllHandle, "BoyCtrlSpeakU8");
if (!speakU8Func)
{
cerr << "Failed to get BoyCtrlSpeakU8" << endl;
uninitFunc();
FreeLibrary(dllHandle);
return 1;
}
auto stopFunc = (decltype(BoyCtrlStopSpeaking)*)GetProcAddress(dllHandle, "BoyCtrlStopSpeaking");
if (!stopFunc)
{
cerr << "Failed to get BoyCtrlStopSpeaking" << endl;
uninitFunc();
FreeLibrary(dllHandle);
return 1;
}
bool withSlave=false, append=false, allowBreak=true;
for (int i = 1; i <= 4; ++i)
{
cout << i << " Press <Enter> to speak" << endl;
getchar();
if (i < 3)
{
wostringstream oss;
oss << i << L" Boy control Speak 中文";
err = speakFunc(oss.str().c_str(), withSlave, append, allowBreak, speakCompleteCallback);
}
else
err = speakU8Func(u8"Boy control Speak UTF-8 中文", withSlave, append, allowBreak, speakCompleteCallback);
if (err != e_bcerr_success)
{
cerr << "error = " << err << endl;
}
}
uninitFunc();
FreeLibrary(dllHandle);
cout << "Press <Enter> to exit" << endl;
getchar();
return 0;
}
// cl /source-charset:utf-8 /DUNICODE /D_UNICODE BoyCtrlTest.cpp