|
-
March 18th, 2009, 08:34 PM
#1
SAFEARRAY - how to use
I am trying to write a VB code to use a DCOM through a DLL. The application is based on OPC HDA Server and I am using OPCHDAAuto.dll. I took the code from HDA specification and it is showed bellow:
Code:
Sub access_values()
Dim AnOPCHDAServer As OPCHDAServer
Dim ARealOPCHDAServer As String
Dim ARealOPCNodeName As String
Dim AnOPCHDAItemCollection As OPCHDAItems
Dim AnOPCHDAItem As OPCHDAItem
Dim ClientHandles(100) As Long
Dim AnOPCHDAItemIDs(100) As String
Dim AnOPCHDAItemServerHandles(10) As Long
Dim AnOPCHDAItemServerErrors(10) As Long
Dim AddItemCount As Long
Dim i As Integer
Set AnOPCHDAServer = New OPCHDAServer
ARealOPCHDAServer = "HDATestSvr"
ARealOPCNodeName = "localhost"
AnOPCHDAServer.Connect ARealOPCHDAServer, ARealOPCNodeName
Set AnOPCHDAItemCollection = AnOPCHDAServer.OPCHDAItems
'Dim AnOPCHDAItemIDs() As String
'Dim AnOPCHDAItemServerHandles As Long
'Dim AnOPCHDAItemServerErrors As Long
AddItemCount = 2
For i = 1 To AddItemCount
ClientHandles(i) = i
AnOPCHDAItemIDs(i) = "A.A.A"
Next i
AnOPCHDAItemIDs(2) = "A.A.B"
AnOPCHDAItemCollection.AddItems AddItemCount, _
AnOPCHDAItemIDs, _
ClientHandles, _
AnOPCHDAItemServerHandles, _
AnOPCHDAItemServerErrors
' add code to process any errors that are returned from 'the method, individual errors are reported in the Errors array
End Sub
The declaration, in the IDL file, of AddItems method of the IOPCHDAItems interface is :
Code:
[helpstring("Adds OPCHDAItem objects to the collection")]
HRESULT AddItems(
[in] LONG NumItems,
[in] SAFEARRAY(BSTR) * ItemIDs,
[in] SAFEARRAY(LONG) * ClientHandles,
[out] SAFEARRAY(LONG) * ServerHandles,
[out] SAFEARRAY(LONG) * Errors);
and in VB is:
AddItems (NumItems As Long, ItemIDs() As String, ClientHandles() As Long, ByRef ServerHandles() As Long, ByRef Errors() As Long)
When I try to run it I get the message Type mismatch.
Someone could help me on that issue?
I appreciate any help.
Last edited by Shuja Ali; March 19th, 2009 at 02:24 PM.
Reason: Added code tags
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|