Declare function problem

  • Thread starter Thread starter Altman
  • Start date Start date
A

Altman

I am having problems with Declaring a function from a dll. I had it work in
VB 6 but I can't get it to work in VB.net. This was the call in VB6
Public Declare Function MBTConnect Lib "MBT" (ByVal szHostAddress As String,
ByVal port As Integer, ByVal useTCPorUDP As Long, ByVal requestTimeout As
Long, hSocket As Long) As Long

When I try this in VB.net I get the following Error:
"Object Reference not set to an instance of an object"

What I think is the problem is that hSocket is the connection handle if it
gets connected. This variable is then used in other calls. I think hSocket
is supposed to be set by the dll. I have tried both ByVal and ByRef on this
but neither seams to work.
 
Try it like this

Declare Function MBTConnect Lib "MBT" (ByVal szHostAddress As String,
ByVal port As Short, ByVal useTCPorUDP As Integer, ByVal
requestTimeout As Integer, ByRef hSocket As IntPtr) As Integer



Mattias
 
I am having problems with Declaring a function from a dll. I had it work in
VB 6 but I can't get it to work in VB.net. This was the call in VB6
Public Declare Function MBTConnect Lib "MBT" (ByVal szHostAddress As String,
ByVal port As Integer, ByVal useTCPorUDP As Long, ByVal requestTimeout As
Long, hSocket As Long) As Long

Public Declare Function MBTConnect Lib "MBT" _
(ByVal szHostAddress As String, _
ByVal port As Short, _
ByVal useTCPorUDP As Boolean, _
ByVal requestTimeout As Integer, _
ByRef hSocket As Integer) As Integer


Data type sizes have changed in VB.NET.
 
That worked great. I am now having problem with 2 other functions though.
I tried changing integer to short but I am still having the same problem.
These were the functions in VB6. I also changed any to object.

Public Declare Function MBTReadRegisters Lib "MBT" (ByVal hSocket As Long,
ByVal tableType As Byte, ByVal dataStartAddress As Integer, ByVal numWords
As Integer, pReadBuffer As Any, ByVal fpReadCompletedCallback As Long, ByVal
callbackContext As Long) As Long


Public Declare Function MBTWriteRegisters Lib "MBT" (ByVal hSocket As Long,
ByVal dataStartAddress As Integer, ByVal numWords As Integer, pWriteBuffer
As Any, ByVal fpWriteCompletedCallback As Long, ByVal callbackContext As
Long) As Long
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top