int __cdecl main(int /*argc*/, char ** /*argv[]*/)
{
HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (FAILED(hr))
{
printf(_T("CoInitializeEx failed!!!\n"));
return 0;
}
{
GWTest gwTest ;
if (gwTest.Initialize())
{
gwTest.Execute();
}
gwTest.Terminate();
}
::CoUninitialize();
return 0;
}
void GWTest::Execute()
{
USES_CONVERSION;
if ( !GetPoolNames() )
return ;
for ( ULONG i = 0 ; i < m_culSessions ; i++ )
{
m_sprghSessions[i] = (HANDLE)_beginthread(HandleSession, 0, (LPVOID)OLE2A(m_sprgbstr[i]));
if (NULL == m_sprghSessions[i])
{
::SetEvent(m_hEvtStopSvc);
break ;
}
}
if ( WAIT_TIMEOUT == ::WaitForMultipleObjects( m_culSessions , m_sprghSessions, TRUE , INFINITE ) )
{
DisplayMsg(_T("Some session threads are still running!!\n")) ;
}
}
bool GWTest::GetPoolNames()
{
HRESULT hr = S_OK;
bool rc = true;
int cDevices = 1;
long lCount;
int Index = 0;
CComPtr<IWSConfiguredDevices> spicd;
VARIANT var;
::VariantInit(&var) ;
printf("GetPoolNames함수 호출.\n");
hr = spicd.CoCreateInstance(CLSID_WSConfiguredDevices);
printf("hr의 반환값 %d\n",hr);
if (FAILED(hr))
{
char buf [256];
sprintf (buf, "CoCreateInstance of IWSConfiguredDevices failed: 0x%x\n", hr);
DisplayMsg(_T(buf)) ;
return false ;
}
spicd->Register((BSTR)"saprt");
hr = spicd->get_Count(&lCount);
if (FAILED(hr))
{
char buf [256];
sprintf (buf, "IWSConfiguredDevices::get_Count failed: 0x%x\n", hr);
DisplayMsg(_T(buf)) ;
return false ;
}
//if (lCount > 35)
//lCount = 35;
printf("lCount의 반환값 %d\n",lCount);
m_sprgbstr = new CComBSTR[lCount] ;
m_sprghSessions = new HANDLE[lCount] ;
for (int i = 0; i < lCount; i++)
m_sprghSessions [i] = NULL;
printf("%d\n",&hr);
for (cDevices = 1; (cDevices <= lCount) && SUCCEEDED(hr); cDevices++)
{
hr = spicd->get_Item(cDevices , &var);
if (SUCCEEDED(hr))
{
CComQIPtr<IWSDevice> spiWSDevice = var.punkVal;
if (spiWSDevice == NULL)
break;
WSDeviceType wsDevType;
hr = spiWSDevice->get_DeviceType(&wsDevType);
if (FAILED(hr))
break ;
if ((wsDevType == DT_DIR) || (wsDevType == DT_CRT))
{
CComBSTR bstr ;
hr = spiWSDevice->get_Poolname(&bstr);
if (FAILED(hr))
break ;
m_sprgbstr[Index++] = bstr ;
}
}
printf("%d\n",&hr);
}
m_culSessions = (ULONG)Index;
::VariantClear( &var ) ;
if (FAILED(hr))
rc = false ;
return rc;
}
실행 코드 상에 왜 lCount =0이 나오고..왜 구동이 안되는 건지 알수 있을까요?
[최초 등록일: ]
[최종 수정일: 12/10/2005]