 |
| Visual Studio 2005 For discussing Visual Studio 2005. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Visual Studio 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

April 30th, 2009, 01:24 PM
|
|
Authorized User
|
|
Join Date: Sep 2007
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Error : Value does not fall within the expected range VB.Net 2005
i'm using VB.Net 2005 application program.
i'm trying to convert VB6 code to VB.Net 2005. QSockB is DLL file.
this is the code i used for VB6. This is code i'm using to create socket, when program runs... and when i hit start button it calls Q_SendHeader function.
Code:
Form1_Load(.....................
Q_KDSPort = &H8000&
Q_MyPort = Q_KDSPort + &H100&
Q_Address = ADDRESS_ANY
Q_CreateSocketPort
Code:
Module QSockB
Declare Function QSOCKNETINIT Lib "QSockB" () As Long
Declare Function QSOCKOPENSOCKETEX Lib "QSockB" _
(ByRef hndSocket As Long, ByVal lngPort As Long, _
ByVal szIPAddress As String) As Long
Declare Function QSOCKSENDMESSAGEEX Lib "QSockB" (ByVal hndSocket As Long, ByVal lngPort As Long, ByVal szIPAddress As String, ByRef szData As Any, ByVal lngDataLength As Long) As Long
Public Const ADDRESS_ANY As String = "AnyAddress"
Structure KDS_HEADER
Dim lngFunction As Long
Dim lngSubFunction As Long
End Structure
Structure KDS_TRANSACTION_HEADER
Dim lngTransactionNumber As Long
Dim lngTerminalNumber As Long
Dim lngDestination As Long
Dim lngSystemTime As SystemTime
Dim lngTableNumber As Long
Dim lngServerId As Long
Dim lngCourse As Long
Dim lngReserved1 As Long
Dim lngReserved2 As Long
Dim lngReserved3 As Long
Dim lngReserved4 As Long
Dim lngReserved5 As Long
Dim lngReserved6 As Long
Dim lngReserved7 As Long
Dim lngReserved8 As Long
<VBFixedString(31)> Dim lpszServerName As String
<VBFixedString(31)> Dim lpszCustomerName As String
Dim lngFlags As Long
End Structure
Structure HEADER_MSG
Dim Hdr As KDS_HEADER
Dim Data As KDS_TRANSACTION_HEADER
End Structure
Public Function Q_CreateSocketPort()
Dim ReturnCode As Long
Q_CreateSocketPort = False
ReturnCode = QSOCKNETINIT
If ReturnCode = SOCK_ERROR_NONE Then
ReturnCode = QSOCKOPENSOCKETEX(Q_Socket, Q_MyPort, Q_Address)
If ReturnCode = SOCK_ERROR_NONE Then
Q_Connected = True
Q_CreateSocketPort = True
End If
End If
End Function
Public Function Q_SendHeader(ByVal TransactionNumber, ByVal Terminal, ByVal VideoChannel, ByVal UniqueTableID, ByVal ServerID, ByVal Course As Long, ByVal ServerName, ByVal HoldName As String, ByVal TimeHeld As Date) As Long
Dim Header As HEADER_MSG
With Header.Hdr
.lngFunction = RDS_FUNCTION_POS_VB
.lngSubFunction = RDS_MESSAGE_HEADER
End With
With Header.Data
.lngTransactionNumber = TransactionNumber
.lngTerminalNumber = Terminal 'must be non-zero
.lngDestination = VideoChannel 'as defined in the KDS (Destination ID's)
.lngTableNumber = UniqueTableID
.lngServerId = ServerID
.lngCourse = Course
.lngReserved1 = 0
.lngReserved2 = 0
.lngReserved3 = 0
.lngReserved4 = 0
.lngReserved5 = 0
.lngReserved6 = 0
.lngReserved7 = 0
.lngReserved8 = 0
' We must Add a Chr(0) to the end of each string to NULL terminate
If Len(Trim(ServerName)) > 0 Then
.lpszServerName = Trim(ServerName) + Chr(0)
Else
.lpszServerName = Chr(0)
End If
If Len(Trim(HoldName)) > 0 Then
.lpszCustomerName = Left(Trim(HoldName), 30) + Chr(0)
Else
.lpszCustomerName = Chr(0)
End If
End With
Q_SendHeader = QSOCKSENDMESSAGEEX(Q_Socket, Q_KDSPort, Q_Address, Header, Len(Header))
End Function
End Module
this is the code i'm using for VB.Net 2005.
This is code i'm using to create socket, when program runs... and when i hit button start, its calling Q_SendHeader function.
Code:
Public objQ As clsQSockB
Private Sub Form1_Load(â¦â¦â¦â¦â¦â¦â¦â¦â¦â¦â¦â¦â¦â¦
objQ = New clsQSockB
objQ.Q_KDSPort = &H8000&
objQ.Q_MyPort = objQ.Q_KDSPort + &H100&
objQ.Q_Address = clsQSockB.ADDRESS_ANY
objQ.Q_CreateSocketPort()
End Sub
Private Sub btnStart_Click(â¦â¦â¦â¦â¦â¦â¦â¦â¦â¦â¦â¦
objQ.Q_SendHeader(100, 33, 1, 100, 3, 1, "Server", 100, Now.Date)
End Sub
Code:
Public Class clsQSockB
Declare Function QSOCKNETINIT Lib "QSockB" () As Int32
Declare Function QSOCKOPENSOCKETEX Lib "QSockB" _
(ByRef hndSocket As Int32, ByVal lngPort As Int32, _
ByVal szIPAddress As String) As Int32
Declare Function QSOCKSENDMESSAGEEX Lib "QSockB" (ByVal hndSocket As Int32, ByVal lngPort As Int32, ByVal szIPAddress As String, ByVal szData As Object, ByVal lngDataLength As Int32) As Int32
Public Q_Socket As Int32
Public Q_MyPort As Int32
Public Q_KDSPort As Int32
Public Q_Address As String
Public Const ADDRESS_ANY As String = "AnyAddress"
Structure KDS_HEADER
Dim lngFunction As Int32
Dim lngSubFunction As Int32
End Structure
Structure KDS_TRANSACTION_HEADER
Dim lngTransactionNumber As Int32
Dim lngTerminalNumber As Int32
Dim lngDestination As Int32
Dim lngSystemTime As SystemTime
Dim lngTableNumber As Int32
Dim lngServerId As Int32
Dim lngCourse As Int32
Dim lngReserved1 As Int32
Dim lngReserved2 As Int32
Dim lngReserved3 As Int32
Dim lngReserved4 As Int32
Dim lngReserved5 As Int32
Dim lngReserved6 As Int32
Dim lngReserved7 As Int32
Dim lngReserved8 As Int32
<VBFixedString(31)> Dim lpszServerName As String
<VBFixedString(31)> Dim lpszCustomerName As String
Dim lngFlags As Int32
End Structure
Structure HEADER_MSG
Dim Hdr As KDS_HEADER
Dim Data As KDS_TRANSACTION_HEADER
End Structure
Public Function Q_CreateSocketPort() As Boolean
Try
Dim ReturnCode As Long
'Attempt to initial QSockB.DLL
ReturnCode = QSOCKNETINIT()
If ReturnCode = SOCK_ERROR_NONE Then
ReturnCode = QSOCKOPENSOCKETEX(Q_Socket, Q_MyPort, Q_Address)
If ReturnCode = SOCK_ERROR_NONE Then
Q_Connected = True
Return True
End If
End If
Catch ex As Exception
Return False
End Try
End Function
Public Function Q_SendHeader(ByVal TransactionNumber As Object, ByVal Terminal As Object, ByVal VideoChannel As Object, ByVal UniqueTableID As Object, ByVal ServerID As Object, ByVal Course As Int32, ByVal ServerName As Object, ByVal HoldName As String, ByVal TimeHeld As Date) As Int32
Try
Dim Header As HEADER_MSG
With Header.Hdr
.lngFunction = RDS_FUNCTION_POS_VB
.lngSubFunction = RDS_MESSAGE_HEADER
End With
With Header.Data
.lngTransactionNumber = TransactionNumber
.lngTerminalNumber = Terminal 'must be non-zero
.lngDestination = VideoChannel 'as defined in the KDS (Destination ID's)
.lngTableNumber = UniqueTableID
.lngServerId = ServerID
.lngCourse = Course
.lngReserved1 = 0
.lngReserved2 = 0
.lngReserved3 = 0
.lngReserved4 = 0
.lngReserved5 = 0
.lngReserved6 = 0
.lngReserved7 = 0
.lngReserved8 = 0
' We must Add a Chr(0) to the end of each string to NULL terminate
If Len(Trim(ServerName)) > 0 Then
.lpszServerName = Trim(ServerName) + Chr(0)
Else
.lpszServerName = Chr(0)
End If
If Len(Trim(HoldName)) > 0 Then
.lpszCustomerName = Left(Trim(HoldName), 30) + Chr(0)
Else
.lpszCustomerName = Chr(0)
End If
End With
Return QSOCKSENDMESSAGEEX(Q_Socket, Q_KDSPort, Q_Address, Header, Len(Header))
Catch ex As Exception
Return -1
End Try
End Function
End Class
Creating Socket works fine. but when i call Q_SendHeader, getting error.
Error i'm getting is
Quote:
|
Value does not fall within the expected range.
|
when it reach this line in Q_SendHeader, its getting error...
Quote:
|
Return QSOCKSENDMESSAGEEX(Q_Socket, Q_KDSPort, Q_Address, Header, Len(Header))
|
This works fine in VB6... but Q_SendHeader is not working in VB.Net 2005.
anything wrong with the code... if you have any idea what's wrong with the code, please help me... please.....
Thanks in advance.
|
|

April 30th, 2009, 01:47 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
Since you are adding a library, can you just add a reference in vb.net to that dll?? .net will probably need a helper dll to connect with it. (and will build it for you).
__________________
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the proof.
================================================== =========
|
|

April 30th, 2009, 02:13 PM
|
|
Authorized User
|
|
Join Date: Sep 2007
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks gbianchi for your reply.
i tried to add a reference in vb.net to that dll... i'm not able to add that dll. the error i'm getting is this.
Quote:
|
A reference to 'C:\Windows\system32\QSockB.dll" could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.
|
if you have any idea what's wrong with the code, please help me... please.....
Thanks in advance.
|
|

April 30th, 2009, 02:34 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
Well, this could be a problem in how .net manage data structure and how that dll manage them. There was a change between vb6 and .net about this. That's why when you need an old dll .net build a wrapper around it.
I don't think I can help you more than this at this point.
__________________
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the proof.
================================================== =========
|
|

April 30th, 2009, 02:56 PM
|
|
Authorized User
|
|
Join Date: Sep 2007
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
but in form load, i'm calling this Q_CreateSocketPort function in DLL. and it's working. i'm getting Q_Socket value and i'm getting socket connection.
Code:
Public Function Q_CreateSocketPort() As Boolean
Try
Dim ReturnCode As Long
'Attempt to initial QSockB.DLL
ReturnCode = QSOCKNETINIT()
If ReturnCode = SOCK_ERROR_NONE Then
ReturnCode = QSOCKOPENSOCKETEX(Q_Socket, Q_MyPort, Q_Address)
If ReturnCode = SOCK_ERROR_NONE Then
Q_Connected = True
Return True
End If
End If
Catch ex As Exception
Return False
End Try
End Function
but Q_SendHeader function is showing this error.
if you have any idea what's wrong with the code, please help me... please.....
Thanks in advance.
|
|
 |