COM Automation 参数传递问题[in,out]

ttff 2001-03-25 02:06:00
已经有了导入库,关于Call函数

void __fastcall Call(TVariant* paramNames/*[in,out,opt]*/= TNoParam(),
TVariant* paramVals/*[in,out,opt]*/= TNoParam())
{
_TDispID _dispid(/* Call */ DISPID(1015));
TAutoArgs<2> _args;
_args[1] = paramNames /*[VT_VARIANT:1]*/;
_args[2] = paramVals /*[VT_VARIANT:1]*/;
OleProcedure(_dispid, _args);
}

应用程序参考手册对paramNames和paramVals的描述:
Parameters

Name Type Description
paramNames array of strings by ref Names of the front panel
objects that act as input
and output parameters to
the call.
paramVals array of variants by ref Input values for the input
parameters and return values
from the output parameters
in the order in which the
names were specified in
paramNames. Designates the
front panel object values
for the input parameters.
The values of parameters can
be numeric, Boolean, string,
or array. A cluster in
LabVIEW is represented as an
array of variants in ActiveX.


有一个VB的例子。如下:

Dim ParamNames(0 To 1) As String '传入参数的名称
Dim ParamVals(0 To 1) As Variant '传入(出)的值

'Declare the object type of a lvApp and VI
Dim lvApp As LabVIEW.Application
Dim VI As LabVIEW.VirtualInstrument
Dim VIPath As String


Private Sub Form_Load()
'Clear the form indicators
ArithmeticExpression.Text = ""
Result.Text = ""

'Initialize the variables & define the strings corresponding to
'the VI connector labels. Note that the strings are case sensitive
ParamNames(0) = "Arithmetic Expression"
ParamNames(1) = "Result"
End Sub


Private Sub Launch_Click()
'Create a reference to LabVIEW
Set lvApp = CreateObject("LabVIEW.Application")

'Determine the path to the VI
VIPath = lvApp.ApplicationDirectory + "\Examples\General\Strings.llb\Parse Arithmetic Expression.vi"

'Assign an object reference to VI
Set VI = lvApp.GetVIReference(VIPath)

Launch.Enabled = False
Run.Enabled = True
Run.SetFocus
Ex.Enabled = True
End Sub


Private Sub Run_Click()
'Get values from front panel objects
ParamVals(0) = ArithmeticExpression.Text

'Check if front panel of VI should be displayed
If ShowPanel.Value = 1 Then
VI.ShowFPOnCall = True
Else
VI.ShowFPOnCall = False
End If

'Call the VI
Call VI.Call(ParamNames, ParamVals)

'Display the result
Result.Text = ParamVals(1)
End Sub


Private Sub Ex_Click()
'Close LabVIEW
If Not IsNull(lvApp) Then
lvApp.Quit
Run.Enabled = False
Ex.Enabled = False
Launch.Enabled = True
Launch.SetFocus
End If
End Sub


Private Sub Quit_Click()
'Quit the application
End
End Sub

这是应用软件给的例程可以运行。paramNames和paramVals可以传入(出)值。

以下是我编的一个sample。
//App1是导入到入库后在ActiveX页下生成的TApp的实例

void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString path;
Labview_tlb::VirtualInstrumentPtr vi;
path=AnsiString(App1->ApplicationDirectory)+"\\Examples\\General\\Strings.llb\\Parse Arithmetic Expression.vi";

vi=App1->GetVIReference(WideString(path),NULL,NULL);

TVariant paramNames[2],paramVals[2];
paramNames[0]="Arithmetic Expression";
paramNames[1]="Result";
paramVals[0]=tinput->Text;

vi->ShowFPOnCall=true;
vi->Call(paramNames,paramVals);
toutput->Text=paramVals[1];
}

发现paramNames,和paramVals无法传入(出)值,不知哪位大虾对此有研究。




...全文
92 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
我不懂电脑 2001-03-25
  • 打赏
  • 举报
回复
是在98下用吧?
ttff 2001-03-25
  • 打赏
  • 举报
回复
Win 2k Pro

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧