Hi,
My conversion seems from VB6 to VB.Net of an interface to an API seem to
have gone OK, but when I look at the output from the Debug.Print("Ac tive
server is " & xmlServerActive ) statement, xmlServerActive only contains one
character(the first one). I suspect it is being truncated. I am pretty much a
novice at this sort of thing so any advice would be welcome.
Here is the old VB6 code:
Listening for Servers and System Status using VB
‘ Declare the functions
Public Declare Function RCA_listenForSe rversBstr Lib "clientapi. dll" _
(ByVal serverActiveCal lback As Long, _
ByVal serverShutdownC allback As Long) As Integer
Public Declare Function RCA_listenForSy stemStatusBstr Lib "clientapi. dll" _
(ByVal systemStatusCal lback As Long, _
ByVal clusterCreatedC allback As Long, _
ByVal clusterDeletedC allback As Long, _
ByVal systemException Callback As Long) As Integer
‘ Declare callback functions
Public Function serverActiveCal lback(ByVal xmlServerActive As String) As Long
Debug.Print "Active server is " & xmlServerActive
End Function
Public Function serverShutdownC allback(ByVal server As String) As Long
Debug.Print "Shutdown server is " & server
End Function
Public Function systemException Callback(ByVal error As String) As Long
MsgBox "Error : " & error
End Function
Public Function systemStatusCal lback(ByVal systemStatus As String) As Long
Debug.Print "System status is " & systemStatus
End Function
Public Function clusterCreatedC allback(ByVal cluster As String) As Long
Debug.Print "Created cluster is " & cluster
End Function
Public Function clusterDeletedC allback(ByVal cluster As String) As Long
Debug.Print "Deleted cluster is " & cluster
End Function
‘ Set up to listen for servers
ret = RCA_listenForSe rversBstr(Addre ssOf serverActiveCal lback, _
AddressOf serverShutdownC allback)
‘ Set up to listen for system status
ret = RCA_listenForSy stemStatusBstr( AddressOf systemStatusCal lback, _
AddressOf clusterCreatedC allback, _
AddressOf clusterDeletedC allback, _
AddressOf systemException Callback)
The new VB.NET (It has some other pieces I have added)
Option Strict Off
Option Explicit On
Module RimagesAPI
Public Structure RCA_production_ order_descripti on
<VBFixedString( 128),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=128) Public orderId() As Char ' This field cannot be NULL
<VBFixedString( 128),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=128) Public clientId() As Char ' This field is optional and can
be NULL
<VBFixedString( 128),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=128) Public originator() As Char ' This field is optional and can
be NULL
<VBFixedString( 128),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=128) Public targetCluster() As Char ' This field cannot be NULL
<VBFixedString( 128),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=128) Public targetServer() As Char ' This field is optional, if
null then any
<VBFixedString( 32),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=32)P ublic priority() As Char ' Default for this field is
PRIORITY_MEDIUM
<VBFixedString( 32),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=32)P ublic action() As Char ' Default for this field is
ACTION_RECORD
<VBFixedString( 32),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=32)P ublic mediaType() As Char ' Default for this field is MT_CDR
<VBFixedString( 32),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=32)P ublic mediaSize() As Char ' Default for this field is MS_120
<VBFixedString( 32),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=32)P ublic targetLine() As Char ' Default for this field is TL_ANY
<VBFixedString( 32),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=32)P ublic copies() As Char ' Default for this field is 1
<VBFixedString( 32),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=32)P ublic inOutInputBin() As Char ' Default for this field is
IOB_ANY
<VBFixedString( 32),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=32)P ublic outputMailslot( ) As Char ' Default for this field is 0
End Structure
Public Declare Function RCA_connect Lib "clientapi. dll" (ByVal clientId As
String) As Short
Public Declare Function RCA_connectEx Lib "clientapi. dll" (ByVal clientId
As String, ByVal host As String, ByVal port As String) As Short
Public Declare Function RCA_listenForSe rversBstr Lib "clientapi. dll"
(ByVal serverActiveCal lback As serverActiveCal lbackDelegate, ByVal
serverShutdownC allback As serverShutdownC allbackDelegate ) As Short
Public Declare Function RCA_listenForSy stemStatusBstr Lib
"clientapi. dll" (ByVal systemStatusCal lback As systemStatusCal lbackDelegate,
ByVal clusterCreatedC allback As clusterCreatedC allbackDelegate , ByVal
clusterDeletedC allback As clusterDeletedC allbackDelegate , ByVal
systemException Callback As systemException CallbackDelegat e) As Short
Public Declare Function RCA_submitProdu ctionOrderBstr Lib
"clientapi. dll" (ByRef orderDesc As RCA_production_ order_descripti on, ByVal
xmlOrder As String, ByVal orderStatusCall back As orderStatusCall backDelegate)
As Short
Public Declare Function RCA_cancelProdu ctionOrder Lib "clientapi. dll"
(ByRef orderDesc As RCA_production_ order_descripti on, ByVal abortCurrent As
Boolean) As Short
Public Declare Function RCA_stopListeni ngForProduction Order Lib
"clientapi. dll" (ByRef orderDesc As RCA_production_ order_descripti on) As Short
Delegate Function serverActiveCal lbackDelegate(B yVal xmlServerActive As
String) As Integer
Public Function serverActiveCal lback(ByVal xmlServerActive As String) As
Integer
Debug.Print("Ac tive server is " & xmlServerActive )
End Function
Delegate Function serverShutdownC allbackDelegate (ByVal server As String)
As Integer
Public Function serverShutdownC allback(ByVal server As String) As Integer
Debug.Print("Sh utdown server is " & server)
End Function
Delegate Function systemException CallbackDelegat e(ByVal wError As
String) As Integer
Public Function systemException Callback(ByVal wError As String) As Integer
MsgBox("Error : " & wError)
End Function
Delegate Function systemStatusCal lbackDelegate(B yVal systemStatus As
String) As Integer
Public Function systemStatusCal lback(ByVal systemStatus As String) As
Integer
Debug.Print("Sy stem status is " & systemStatus)
End Function
Delegate Function clusterCreatedC allbackDelegate (ByVal cluster As
String) As Integer
Public Function clusterCreatedC allback(ByVal cluster As String) As Integer
Debug.Print("Cr eated cluster is " & cluster)
End Function
Delegate Function clusterDeletedC allbackDelegate (ByVal cluster As
String) As Integer
Public Function clusterDeletedC allback(ByVal cluster As String) As Integer
Debug.Print("De leted cluster is " & cluster)
End Function
Delegate Function orderStatusCall backDelegate(By Val orderStatus As
String) As Integer
Public Function orderStatusCall back(ByVal orderStatus As String) As
Integer
On Error Resume Next
Debug.Print(ord erStatus)
orderStatusCall back = 0
End Function
My conversion seems from VB6 to VB.Net of an interface to an API seem to
have gone OK, but when I look at the output from the Debug.Print("Ac tive
server is " & xmlServerActive ) statement, xmlServerActive only contains one
character(the first one). I suspect it is being truncated. I am pretty much a
novice at this sort of thing so any advice would be welcome.
Here is the old VB6 code:
Listening for Servers and System Status using VB
‘ Declare the functions
Public Declare Function RCA_listenForSe rversBstr Lib "clientapi. dll" _
(ByVal serverActiveCal lback As Long, _
ByVal serverShutdownC allback As Long) As Integer
Public Declare Function RCA_listenForSy stemStatusBstr Lib "clientapi. dll" _
(ByVal systemStatusCal lback As Long, _
ByVal clusterCreatedC allback As Long, _
ByVal clusterDeletedC allback As Long, _
ByVal systemException Callback As Long) As Integer
‘ Declare callback functions
Public Function serverActiveCal lback(ByVal xmlServerActive As String) As Long
Debug.Print "Active server is " & xmlServerActive
End Function
Public Function serverShutdownC allback(ByVal server As String) As Long
Debug.Print "Shutdown server is " & server
End Function
Public Function systemException Callback(ByVal error As String) As Long
MsgBox "Error : " & error
End Function
Public Function systemStatusCal lback(ByVal systemStatus As String) As Long
Debug.Print "System status is " & systemStatus
End Function
Public Function clusterCreatedC allback(ByVal cluster As String) As Long
Debug.Print "Created cluster is " & cluster
End Function
Public Function clusterDeletedC allback(ByVal cluster As String) As Long
Debug.Print "Deleted cluster is " & cluster
End Function
‘ Set up to listen for servers
ret = RCA_listenForSe rversBstr(Addre ssOf serverActiveCal lback, _
AddressOf serverShutdownC allback)
‘ Set up to listen for system status
ret = RCA_listenForSy stemStatusBstr( AddressOf systemStatusCal lback, _
AddressOf clusterCreatedC allback, _
AddressOf clusterDeletedC allback, _
AddressOf systemException Callback)
The new VB.NET (It has some other pieces I have added)
Option Strict Off
Option Explicit On
Module RimagesAPI
Public Structure RCA_production_ order_descripti on
<VBFixedString( 128),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=128) Public orderId() As Char ' This field cannot be NULL
<VBFixedString( 128),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=128) Public clientId() As Char ' This field is optional and can
be NULL
<VBFixedString( 128),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=128) Public originator() As Char ' This field is optional and can
be NULL
<VBFixedString( 128),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=128) Public targetCluster() As Char ' This field cannot be NULL
<VBFixedString( 128),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=128) Public targetServer() As Char ' This field is optional, if
null then any
<VBFixedString( 32),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=32)P ublic priority() As Char ' Default for this field is
PRIORITY_MEDIUM
<VBFixedString( 32),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=32)P ublic action() As Char ' Default for this field is
ACTION_RECORD
<VBFixedString( 32),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=32)P ublic mediaType() As Char ' Default for this field is MT_CDR
<VBFixedString( 32),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=32)P ublic mediaSize() As Char ' Default for this field is MS_120
<VBFixedString( 32),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=32)P ublic targetLine() As Char ' Default for this field is TL_ANY
<VBFixedString( 32),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=32)P ublic copies() As Char ' Default for this field is 1
<VBFixedString( 32),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=32)P ublic inOutInputBin() As Char ' Default for this field is
IOB_ANY
<VBFixedString( 32),
System.Runtime. InteropServices .MarshalAs(Syst em.Runtime.Inte ropServices.Unm anagedType.ByVa lArray,
SizeConst:=32)P ublic outputMailslot( ) As Char ' Default for this field is 0
End Structure
Public Declare Function RCA_connect Lib "clientapi. dll" (ByVal clientId As
String) As Short
Public Declare Function RCA_connectEx Lib "clientapi. dll" (ByVal clientId
As String, ByVal host As String, ByVal port As String) As Short
Public Declare Function RCA_listenForSe rversBstr Lib "clientapi. dll"
(ByVal serverActiveCal lback As serverActiveCal lbackDelegate, ByVal
serverShutdownC allback As serverShutdownC allbackDelegate ) As Short
Public Declare Function RCA_listenForSy stemStatusBstr Lib
"clientapi. dll" (ByVal systemStatusCal lback As systemStatusCal lbackDelegate,
ByVal clusterCreatedC allback As clusterCreatedC allbackDelegate , ByVal
clusterDeletedC allback As clusterDeletedC allbackDelegate , ByVal
systemException Callback As systemException CallbackDelegat e) As Short
Public Declare Function RCA_submitProdu ctionOrderBstr Lib
"clientapi. dll" (ByRef orderDesc As RCA_production_ order_descripti on, ByVal
xmlOrder As String, ByVal orderStatusCall back As orderStatusCall backDelegate)
As Short
Public Declare Function RCA_cancelProdu ctionOrder Lib "clientapi. dll"
(ByRef orderDesc As RCA_production_ order_descripti on, ByVal abortCurrent As
Boolean) As Short
Public Declare Function RCA_stopListeni ngForProduction Order Lib
"clientapi. dll" (ByRef orderDesc As RCA_production_ order_descripti on) As Short
Delegate Function serverActiveCal lbackDelegate(B yVal xmlServerActive As
String) As Integer
Public Function serverActiveCal lback(ByVal xmlServerActive As String) As
Integer
Debug.Print("Ac tive server is " & xmlServerActive )
End Function
Delegate Function serverShutdownC allbackDelegate (ByVal server As String)
As Integer
Public Function serverShutdownC allback(ByVal server As String) As Integer
Debug.Print("Sh utdown server is " & server)
End Function
Delegate Function systemException CallbackDelegat e(ByVal wError As
String) As Integer
Public Function systemException Callback(ByVal wError As String) As Integer
MsgBox("Error : " & wError)
End Function
Delegate Function systemStatusCal lbackDelegate(B yVal systemStatus As
String) As Integer
Public Function systemStatusCal lback(ByVal systemStatus As String) As
Integer
Debug.Print("Sy stem status is " & systemStatus)
End Function
Delegate Function clusterCreatedC allbackDelegate (ByVal cluster As
String) As Integer
Public Function clusterCreatedC allback(ByVal cluster As String) As Integer
Debug.Print("Cr eated cluster is " & cluster)
End Function
Delegate Function clusterDeletedC allbackDelegate (ByVal cluster As
String) As Integer
Public Function clusterDeletedC allback(ByVal cluster As String) As Integer
Debug.Print("De leted cluster is " & cluster)
End Function
Delegate Function orderStatusCall backDelegate(By Val orderStatus As
String) As Integer
Public Function orderStatusCall back(ByVal orderStatus As String) As
Integer
On Error Resume Next
Debug.Print(ord erStatus)
orderStatusCall back = 0
End Function
Comment