这里导入dll:
#import "F:\\VPN\\TestProjects\\tempcom\\Debug\\tempcom.dll"
然后:一个console工程中:
            CoInitialize(NULL);
ITest *ICalc = NULL
ICalc->CreateInstance(__uuidof(ITest));
int *ret = NULL;
ICalc->Mul (2, 3 ,ret);
ICalc->Release ();
cout<<"ret = "<<*ret<<endl;TestCom是一个ATL COM Wizard工程名字  然后我自己加了一个ATL 资源 接口名ITest 
出错:'ICalc' : undeclared identifier
F:\VPN\TestProjects\Testio\Testio.cpp(42) : error C2106: '=' : left operand must be l-value
F:\VPN\TestProjects\Testio\Testio.cpp(42) : error C2146: syntax error : missing ';' before identifier 'ICalc'
F:\VPN\TestProjects\Testio\Testio.cpp(42) : error C2227: left of '->CreateInstance' must point to class/struct/union
F:\VPN\TestProjects\Testio\Testio.cpp(44) : error C2227: left of '->Mul' must point to class/struct/union
F:\VPN\TestProjects\Testio\Testio.cpp(45) : error C2227: left of '->Release' must point to class/struct/union
Error executing cl.exe.改怎么调用???

解决方案 »

  1.   

    ITest *ICalc = NULL
    ICalc->CreateInstance(__uuidof(ITest));
    这样也行?
      

  2.   

    分号是我贴的时候贴掉了 不好意思~~~
    在线等ing~~~
      

  3.   

    你把 Atl 工程下的 一个 ***_i.c的文件包含到测试工程中试试! 那个文件中包含了ITest 的接口定义!
      

  4.   

    一样 而且我是直接copy了dll就不用_i.c文件了吧
      

  5.   

    1. 你copy什么都得把头文件include 进来。
    2. 
    CoInitialize();
    CoCreateInstance(clsid, NULL, context, __uuidof(ITest), ICalc);
    3. invoke ICalc method
      

  6.   

    ITestPtr *ICalc = NULL 吧?
      

  7.   

    同意wzp11252000(高歌猛进) 的做法,
    包含dll会生成智能指针的定义,但是接口定义好像在头文件中才有。
    你可以看看置顶,“来总结一下在VC中调用COM组件的方法(大家来补充)”
      

  8.   

    多谢大家关注 
    置顶的帖子我看了~~~
    就是这里的问题没发解决include 头文件后那个问题解决了 
    现在我想问一下:
    1 按照我的方法应该也可以的啊? 该怎么写才对呢?2 CoCreateInstance(clsid, NULL, ,CLSCTX_ALL, __uuidof(ITest), ICalc);
    第一个参数clsid怎么写呢?
      

  9.   

    #import "F:\\VPN\\TestProjects\\tempcom\\Debug\\tempcom.dll"  no_namespace
    然后:一个console工程中:
                CoInitialize(NULL);
    ITestPtr *ICalc = NULL;  //或者 CComPtr<ITest> ICalc = NULL;
    ICalc->CreateInstance(__uuidof(CTest));  //如果CTest是接口的实现类的话
      

  10.   

    CreateInstance()不对, 应该是CoCreateInstance ?
      

  11.   

    yes, you should evoke CoCreateInstance() to create object.