描述:
这里导入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:
你把 Atl 工程下的 一个 ***_i.c的文件包含到测试工程中试试! 那个文件中包含了ITest 的接口定义!
解决方案2:ITestPtr *ICalc = NULL 吧?
解决方案3: 1. 你copy什么都得把头文件include 进来。
2.
CoInitialize();
CoCreateInstance(clsid, NULL, context, __uuidof(ITest), ICalc);
3. invoke ICalc method