2 [momiji music component library]
3 ---------------------------------------------------------------------
4 Momiji.Core.Midi.Out.cpp
6 ---------------------------------------------------------------------
7 Copyright (C) 2011 tyiki badwell {miria@users.sourceforge.jp}.
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/gpl-3.0.html>.
21 ---------------------------------------------------------------------
25 #include "Momiji.Interop.MMDeviceAPI.h"
26 #include "Momiji.Core.MMDeviceAPI.h"
30 namespace MMDeviceAPI {
33 Interop::MMDeviceAPI::EDataFlow dataFlow
37 System::Console::WriteLine("[{0}][dataFlow:{1}]",__FUNCTION__, dataFlow);
41 System::Console::WriteLine("[{0}][dataFlow:{1}]",__FUNCTION__, Interop::MMDeviceAPI::FunctionDiscoveryKeys_devpkey::PKEY_Device);
46 Interop::MMDeviceAPI::IMMDeviceEnumerator^ a = gcnew Interop::MMDeviceAPI::MMDeviceEnumeratorClass();
47 Interop::MMDeviceAPI::IMMDeviceCollection^ b;
49 a->EnumAudioEndpoints(dataFlow, 1, b);
55 System::Console::WriteLine("[{0}][IMMDeviceCollection.GetCount:{1}]",__FUNCTION__, c);
58 for (auto i = 0; i < c; i++) {
59 Interop::MMDeviceAPI::IMMDevice^ d;
67 System::Console::WriteLine("[{0}][IMMDevice.GetId:{1}]",__FUNCTION__, e);
70 Interop::MMDeviceAPI::DEVICE_STATE f;
74 System::Console::WriteLine("[{0}][IMMDevice.GetState:{1:F}]",__FUNCTION__, f);
77 Interop::PropIdl::IPropertyStore^ g;
78 d->OpenPropertyStore(Interop::MMDeviceAPI::STGM::READ, g);
84 System::Console::WriteLine("[{0}][IPropertyStore.GetCount:{1}]",__FUNCTION__, h);
87 for (auto j = 0; j < h; j++) {
88 auto x = gcnew Interop::PropIdl::PROPERTYKEY();
92 System::Console::WriteLine("[{0}][IPropertyStore.GetAt:{1}]",__FUNCTION__, x);
94 auto y = gcnew Interop::PropIdl::PROPVARIANT();
95 auto marshaler = Interop::PropIdl::PROPVARIANTMarshaler::GetInstance("");
96 auto z = marshaler->MarshalManagedToNative(y);
100 y = safe_cast<Interop::PropIdl::PROPVARIANT^>(marshaler->MarshalNativeToManaged(z));
104 marshaler->CleanUpNativeData(z);
108 System::Console::WriteLine("[{0}][IPropertyStore.GetValue:{1}]",__FUNCTION__, y);
124 System::Console::WriteLine("[{0}]",__FUNCTION__);
132 System::Console::WriteLine("[{0}]",__FUNCTION__);
134 // this->_handle->Close();
137 Devices::Detail::Detail(
144 System::Console::WriteLine("[{0}]",__FUNCTION__);
147 // this->GetDetail(index);
150 Devices::Detail::~Detail()
153 System::Console::WriteLine("[{0}]",__FUNCTION__);
158 Devices::Detail::!Detail()
161 System::Console::WriteLine("[{0}]",__FUNCTION__);
165 void Devices::Detail::GetDetail(
170 System::Console::WriteLine("[{0}][index: {1}]",__FUNCTION__, index);
173 auto data = Interop::Setupapi::SpDeviceInterfaceData();
174 data.cbSize = safe_cast<System::UInt32>(InteropServices::Marshal::SizeOf(data));
176 System::Console::WriteLine("[{0}] data->cbSize {1}",__FUNCTION__, data.cbSize);
179 !Interop::Setupapi::Function::SetupDiEnumDeviceInterfaces(
180 this->_devices->_handle,
182 this->_devices->_category,
188 auto error = InteropServices::Marshal::GetHRForLastWin32Error();
190 System::Console::WriteLine("[{0}] error [{1}]",__FUNCTION__, InteropServices::Marshal::GetExceptionForHR(error)->ToString());
192 if (error == 0x80070103) //ERROR_NO_MORE_ITEMS
194 this->_noMoreItems = true;
199 InteropServices::Marshal::ThrowExceptionForHR(error);
204 System::Console::WriteLine("[{0}] data [{1}]", __FUNCTION__, data);
209 //
\83f
\81[
\83^
\83T
\83C
\83Y
\8am
\94F
210 System::UInt32 reqired = 0;
213 !Interop::Setupapi::Function::SetupDiGetDeviceInterfaceDetail(
214 this->_devices->_handle,
216 System::IntPtr::Zero,
223 auto error = InteropServices::Marshal::GetHRForLastWin32Error();
225 System::Console::WriteLine("[{0}] error [{1}]",__FUNCTION__, InteropServices::Marshal::GetExceptionForHR(error)->ToString());
227 if (error != 0x8007007A)//ERROR_INSUFFICIENT_BUFFER
229 InteropServices::Marshal::ThrowExceptionForHR(error);
234 System::Console::WriteLine("[{0}] reqired {1}",__FUNCTION__, reqired);
237 //
\81E
\81E
\81E
\82Í
\82µ
\82Ä
\82é
\82à
\82Ì
\82Ì
\81A
\8c\8b\8bÇ
\8d¡
\82Í
\81A1024byte
\8cÅ
\92è
\82Å
\93Ç
\82Ý
\8d\9e\82ñ
\82Å
\82¢
\82é
238 auto detail = Interop::Setupapi::SpDeviceInterfaceDetailData();
239 detail.cbSize = safe_cast<System::UInt32>(InteropServices::Marshal::SizeOf(detail.cbSize) + InteropServices::Marshal::SystemDefaultCharSize);
241 auto info = Interop::Setupapi::SpDevinfoData();
242 info.cbSize = safe_cast<System::UInt32>(InteropServices::Marshal::SizeOf(info));
245 System::Console::WriteLine("[{0}] detail->cbSize {1}",__FUNCTION__, detail.cbSize);
249 System::Console::WriteLine("[{0}] info->cbSize {1}",__FUNCTION__, info.cbSize);
253 !Interop::Setupapi::Function::SetupDiGetDeviceInterfaceDetail(
254 this->_devices->_handle,
263 auto error = InteropServices::Marshal::GetHRForLastWin32Error();
264 InteropServices::Marshal::ThrowExceptionForHR(error);
268 System::Console::WriteLine("[{0}] detail [{1}]",__FUNCTION__, detail);
269 System::Console::WriteLine("[{0}] info [{1}]", __FUNCTION__, info);
272 this->_devicePath = detail.DevicePath;
276 Interop::Setupapi::SpDeviceInterfaceData^ Devices::Detail::GetAlias(
277 Interop::Guiddef::Guid subCategory
281 System::Console::WriteLine("[{0}][{1}]",__FUNCTION__, subCategory);
283 auto data = Interop::Setupapi::SpDeviceInterfaceData();
284 data.cbSize = safe_cast<System::UInt32>(InteropServices::Marshal::SizeOf(data));
287 !Interop::Setupapi::Function::SetupDiGetDeviceInterfaceAlias(
288 this->_devices->_handle,
296 auto error = InteropServices::Marshal::GetHRForLastWin32Error();
297 System::Console::WriteLine("[{0}] error [{1}]",__FUNCTION__, InteropServices::Marshal::GetExceptionForHR(error)->ToString());
303 System::Console::WriteLine("[{0}] alias [{1}]", __FUNCTION__, data);
308 System::String^ Devices::Detail::GetDeviceRegistryProperty(
309 Interop::Setupapi::SPDRP spdrp
313 // System::Console::WriteLine("[{0}][{1}]",__FUNCTION__, spdrp);
315 System::UInt32 regDataType = 0;
316 System::UInt32 reqired = 0;
318 !Interop::Setupapi::Function::SetupDiGetDeviceRegistryProperty(
319 this->_devices->_handle,
329 auto error = InteropServices::Marshal::GetHRForLastWin32Error();
331 // System::Console::WriteLine("[{0}] error {1:X}",__FUNCTION__, error);
333 if (error != 0x8007007A)//ERROR_INSUFFICIENT_BUFFER
336 System::Console::WriteLine("[{0}] {1} [{2}]",__FUNCTION__, spdrp, InteropServices::Marshal::GetExceptionForHR(error)->ToString());
342 // System::Console::WriteLine("[{0}] reqired {1}",__FUNCTION__, reqired);
344 auto buf = gcnew System::Text::StringBuilder(safe_cast<System::Int32>(reqired));
347 !Interop::Setupapi::Function::SetupDiGetDeviceRegistryProperty(
348 this->_devices->_handle,
358 auto error = InteropServices::Marshal::GetHRForLastWin32Error();
360 // System::Console::WriteLine("[{0}] error {1:X}",__FUNCTION__, error);
362 InteropServices::Marshal::ThrowExceptionForHR(error);
366 System::Console::WriteLine("[{0}] {1} [{2}]",__FUNCTION__, spdrp, buf->ToString());
368 return buf->ToString();
371 System::String^ Devices::Detail::GetDeviceRegistryProperty(
376 // System::Console::WriteLine("[{0}][{1}]",__FUNCTION__, name);
378 Interop::Setupapi::Function::RegKey^ regKey;
382 Interop::Setupapi::Function::SetupDiOpenDeviceInterfaceRegKey(
383 this->_devices->_handle,
386 Interop::Kernel32::ACCESS_TYPES::KEY_READ
388 if (regKey->IsInvalid)
391 auto error = InteropServices::Marshal::GetHRForLastWin32Error();
392 System::Console::WriteLine("[{0}] error {1:X}",__FUNCTION__, InteropServices::Marshal::GetExceptionForHR(error)->ToString());
400 System::UInt32 type = 0;
401 System::UInt32 size = 1024;
402 auto data = InteropServices::Marshal::AllocHGlobal(size);
405 System::UInt32 error =
406 Interop::Setupapi::Function::RegQueryValueEx(
409 System::IntPtr::Zero,
415 // System::Console::WriteLine("[{0}] error {1:X}",__FUNCTION__, error);
420 System::Console::WriteLine("[{0}] msg {1}",__FUNCTION__, InteropServices::Marshal::GetExceptionForHR(error)->ToString());
425 auto result = InteropServices::Marshal::PtrToStringAuto(data);
427 System::Console::WriteLine("[{0}] {1} [{2}]",__FUNCTION__, name, result);
433 InteropServices::Marshal::FreeHGlobal(data);
444 Devices::DetailEnum::DetailEnum(
448 _index(0) //
\88ê
\94Ê
\93I
\82È
\97p
\96@
\82©
\82ç
\82Í
\8aO
\82µ
\82Ä
\81AMoveNext
\8cã
\82É+1
\82µ
\82Ä
\82¢
\82é
451 System::Console::WriteLine("[{0}]",__FUNCTION__);
455 System::Boolean Devices::DetailEnum::MoveNext()
464 (detail->IsNoMoreItems)
468 return !detail->IsNoMoreItems;
471 void Devices::DetailEnum::Reset()
473 this->_detail = nullptr;