用ATLCOMAppWinzard加方法时出现编译错误:syntaxerror:expecting]or,near"int"
描述:
刚开始接触COM 遇到这个编译问题无从下手请问高手几个问题:
我的idl代码为:
////////////////////////////////////
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(608DFA72-8706-4802-B3CB-A3CE164B34EE),
dual,
helpstring("IQuestion Interface"),
pointer_default(unique)
]
interface IQuestion : IDispatch
{
[propget, id(1), helpstring("retrives content")] HRESULT content([out, retval] BSTR *pVal);
[propget, id(2), helpstring("retrives Q1")] HRESULT Q1([out, retval] BSTR *pVal);
[propget, id(3), helpstring("retrives Q2")] HRESULT Q2([out, retval] BSTR *pVal);
[propget, id(4), helpstring("retrives Q3")] HRESULT Q3([out, retval] BSTR *pVal);
[propget, id(5), helpstring("retrives Q4")] HRESULT Q4([out, retval] BSTR *pVal);
[propget, id(6), helpstring("retrives Q5")] HRESULT Q5([out, retval] BSTR *pVal);
[propget, id(7), helpstring("retrives Answer")] HRESULT Answer([out, retval] BSTR *pVal);
//======> [id(8), helpstring("method GetQuestion")] HRESULT GetQuestion([int] int x_nType, int x_nQID,BSTR *x_QInfo);
};
[
uuid(1528EF96-2B7D-42EB-9376-9B8DBE6E3800),
version(1.0),
helpstring("Qestion_info 1.0 Type Library")
]
library QESTION_INFOLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
uuid(74F93E79-0548-462B-A2C8-6F2A3EB4EE1A),
helpstring("Question Class")
]
coclass Question
{
[default] interface IQuestion;
};
};
//编译结果
error MIDL2025 : syntax error : expecting ] or , near "int"
////////////////////////////////////////////////////////////////////////
问题:1,这怎么解决?
2,可不可以把该行[int]去掉,(我试过去掉之后带来其它的错误,如XXXX前缺";"错误),为什么?[int]有什么作用?
谢谢!
解决方案1:
这个文件不是向导自动产生是你自己编辑的吧
1、helpstring("retrives Q5")] 多出个"]"
2、[int]应该是[in],去掉也不影响