_DataProvider *dataPro; HRESULT hresult; CLSID clsid; IUnknown *pUnk = NULL; CoInitialize(NULL); //initialize COM library hresult=CLSIDFromProgID(OLESTR("T24DataProviderCOM.DataProvider"), &clsid); if(FAILED(hresult)) { MessageBox(NULL,L"ProgID",L"test",MB_OKCANCEL); } hresult=CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,__uuidof(_DataProvider),(LPVOID *) &dataPro); if(FAILED(hresult)) { MessageBox(NULL, L"失败",L"test",MB_OKCANCEL); } _DataProviderPtr m_spDataProvider; HRESULT hr = m_spDataProvider.CreateInstance(__uuidof(DataProvider)); if(FAILED(hr)) { MessageBox(_T("创建对象失败"), _T("错误"), MB_ICONERROR); EndDialog(IDCANCEL); return FALSE; }