2012. 3. 14. 09:46
윈도우/참고
#include "stdafx.h" #include "stdio.h" #include "conio.h" // WMDM includes #include "mswmdm_i.c" #include "mswmdm.h" #include "sac.h" #include "scclient.h" void OutputNibble(BYTE b) { char ch = (b < 10) ? b += 48 : b+= 55; printf("%c", ch); } void OutputByte(BYTE b) { BYTE nb = b; nb = nb>>4; OutputNibble(nb); nb = b; nb = nb & 0x0F; OutputNibble(nb); } int main(int argc, char* argv[]) { HRESULT hr; IComponentAuthenticate* pICompAuth; CSecureChannelClient *m_pSacClient = new CSecureChannelClient; IWMDeviceManager3* m_pIdvMgr = NULL; //these are generic keys BYTE abPVK[] = {0x00}; BYTE abCert[] = {0x00}; printf("MTP Serial Numbers\n"); printf("==================\n"); CoInitialize(NULL); // get an authentication interface hr = CoCreateInstance(CLSID_MediaDevMgr, NULL, CLSCTX_ALL ,IID_IComponentAuthenticate, (void **)&pICompAuth); if SUCCEEDED(hr) { // create a secure channel client certificate hr = m_pSacClient->SetCertificate(SAC_CERT_V1, (BYTE*) abCert, sizeof(abCert), (BYTE*) abPVK, sizeof(abPVK)); if SUCCEEDED(hr) { // bind the authentication interface to the secure channel client m_pSacClient->SetInterface(pICompAuth); // trigger communication hr = m_pSacClient->Authenticate(SAC_PROTOCOL_V1); if SUCCEEDED(hr) { // get main interface to media device manager hr = pICompAuth->QueryInterface(IID_IWMDeviceManager2, (void**)&m_pIdvMgr); if SUCCEEDED(hr) { // we now have a media device manager interface... // enumerate devices... IWMDMEnumDevice *pIEnumDev; wchar_t pwsString[256]; char ch[256]; hr = m_pIdvMgr->EnumDevices2(&pIEnumDev); if SUCCEEDED(hr) { hr = pIEnumDev->Reset(); // Next will now return the first device if SUCCEEDED(hr) { printf(""); IWMDMDevice3* pIDevice; unsigned long ulNumFetched; size_t ret; hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched); while (SUCCEEDED(hr) && (hr != S_FALSE)) { // output device name hr = pIDevice->GetName(pwsString, 256); if SUCCEEDED(hr) { wcstombs_s(&ret, ch, 256, pwsString,_TRUNCATE); printf("Found device %s\n", ch); } // get serial number (if available) WMDMID serialNumber; BYTE mac[WMDM_MAC_LENGTH]; hr = pIDevice->GetSerialNumber(&serialNumber, mac); if SUCCEEDED(hr) { printf("Serial Number : 0x"); for (UINT i = 0; i < serialNumber.SerialNumberLength; i++) { OutputByte(serialNumber.pID[i]); } printf(" (%d bytes)\n", serialNumber.SerialNumberLength); } else { switch (hr) { case E_INVALIDARG: printf("GetSerialNumber failed -- invalid argument.\n"); break; case WMDM_E_NOTSUPPORTED: printf("GetSerialNumber failed -- this device doesn't support unique serial numbers.\n"); break; case E_FAIL: printf("GetSerialNumber failed -- unspecified error.\n"); break; } } // move to next device hr = pIEnumDev->Next(1, (IWMDMDevice **)&pIDevice, &ulNumFetched); } pIEnumDev->Release(); } m_pIdvMgr->Release(); } pICompAuth->Release(); } } } } char c = _getch(); CoUninitialize(); return 0; }
출처 : http://opensource.creative.com/mtp_serial_code.txt
'윈도우 > 참고' 카테고리의 다른 글
Fiddler 다운로드 사이트 (0) | 2012.04.05 |
---|---|
Invalid address specified to RtlFreeHeap( 00130000, 0098D730 ) (0) | 2012.04.04 |
MTP 디바이스가 연결 될때 받는 메시지 핸들러 (0) | 2012.03.13 |
IWMDMStorage Interface (0) | 2012.03.09 |
휴대용 디지털 기기의 콘텐츠 이동을 위한 프로토콜 방식인 MSC과 MTP (0) | 2012.02.27 |