使用 MIDL 编译时不知道 SAFEARRAY 类型
SAFEARRAY type not known when compiling using MIDL
我的 ODL 文件如下所示:
import "oaidl.idl";
import "ocidl.idl";
[oleautomation, uuid(/* redacted */)]
interface ISomething : IUnknown
{
HRESULT DoSomething(
[in]BSTR User,
[in]VARIANT Object,
[in]SAFEARRAY Array // may be NULL
);
}
我遇到错误:
1>.\Something.odl(17): error MIDL2139: type of the parameter cannot
derive from void or void * : [ Type 'PVOID' ( Parameter 'Array' ) ]
1>.\Something.odl(17): error MIDL2105: pointee / array does not derive
any size : [ Field 'rgsabound' of Struct 'tagSAFEARRAY' ( Parameter
'Array' ) ] 1>.\Something.odl(17): error MIDL2465: Structures
containing conformant arrays must be passed by reference. See MSDN for
more details : [ Struct 'tagSAFEARRAY' ( Parameter 'Array' ) ]
如果我将类型从 SAFEARRAY
更改为 SAFEARRAY*
(我认为这不正确?)我会收到不同的错误:
1>.\Something.odl(17): error MIDL2139: type of the parameter cannot
derive from void or void * : [ Type 'PVOID' ( Parameter 'Array' ) ]
1>.\Something.odl(17): error MIDL2105: pointee / array does not derive
any size : [ Field 'rgsabound' of Struct 'tagSAFEARRAY' ( Parameter
'Array' ) ]
这只是我需要包含其他一些 headers 的情况吗?我在 VS2013 中使用 MIDL 编译器进行编译,显然 command-line 看起来像这样:
/iid "./source/Something_i.c" /h "Something.h" /W1 /char signed /notlb /app_config /nologo /dlldata "./source/Something_dlldata.c" /proxy "./source/Something_p.c"
您需要告诉它您的 SafeArray 中的元素类型。例如 SAFEARRAY(unsigned char) *Data for an array of unsigned chars。如果数组元素的数据类型在运行时是可变的,您可以将元素作为 VARIANT 的 SafeArray 传递。例如:
import "oaidl.idl";
import "ocidl.idl";
[oleautomation, uuid(/* redacted */)]
interface ISomething : IUnknown
{
HRESULT DoSomething(
[in]BSTR User,
[in]VARIANT Object,
[in]SAFEARRAY(unsigned char) *Array // may be NULL
);
}
我的 ODL 文件如下所示:
import "oaidl.idl";
import "ocidl.idl";
[oleautomation, uuid(/* redacted */)]
interface ISomething : IUnknown
{
HRESULT DoSomething(
[in]BSTR User,
[in]VARIANT Object,
[in]SAFEARRAY Array // may be NULL
);
}
我遇到错误:
1>.\Something.odl(17): error MIDL2139: type of the parameter cannot derive from void or void * : [ Type 'PVOID' ( Parameter 'Array' ) ] 1>.\Something.odl(17): error MIDL2105: pointee / array does not derive any size : [ Field 'rgsabound' of Struct 'tagSAFEARRAY' ( Parameter 'Array' ) ] 1>.\Something.odl(17): error MIDL2465: Structures containing conformant arrays must be passed by reference. See MSDN for more details : [ Struct 'tagSAFEARRAY' ( Parameter 'Array' ) ]
如果我将类型从 SAFEARRAY
更改为 SAFEARRAY*
(我认为这不正确?)我会收到不同的错误:
1>.\Something.odl(17): error MIDL2139: type of the parameter cannot derive from void or void * : [ Type 'PVOID' ( Parameter 'Array' ) ] 1>.\Something.odl(17): error MIDL2105: pointee / array does not derive any size : [ Field 'rgsabound' of Struct 'tagSAFEARRAY' ( Parameter 'Array' ) ]
这只是我需要包含其他一些 headers 的情况吗?我在 VS2013 中使用 MIDL 编译器进行编译,显然 command-line 看起来像这样:
/iid "./source/Something_i.c" /h "Something.h" /W1 /char signed /notlb /app_config /nologo /dlldata "./source/Something_dlldata.c" /proxy "./source/Something_p.c"
您需要告诉它您的 SafeArray 中的元素类型。例如 SAFEARRAY(unsigned char) *Data for an array of unsigned chars。如果数组元素的数据类型在运行时是可变的,您可以将元素作为 VARIANT 的 SafeArray 传递。例如:
import "oaidl.idl";
import "ocidl.idl";
[oleautomation, uuid(/* redacted */)]
interface ISomething : IUnknown
{
HRESULT DoSomething(
[in]BSTR User,
[in]VARIANT Object,
[in]SAFEARRAY(unsigned char) *Array // may be NULL
);
}