- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试调用 COM 对象的方法。该方法(在 OLEView 中)如下所示:-
VARIANT_BOOL GetValues(
[out] rsValues** values,
[in, optional] rsCategory* category,
[in, optional] rsProcess* process);
最后两个参数是可选的,我想从调用中“省略”它们(仅传递 NULL 不起作用)。
我的理解是,Delphi/C++Builder 类型库导入程序生成的所有 COM 包装器都会将每个传递的参数转换为变体。但要传递“省略”参数,我想我必须构造一个像这样的特殊变体。
varOpt.vt = VT_ERROR;
varOpt.sCode = DISP_E_PARAMNOTFOUND;
这似乎意味着我无法使用任何自动生成的组件包装器。
如何(使用 C++Builder 或 Delphi - 我应该能够将 Delphi 转换为 C++)调用该方法并传递“省略”变体?
更新
以下是我按照 David Heffernan 的回答中的建议尝试调用该方法的方法。
procedure TForm38.Wibble(obj : IrsObject);
var vals : IrsValues;
begin
ps.GetValues(vals, emptyparam, emptyparam);
但这给出了这个错误:
[DCC Error] E2010 Incompatible types: 'IrsCategory' and 'OleVariant'
[DCC Error] E2010 Incompatible types: 'IrsProcess' and 'OleVariant'
<小时/>
由于我使用的是非“Disp”对象,因此我相信我正在使用早期绑定(bind)。
我试图避免发布 45000 行的 foo_TLB.pas 文件,但这里(我希望)是相关部分。
IrsCategory = interface;
IrsCategoryDisp = dispinterface;
IrsProcess = interface;
IrsProcessDisp = dispinterface;
// *********************************************************************//
// Interface: IrsObject
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {861817F7-EA49-49D1-89FC-395BCA57E342}
// *********************************************************************//
IrsObject = interface(IDispatch)
['{861817F7-EA49-49D1-89FC-395BCA57E342}']
...
function GetValues(out values : IrsValue;
const Category: IrsCategory;
const Process: IrsProcess):): WordBool; safecall;
...
end;
// *********************************************************************//
// Interface: IrsObjectDisp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {861817F7-EA49-49D1-89FC-395BCA57E342}
// *********************************************************************//
IrsObjectDisp = dispinterface ... // basically the same, repeated
最佳答案
海森堡选项 1
您正在使用自动化接口(interface),可能带有后期绑定(bind)的 COM,并且参数都是变体。
通行证EmptyParam
到这些参数。
function EmptyParam: OleVariant;
Contains an OleVariant that represents an unused optional parameter on a dual interface.
EmptyParam can be used for Variants that represent optional parameters whose value is unassigned. This is useful when the code that marshals method calls requires a fixed number of parameters, even if some of them are optional.
When marshaling interface calls that include optional parameters, COM requires a value for those parameters even when they are not used. EmptyParam returns an OleVariant you can pass as that value to indicate that the parameter is not used.
海森堡选项 2
您正在使用早期绑定(bind)的 COM,参数是接口(interface)。
将 nil
传递给这些参数以省略它们。如果参数是 COM 接口(interface)而不是变体,那么这是您唯一可能的选择。 COM 接口(interface)变量必须是有效接口(interface),或者nil
。
关于delphi - Delphi/C++Builder COM 的可选参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24491125/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!