TNB Library
TnbRapi.h
[詳解]
1#pragma once
14#ifdef _WIN32_WCE
15 #error TnbRapi.h is only supported on Windows NT Series platforms.
16#endif // _WIN32_WCE
17
18#include "TnbDef.h"
19#include <rapi.h>
20#pragma comment(lib,"rapi.lib")
21#ifdef __MSVCPP6__
22 #pragma comment(lib, "delayimp.lib")
23 #pragma comment(linker,"/DELAYLOAD:rapi.dll")
24#endif
25
26
27
28//TNB Library
29namespace TNB
30{
31
32
33
47#ifndef _TnbDOXYGEN //Document作成用シンボル
48 // 初期化済みフラグ
49 _SELECTANY RAPIINIT* s_pRapiInit = NULL;
50#endif
51
52
53
69class CRapi
70{
71public:
72
81 static bool Startup(void)
82 {
83 LONG* P = reinterpret_cast<LONG*>(&s_pRapiInit);
84 if ( InterlockedCompareExchange(P, 1, NULL) == NULL )
85 {
86 HMODULE hModule = ::LoadLibraryA("rapi.dll");
87 if ( hModule == NULL )
88 {
89 s_pRapiInit = NULL;
90 }
91 else
92 {
93 ::FreeLibrary(hModule);
94 ASSERT( s_pRapiInit != NULL );
95 RAPIINIT* P = new RAPIINIT;
96 P->cbSize = sizeof(RAPIINIT);
97 P->heRapiInit = NULL;
98 P->hrRapiInit = NULL;
99 static CReject s_reject;
100 ::OutputDebugString(_T("::CeRapiInitEx() 中\n"));
101 HRESULT hr = ::CeRapiInitEx(P);
102 ::OutputDebugString(_T("::CeRapiInitEx() 完了\n"));
103 if ( FAILED(hr) )
104 {
105 delete P;
106 s_pRapiInit = NULL;
107 }
108 else
109 {
110 s_pRapiInit = P;
111 }
112 }
113 }
114 while ( reinterpret_cast<UINT_PTR>(s_pRapiInit) == 1 )
115 {
116 ::Sleep(10);
117 }
118 return s_pRapiInit != NULL;
119 }
120
127 static bool IsSupported(void)
128 {
129 Startup();
130 return (s_pRapiInit != NULL);
131 }
132
140 static bool IsConnected(DWORD time = 0)
141 {
142 if ( IsSupported() )
143 {
144 DWORD dwWaitRet = ::WaitForSingleObject(s_pRapiInit->heRapiInit, time);
145 return (dwWaitRet == WAIT_OBJECT_0);
146 }
147 return false;
148 }
149
157 static void Shutdown(void)
158 {
159 while ( reinterpret_cast<UINT_PTR>(s_pRapiInit) == 1 )
160 {
161 ::Sleep(10);
162 }
163 if ( s_pRapiInit != NULL )
164 {
165 ::OutputDebugString(_T("::CeRapiUninit() 中\n"));
166 ::CeRapiUninit();
167 ::OutputDebugString(_T("::CeRapiUninit() 完了\n"));
168 delete s_pRapiInit;
169 s_pRapiInit = NULL;
170 }
171 }
172
173private:
175 CRapi(void) {}
177 class CReject
178 {
179 public:
181 ~CReject(void)
182 {
183 Shutdown();
184 }
185 };
186};
187
188
189
190}; //TNB
191
192
193
TNBライブラリの定義ヘッダ
RAPI 管理クラス
Definition: TnbRapi.h:70
static bool IsSupported(void)
[確認] サポート確認.
Definition: TnbRapi.h:127
static bool IsConnected(DWORD time=0)
[確認] 接続確認.
Definition: TnbRapi.h:140
static void Shutdown(void)
[設定] RAPI 解除.
Definition: TnbRapi.h:157
static bool Startup(void)
[設定] RAPI 初期化.
Definition: TnbRapi.h:81
TNB Library
Definition: TnbDoxyTitle.txt:2