这里导入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.改怎么调用???
#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.改怎么调用???
ICalc->CreateInstance(__uuidof(ITest));
这样也行?
在线等ing~~~
2.
CoInitialize();
CoCreateInstance(clsid, NULL, context, __uuidof(ITest), ICalc);
3. invoke ICalc method
包含dll会生成智能指针的定义,但是接口定义好像在头文件中才有。
你可以看看置顶,“来总结一下在VC中调用COM组件的方法(大家来补充)”
置顶的帖子我看了~~~
就是这里的问题没发解决include 头文件后那个问题解决了
现在我想问一下:
1 按照我的方法应该也可以的啊? 该怎么写才对呢?2 CoCreateInstance(clsid, NULL, ,CLSCTX_ALL, __uuidof(ITest), ICalc);
第一个参数clsid怎么写呢?
然后:一个console工程中:
CoInitialize(NULL);
ITestPtr *ICalc = NULL; //或者 CComPtr<ITest> ICalc = NULL;
ICalc->CreateInstance(__uuidof(CTest)); //如果CTest是接口的实现类的话