Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Transfer COMobject from Visual Basic to Powershell

$
0
0

Hello,

What I got in VB:

Sub Main()
        Dim h As Object
        Dim id As Integer 'integer is data type int32 (4 bytes)
        Dim test As Integer


        Set h = CreateObject("CarSim.Application") 'Launch Carsim

        test = h.GetDataSetID("CarSim Run Control", "Braking example by COM", "COM Example", id)
End Sub

With the result: test=0 and id=333 (the correct ID).

When i transform this into a Powershell code:

PS C:\powershell> $carsim =New-Object -Com CarSim.Application
$x=[int32]0
$id = $carsim.GetDataSetID('CarSim Run Control',"Braking example by COM", "COM Example",$x)

Method invocation failed because [System.__ComObject] does not contain a method named
'GetDataSetID'.At line:3 char:1
+ $id = $carsim.GetDataSetID('CarSim Run Control',"Braking example by COM", "COM E ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException+ FullyQualifiedErrorId : MethodNotFound

But if i check $carsim for it's members the method 'GetDataSetID' is available:

PS C:\powershell> $carsim | Get-MemberTypeName:System.__ComObject#{1a52ca8a-4aba-45a9-9f3b-b56d5bd18c17}NameMemberTypeDefinition------------------------BatchRunMethodvoidBatchRun(string,string)...GetDataSetIDMethodvoidGetDataSetID(string,string,string,short)...

Where did I make a mistake?



Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images