什么可能导致我们的应用程序无法运行? C++
void CCaptureDlg::ListDevice()
{
((CComboBox *)GetDlgItem(IDC_COMBO_DEVICE))->ResetContent();
HRESULT hr;
IMoniker * pMoniker =NULL;
ULONG cFetched;
ICreateDevEnum * pDevEnum =NULL;
hr = CoCreateInstance (CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
IID_ICreateDevEnum, (void ** ) &pDevEnum);
if (FAILED(hr))
{
AfxMessageBox("Couldn't create system enumerator!");
return ;
}
IEnumMoniker * pClassEnum = NULL;
hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &pClassEnum, 0);
//hr = pDevEnum->CreateClassEnumerator (CLSID_LegacyAmFilterCategory, &pClassEnum, 0);
if (FAILED(hr))
{
AfxMessageBox("Couldn't create class enumerator!");
pDevEnum->Release();
return ;
}
if (pClassEnum == NULL)
{
AfxMessageBox("No video capture device was detected.");
pDevEnum->Release();
return ;
}
while(S_OK == (pClassEnum->Next (1, &pMoniker, &cFetched)))
{
IPropertyBag *pBag;
hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);
if(SUCCEEDED(hr))
{
CString ss;
VARIANT var;
var.vt = VT_BSTR;
hr = pBag->Read(L"FriendlyName", &var, NULL);
if (SUCCEEDED(hr))
{
ss.Format("%S",var.pbstrVal);
((CComboBox *)GetDlgItem(IDC_COMBO_DEVICE))->AddString(ss);
SysFreeString(var.bstrVal);
}
pBag->Release();
}
pMoniker->Release();
}
pClassEnum->Release();
pDevEnum->Release();
}
上面是我们应用程序的源代码,我们用它来列出所有视频设备,但是这个应用程序无法在某些安装了 Windows XP 的机器上运行。它提示我们“端口号无效”,有人可以告诉我可能的原因是什么吗?
void CCaptureDlg::ListDevice()
{
((CComboBox *)GetDlgItem(IDC_COMBO_DEVICE))->ResetContent();
HRESULT hr;
IMoniker * pMoniker =NULL;
ULONG cFetched;
ICreateDevEnum * pDevEnum =NULL;
hr = CoCreateInstance (CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
IID_ICreateDevEnum, (void ** ) &pDevEnum);
if (FAILED(hr))
{
AfxMessageBox("Couldn't create system enumerator!");
return ;
}
IEnumMoniker * pClassEnum = NULL;
hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &pClassEnum, 0);
//hr = pDevEnum->CreateClassEnumerator (CLSID_LegacyAmFilterCategory, &pClassEnum, 0);
if (FAILED(hr))
{
AfxMessageBox("Couldn't create class enumerator!");
pDevEnum->Release();
return ;
}
if (pClassEnum == NULL)
{
AfxMessageBox("No video capture device was detected.");
pDevEnum->Release();
return ;
}
while(S_OK == (pClassEnum->Next (1, &pMoniker, &cFetched)))
{
IPropertyBag *pBag;
hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);
if(SUCCEEDED(hr))
{
CString ss;
VARIANT var;
var.vt = VT_BSTR;
hr = pBag->Read(L"FriendlyName", &var, NULL);
if (SUCCEEDED(hr))
{
ss.Format("%S",var.pbstrVal);
((CComboBox *)GetDlgItem(IDC_COMBO_DEVICE))->AddString(ss);
SysFreeString(var.bstrVal);
}
pBag->Release();
}
pMoniker->Release();
}
pClassEnum->Release();
pDevEnum->Release();
}
Above is source code of our application, we use it to list all video device, but this application doesn't work on some machine with windows xp installed. it prompts us "invalid port number", Can someone tell me what's the possible reason?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只能想到一个有缺陷的视频捕获设备显示此错误消息,或者您未提供的代码的另一部分。此代码片段中没有任何内容可以执行此类提示。
如果你突然出现一个奇怪的消息框,你可以做的调试是在不关闭消息框的情况下使用调试器中断并检查窗口调用堆栈,以便识别弹出消息的 DLL...
I can only think of a buggy video capture device which shows this error message, or another part of your code which you did not provide. There is nothing here in this code snippet to do such a prompt.
If you have a weird message box coming out of nowhere, the debugging you can do is to break with debugger without closing the box and check the window call stack, in order to identify the DLL which pops up the message...