all groups > vb.net upgrade > august 2007 >
You're in the

vb.net upgrade

group:

need help upgrading a vb6 program to vb.net


need help upgrading a vb6 program to vb.net steve
8/26/2007 11:36:02 AM
vb.net upgrade: hi,

I bought me a symbol CS1504 scanner to use the scanner there is an sdk with
an C++ dll and an example code written in vb6 to bind the dll to the vb6 app.

I got my app running in vb6 but like to rebuild the thing so i can use it in
vb.net.
If I just open the app in visual studio 2005 I get an error and It just
shuts down.

Do i need to convert the C++ dll?
How do I get the DLL to work in vb.net?

The code from VB6:

'// Communications
Declare Function csp2Init Lib "csp2.dll" (ByVal nComPort As Long) As Long
Declare Function csp2Restore Lib "csp2.dll" () As Long
Declare Function csp2WakeUp Lib "csp2.dll" () As Long
Declare Function csp2DataAvailable Lib "csp2.dll" () As Long

'// Basic Functions
Declare Function csp2ReadData Lib "csp2.dll" () As Long
Declare Function csp2ClearData Lib "csp2.dll" () As Long
Declare Function csp2PowerDown Lib "csp2.dll" () As Long
Declare Function csp2GetTime Lib "csp2.dll" (aTimeBuf As Byte) As Long
Declare Function csp2SetTime Lib "csp2.dll" (aTimeBuf As Byte) As Long
Declare Function csp2SetDefaults Lib "csp2.dll" () As Long

'// CSP Data Get
Declare Function csp2GetPacket Lib "csp2.dll" (stPacketData As Byte, ByVal
lgBarcodeNumber As Long, ByVal maxLength As Long) As Long
Declare Function csp2GetDeviceId Lib "csp2.dll" (szDeviceId As Byte, ByVal
nMaxLength As Long) As Long
Declare Function csp2GetProtocol Lib "csp2.dll" () As Long
Declare Function csp2GetSystemStatus Lib "csp2.dll" () As Long
Declare Function csp2GetSwVersion Lib "csp2.dll" (ByVal szSwVersion As
String, ByVal nMaxLength As Long) As Long
Declare Function csp2GetASCIIMode Lib "csp2.dll" () As Long
Declare Function csp2GetRTCMode Lib "csp2.dll" () As Long

'// DLL Configuration
Declare Function csp2SetRetryCount Lib "csp2.dll" (ByVal nRetryCount As
Long) As Long
Declare Function csp2GetRetryCount Lib "csp2.dll" () As Long

'// Miscellaneous
Declare Function csp2GetDllVersion Lib "csp2.dll" (ByVal szDllVersion As
String, ByVal nMaxLength As Long) As Long
Declare Function csp2TimeStamp2Str Lib "csp2.dll" (Stamp As Byte, ByVal
value As String, ByVal nMaxLength As Long) As Long
Declare Function csp2GetCodeType Lib "csp2.dll" (ByVal CodeID As Long, ByVal
CodeType As String, ByVal nMaxLength As Long) As Long

'// Advanced functions
Declare Function csp2ReadRawData Lib "csp2.dll" (aBuffer As Byte, ByVal
nMaxLength As Long) As Long
Declare Function csp2SetParam Lib "csp2.dll" (ByVal nParam As Long, szString
As Byte, ByVal nMaxLength As Long) As Long
Declare Function csp2GetParam Lib "csp2.dll" (ByVal nParam As Long, szString
As Byte, ByVal nMaxLength As Long) As Long
Declare Function csp2Interrogate Lib "csp2.dll" () As Long
Declare Function csp2GetCTS Lib "csp2.dll" () As Long
Declare Function csp2SetDTR Lib "csp2.dll" (ByVal nOnOff As Long) As Long
Declare Function csp2SetDebugMode Lib "csp2.dll" (ByVal nOnOff As Long) As
Long

'// Returned status values...
Global Const STATUS_OK As Long = 0
Global Const COMMUNICATIONS_ERROR As Long = -1
Global Const BAD_PARAM As Long = -2
Global Const SETUP_ERROR As Long = -3
Global Const INVALID_COMMAND_NUMBER As Long = -4
Global Const COMMAND_LRC_ERROR As Long = -7
Global Const RECEIVED_CHARACTER_ERROR As Long = -8
Global Const GENERAL_ERROR As Long = -9
Global Const FILE_NOT_FOUND As Long = 2
Global Const ACCESS_DENIED As Long = 5

'// Parameter values...
Global Const PARAM_OFF As Long = 0
Global Const PARAM_ON As Long = 1

Global Const DATA_AVAILABLE As Long = 1
Global Const DATA_NOT_AVAILABLE As Long = 0

Global Const DETERMINE_SIZE As Long = 0


I have tride to load the dll with te code but I'm getting the error
BadImageFormatException Make sure the file image is a valid managed assembly
or module.:

Dim a As Reflection.Assembly
Dim lateBDLL As String
Dim obj As Object
Dim Params() As Object

lateBDLL = "Csp2.dll"
Debug.Print(lateBDLL)

a = Reflection.Assembly.LoadFrom(lateBDLL)



thanks
Re: need help upgrading a vb6 program to vb.net steve
8/26/2007 4:32:00 PM
thanks patrick,

The only thing thats strange is that I seem to get an differend output from
the dll if I use .net or vb6.
example if i run the opencom_click (it opens the com connection):
Private Sub OpenCom_Click()
Dim dwRC As Long
Dim dwComPort As Long
dwComPort = SelectCOMcb.ListIndex

'Open the com port
dwRC = csp2Init(dwComPort) ' this gives me a 0 in vb6 and
8975933078237085696 in vb.net


If dwRC <> STATUS_OK Then 'i need to get a 0 to get past this if
WriteToLog "Could Not Open COM" & CStr(dwComPort + 1)
Else

WriteToLog "COM" & CStr(dwComPort + 1) & " Opened"

'Disable the open button
OpenCom.Enabled = False
CloseCom.Enabled = True

'Disable COM Select
SelectCOMcb.Enabled = False
bComConnected = True

'Register the callback when the device is present.
'Status = csp2StartPolling(AddressOf CallBackDataAvailable)
End If

'Start the CTS State Timer
CTSStateTimer.Enabled = True

UpdateMainFormCtrls

End Sub

this is the function in the dll
in vb.net I've made a module where i put the functions in.
Declare Function csp2Init Lib "csp2.dll" (ByVal nComPort As Long) As Long


It seem like all the csp2.dll functions are given me other values in vb.net.

What am i doing wrong?

thanks

[quoted text, click to view]
Re: need help upgrading a vb6 program to vb.net Patrick Steele
8/26/2007 5:50:05 PM
In article <2EDEF0CA-6069-4A74-A08E-AF1E7D93BBA3@microsoft.com>,
steve@discussions.microsoft.com says...
[quoted text, click to view]

Assembly.LoadFrom is only for loading managed code (i.e. .NET framework
assembliues). Your "Declare" statements should be all you need to
utilize the DLL from .NET.

Have you tried loading the VB6 project using VS2005 and let the upgrade
wizard convert your code?

--
Patrick Steele (patrick@mvps.org)
Re: need help upgrading a vb6 program to vb.net Patrick Steele
8/26/2007 9:26:53 PM
In article <A0A41FD7-BDA9-499E-AF5A-3064A79BE000@microsoft.com>,
steve@discussions.microsoft.com says...
[quoted text, click to view]

Did you run this through the VB.NET upgrade wizard?

According to your original post (the VB6 code), the datatypes above are
Long (4-bytes in VB6). In VB.NET, a 4-byte datatype is an Integer. So
the comparable translation of the above Declare in VB.NET would be:

Declare Function csp2Init _
Lib "csp2.dll" (ByVal nComPort As Integer) As Integer

I would have thought the conversion wizard and switched those for you.

--
Patrick Steele (patrick@mvps.org)
Re: need help upgrading a vb6 program to vb.net steve
8/27/2007 6:44:02 AM
hi,

thanks, changed the longs to integer and some byval to byref and it works now.
I try to use te update wizard but the thing keeps bugging me with an error.
I try it with a new vb6 app and same result.

Since the app is no more than 3 forms I rebuild the app from scratch.




[quoted text, click to view]
AddThis Social Bookmark Button