473,769 Members | 3,305 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("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

Jun 27 '08 #1
1 1790

"Mike M" <Mike M@discussions.m icrosoft.comwrote in message
news:92******** *************** ***********@mic rosoft.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("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.
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_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
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.Seq uential, CharSet:=CharSe t.Ansi) _
Public Structure RCA_production_ order_descripti on
<MarshalAs(Unma nagedType.ByVal TStr, SizeConst:=128) _
Public orderId As String ' This field cannot be NULL

<MarshalAs(Unma nagedType.ByVal TStr, 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
5655
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 at the bottom. Hope you can help me understand the "explicit" keyword and its usage. Specifically, Is "explicit" keyword only associated with constructor in C++? What's "implied conversion of types"?
7
3260
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 I couldn't find the exact rule in the C++ standard. And what if the classes have template parameters? It would be great if somebody could get me a rough hint where in the
16
5138
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. And K&R2 mentions "signed extension" everywhere. Reading some old clc posts, I've beginning to realize that these books are over-generalizing the topic. I am just wondering what the difference between the following pairs of terms are: 1)...
31
6649
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 variable becomes 364 and the other one becomes 365. Does anyone have any insight to what the problem is? Thanks in advance. Bjørn
11
7622
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 Test. I expected the same error from the following line, but it compiles fine. The double is silently truncated to an int and then fed in to the implicit conversion operator. Why does this happen? Is there any way that I can keep the implicit...
2
6870
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 static explicit System.IntPtr (long);
3
4458
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 calling the constructor 'MyString::MyString(const wchar_t *)' c:\SrNet\jury\JuryTest.h(21) : see declaration of 'MyString::MyString' The class "StringData" uses a, whatever you call it, operator const
0
2292
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 pages to a variety of formats. SII's service bureau has a reputation as being a least-cost provider that can offer a timely turnaround with 100% accuracy. Here are some of the formats SII has converted over the last 20 years:
0
1867
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 provides form data entry, data capture, HTML/SGML coding, image scanning, file conversion with low cost, high quality,99.98% accuracy and time bound. Data Conversion Services offer cost effective data conversion projects, Outsourcing Data...
21
2462
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 type is not a single identifier or keyword. Which one is correct? For example: unsigned long x = unsigned long(y); REH
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10216
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.