473,394 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Conversion from VB6 to VB.NET

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.

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
Option Explicit On
Module RimagesAPI

Public Structure RCA_production_order_description
<VBFixedString(128),
System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.UnmanagedType.ByValArray,
SizeConst:=128)Public orderId() As Char ' This field cannot be NULL
<VBFixedString(128),
System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.UnmanagedType.ByValArray,
SizeConst:=128)Public clientId() As Char ' This field is optional and can
be NULL
<VBFixedString(128),
System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.UnmanagedType.ByValArray,
SizeConst:=128)Public originator() As Char ' This field is optional and can
be NULL
<VBFixedString(128),
System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.UnmanagedType.ByValArray,
SizeConst:=128)Public targetCluster() As Char ' This field cannot be NULL
<VBFixedString(128),
System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.UnmanagedType.ByValArray,
SizeConst:=128)Public targetServer() As Char ' This field is optional, if
null then any
<VBFixedString(32),
System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.UnmanagedType.ByValArray,
SizeConst:=32)Public priority() As Char ' Default for this field is
PRIORITY_MEDIUM
<VBFixedString(32),
System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.UnmanagedType.ByValArray,
SizeConst:=32)Public action() As Char ' Default for this field is
ACTION_RECORD
<VBFixedString(32),
System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.UnmanagedType.ByValArray,
SizeConst:=32)Public mediaType() As Char ' Default for this field is MT_CDR
<VBFixedString(32),
System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.UnmanagedType.ByValArray,
SizeConst:=32)Public mediaSize() As Char ' Default for this field is MS_120
<VBFixedString(32),
System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.UnmanagedType.ByValArray,
SizeConst:=32)Public targetLine() As Char ' Default for this field is TL_ANY
<VBFixedString(32),
System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.UnmanagedType.ByValArray,
SizeConst:=32)Public copies() As Char ' Default for this field is 1
<VBFixedString(32),
System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.UnmanagedType.ByValArray,
SizeConst:=32)Public inOutInputBin() As Char ' Default for this field is
IOB_ANY
<VBFixedString(32),
System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.UnmanagedType.ByValArray,
SizeConst:=32)Public 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_listenForServersBstr Lib "clientapi.dll"
(ByVal serverActiveCallback As serverActiveCallbackDelegate, ByVal
serverShutdownCallback As serverShutdownCallbackDelegate) As Short
Public Declare Function RCA_listenForSystemStatusBstr Lib
"clientapi.dll" (ByVal systemStatusCallback As systemStatusCallbackDelegate,
ByVal clusterCreatedCallback As clusterCreatedCallbackDelegate, ByVal
clusterDeletedCallback As clusterDeletedCallbackDelegate, ByVal
systemExceptionCallback As systemExceptionCallbackDelegate) As Short
Public Declare Function RCA_submitProductionOrderBstr Lib
"clientapi.dll" (ByRef orderDesc As RCA_production_order_description, ByVal
xmlOrder As String, ByVal orderStatusCallback As orderStatusCallbackDelegate)
As Short
Public Declare Function RCA_cancelProductionOrder Lib "clientapi.dll"
(ByRef orderDesc As RCA_production_order_description, ByVal abortCurrent As
Boolean) As Short
Public Declare Function RCA_stopListeningForProductionOrder Lib
"clientapi.dll" (ByRef orderDesc As RCA_production_order_description) As Short
Delegate Function serverActiveCallbackDelegate(ByVal xmlServerActive As
String) As Integer
Public Function serverActiveCallback(ByVal xmlServerActive As String) As
Integer
Debug.Print("Active server is " & xmlServerActive)
End Function
Delegate Function serverShutdownCallbackDelegate(ByVal server As String)
As Integer
Public Function serverShutdownCallback(ByVal server As String) As Integer
Debug.Print("Shutdown server is " & server)
End Function
Delegate Function systemExceptionCallbackDelegate(ByVal wError As
String) As Integer
Public Function systemExceptionCallback(ByVal wError As String) As Integer
MsgBox("Error : " & wError)
End Function
Delegate Function systemStatusCallbackDelegate(ByVal systemStatus As
String) As Integer
Public Function systemStatusCallback(ByVal systemStatus As String) As
Integer
Debug.Print("System status is " & systemStatus)
End Function
Delegate Function clusterCreatedCallbackDelegate(ByVal cluster As
String) As Integer
Public Function clusterCreatedCallback(ByVal cluster As String) As Integer
Debug.Print("Created cluster is " & cluster)
End Function
Delegate Function clusterDeletedCallbackDelegate(ByVal cluster As
String) As Integer
Public Function clusterDeletedCallback(ByVal cluster As String) As Integer
Debug.Print("Deleted cluster is " & cluster)
End Function
Delegate Function orderStatusCallbackDelegate(ByVal orderStatus As
String) As Integer
Public Function orderStatusCallback(ByVal orderStatus As String) As
Integer
On Error Resume Next
Debug.Print(orderStatus)
orderStatusCallback = 0
End Function

Jun 27 '08 #1
1 1775

"Mike M" <Mike M@discussions.microsoft.comwrote in message
news:92**********************************@microsof t.com...
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

Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stub | last post by:
Docs says that "The compiler does not use an explicit constructor to implement an implied conversion of types. It's purpose is reserved explicitly for construction." I put up code of three cases...
7
by: Michael Lehn | last post by:
Hi, I have a question regarding the conversion of objects. When is the conversion done by the constructor and when by the operator. My feeling tells me that the constructor is preferred. But...
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
31
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
11
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type...
2
by: Alex Sedow | last post by:
Why explicit conversion from SomeType* to IntPtr is not ambiguous (according to standart)? Example: // System.IntPtr class IntPtr { public static explicit System.IntPtr (int); public...
3
by: Steve Richter | last post by:
here is a warning I am getting in a C++ .NET compile: c:\SrNet\jury\JuryTest.cpp(55) : warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied while...
0
by: Lou Evart | last post by:
DOCUMENT CONVERSION SERVICES Softline International (SII) operates one of the industry's largest document and data conversion service bureaus. In the past year, SII converted over a million...
0
by: dataentryoffshore | last post by:
Get a Discount up to 60% on data entry, data capture, dataentry services, large volume data processing and data conversion services through offshore facilities in India. Offshore data entry also...
21
by: REH | last post by:
It it permissible to use the constructor style cast with primitives such as "unsigned long"? One of my compilers accepts this syntax, the other does not. The failing one chokes on the fact that the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.