首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

CoCreateInstance有关问题

2012-08-13 
CoCreateInstance问题C/C++ code#include ..\Simple_ATL\Simple_ATL.h#include iostream.h// Copy the

CoCreateInstance问题

C/C++ code
#include "..\Simple_ATL\Simple_ATL.h"#include <iostream.h>// Copy the following from the Simple_ATL_i.c file// from the Simple_ATL project directoryconst IID IID_IFirst_ATL = {0x8958F781,0xC2B1,0x497B,{0x8C,0x46,0x48,0x30,0xE3,0x8A,0xDA,0x71}};const CLSID CLSID_First_ATL = {0x146EC893,0xDA14,0x41BC,{0xAF,0x12,0x19,0xB7,0x6B,0x61,0xCE,0x23}};void main(void){    // Declare and HRESULT and a pointer to the Simple_ATL interface    HRESULT hr=S_FALSE;    IFirst_ATL *IFirstATL=NULL;        // Now we will intilize COM    hr = CoInitialize(0);        // Use the SUCCEEDED macro and see if we can get a pointer     // to the interface    if(SUCCEEDED(hr))    {        hr = CoCreateInstance(CLSID_First_ATL, NULL, CLSCTX_INPROC_SERVER,            IID_IFirst_ATL, (void**)&IFirstATL);                cout<<GetLastError()<<endl;        // If we succeeded then call the AddNumbers method, if it failed        // then display an appropriate message to the user.        if(SUCCEEDED(hr))        {            long ReturnValue;            IFirstATL->AddNumbers(5, 7, &ReturnValue);            cout << "The answer for 5 + 7 is: " << ReturnValue << endl;            IFirstATL->Release();          }        else        {            cout << "CoCreateInstance Failed." << endl;        }    }    // Uninitialize COM    CoUninitialize();}


SUCCEEDED(hr)不成功,
GetLastError()得到1008

是不是CoCreateInstance使用问题,各位帮忙看看

[解决办法]
是你的控件的 原因
[解决办法]
〖1008〗-试图引用不存在的令牌
--- COM组件是否注册成功等
[解决办法]
一般直接看返回值hr是什么,而不是看getlasterror
正常来说,只要你的CLSID_First_ATL是对了,组件注册到注册表就没问题的

热点排行