Re: Conversion from VB6 to VB.NET




"Mike M" <Mike M@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:922314A3-6E09-4EDD-9EE0-9E66D8717A9B@xxxxxxxxxxxxxxxx
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("Active
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.


I did a google search, and it sure looks like this api your referencing - actually has a .NET version already, so you might want to check into that. Never the less:

Here is the old VB6 code:
Listening for Servers and System Status using VB
‘ Declare the functions
Public Declare Function RCA_listenForServersBstr Lib "clientapi.dll" _
(ByVal serverActiveCallback As Long, _
ByVal serverShutdownCallback As Long) As Integer
Public Declare Function RCA_listenForSystemStatusBstr Lib "clientapi.dll" _
(ByVal systemStatusCallback As Long, _
ByVal clusterCreatedCallback As Long, _
ByVal clusterDeletedCallback As Long, _
ByVal systemExceptionCallback As Long) As Integer
‘ Declare callback functions
Public Function serverActiveCallback(ByVal xmlServerActive As String) As Long
Debug.Print "Active server is " & xmlServerActive
End Function
Public Function serverShutdownCallback(ByVal server As String) As Long
Debug.Print "Shutdown server is " & server
End Function
Public Function systemExceptionCallback(ByVal error As String) As Long
MsgBox "Error : " & error
End Function
Public Function systemStatusCallback(ByVal systemStatus As String) As Long
Debug.Print "System status is " & systemStatus
End Function
Public Function clusterCreatedCallback(ByVal cluster As String) As Long
Debug.Print "Created cluster is " & cluster
End Function
Public Function clusterDeletedCallback(ByVal cluster As String) As Long
Debug.Print "Deleted cluster is " & cluster
End Function
‘ Set up to listen for servers
ret = RCA_listenForServersBstr(AddressOf serverActiveCallback, _
AddressOf serverShutdownCallback)
‘ Set up to listen for system status
ret = RCA_listenForSystemStatusBstr(AddressOf systemStatusCallback, _
AddressOf clusterCreatedCallback, _
AddressOf clusterDeletedCallback, _
AddressOf systemExceptionCallback)


The new VB.NET (It has some other pieces I have added)
Option Strict Off

I would turn Option Strict On - pretty much always. There are few cases, such as late binding where it is useful to have it turned off, but I would not make it the general case.

Option Strict On

Imports System.Runtime.InteropServices ' save your self some typeing :)

Option Explicit On
Module RimagesAPI

Unless your planning to use this structure with VB.NET file IO - I would get rid of the VBFixedString attribute. Without the documentation and seeing the VB6 declaration, I would probably change the char arrays below to just plain old strings. I'm not sure what char set this is using, but I'll assume ansi:

<StructLayout (LayoutKind.Sequential, CharSet:=CharSet.Ansi) > _
Public Structure RCA_production_order_description
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> _
Public orderId As String ' This field cannot be NULL

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)>
Public clientId As String ' This field is optional and can be NULL
....
End Structure


Public Declare Ansi Function RCA_connect Lib "clientapi.dll" (ByVal clientId As String) As Short

Anyway, I am making some assumptions here that may or may not be correct, depending on this particular API - so I can't guarentee you that this is going to work :)

--
Tom Shelton

.



Relevant Pages

  • Conversion from VB6 to VB.NET
    ... Public Function serverActiveCallback(ByVal xmlServerActive As String) As Long ... Debug.Print "Active server is " & xmlServerActive ... Public Function systemStatusCallback(ByVal systemStatus As String) As Long ... Public Function clusterCreatedCallback(ByVal cluster As String) As Long ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Expert help needed
    ... server end. ... > Public Function UploadFileAs Byte, ... > ByVal FlName As String) As Boolean ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How to discover Exchange Server is an EVS (clustered)?
    ... Determining If the Specified Server Is a Clustered Server ... ' Exchange Management Library, Microsoft Cluster Service Automation Classes, ... Dim szConnString As String ... Set objContainer = objLdap.OpenDSObject(szConnString, _ ...
    (microsoft.public.exchange.development)
  • Re: Collections Woes - Help!
    ... Default Public Property ItemAs Server ... Public Sub AddRangeAs Server) ... Public Function ContainsAs Boolean ... > Default Public Property PathAs String ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Create a DLL with VB.NET to use it in ASP pages
    ... Imports System.IO ... Public Function LDAPgetAllEmails(ByVal domain As String) As String ... On the server I've registered it with regasm.exe but when I try to run ...
    (microsoft.public.dotnet.languages.vb)