[英]How can I define this struct in my COM library?
I created a new ATL project in Visual Studio 2015. I added a new simple ATL object, inside of the library I am trying to define a struct
so that I may pass this struct
around in my COM implementation. 我在Visual Studio 2015中创建了一个新的ATL项目。我试图在库中添加一个新的简单ATL对象,以定义一个
struct
以便可以在COM实现中传递该struct
。 Here is my CerberusNative.idl
definition, with the added CerberusErrorDetails
structure: 这是我的
CerberusNative.idl
定义,其中添加了CerberusErrorDetails
结构:
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(B98A7D3F-651A-49BE-9744-2B1D8C896E9E),
dual,
nonextensible,
pointer_default(unique)
]
interface ICerberusSession : IDispatch{
};
[
uuid(8F2227F9-10A9-4114-A683-3CBEB02BD6DA),
version(1.0),
]
library CerberusNativeLib
{
[
uuid(527568A1-36A8-467A-82F5-228F7C3AC926)
]
typedef struct CerberusErrorDetails
{
INT ErrorCode;
BSTR ErrorMessage;
};
importlib("stdole2.tlb");
[
uuid(CAB8A88E-CE0E-4B4C-B656-C52A7C8A5B18)
]
coclass CerberusSession
{
[default] interface ICerberusSession;
};
};
When I try to compile it, I get the following error: 当我尝试编译它时,出现以下错误:
Error MIDL2312 illegal syntax unless using mktyplib compatibility mode : CerberusErrorDetails CerberusNative CerberusNative.idl 32
错误MIDL2312非法语法,除非使用mktyplib兼容模式:CerberusErrorDetails CerberusNative CerberusNative.idl 32
Am I doing something wrong? 难道我做错了什么? What is this
mktyplib
error? 这是什么
mktyplib
错误? Why is it asking for it? 为什么要这样呢?
Syntax was wrong. 语法错误。 Correct way:
正确方法:
typedef
[
uuid(527568A1-36A8-467A-82F5-228F7C3AC926),
version(1.0)
]
struct CerberusErrorDetails {
INT ErrorCode;
BSTR ErrorMessage;
} CerberusErrorDetails;
The error appears to be: 该错误似乎是:
[
uuid(527568A1-36A8-467A-82F5-228F7C3AC926)
]
typedef struct tagCerberusErrorDetails
{
INT ErrorCode;
BSTR ErrorMessage;
} CerberusErrorDetails; /// <- You forgot this
Note that what you appear to be attempting you should probably consider using ISupportErrorInfo
/ IErrorInfo
which is the standard way of reporting error numbers and messages. 请注意,您似乎正在尝试的操作可能应该考虑使用
ISupportErrorInfo
/ IErrorInfo
,这是报告错误编号和消息的标准方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.