PC Review


Reply
Thread Tools Rate Thread

Declare function problem

 
 
Altman
Guest
Posts: n/a
 
      19th Oct 2004
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.


 
Reply With Quote
 
 
 
 
Mattias Sjögren
Guest
Posts: n/a
 
      19th Oct 2004

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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
Tom Shelton
Guest
Posts: n/a
 
      19th Oct 2004
In article <#(E-Mail Removed)>, Altman wrote:
> 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.

--
Tom Shelton [MVP]
 
Reply With Quote
 
Altman
Guest
Posts: n/a
 
      20th Oct 2004
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


"Tom Shelton" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In article <#(E-Mail Removed)>, Altman wrote:
>> 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.
>
> --
> Tom Shelton [MVP]



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DECLARE FUNCTION - DLL zzzxtreme@gmail.com Microsoft ASP .NET 2 4th Jan 2008 05:41 PM
Private Declare Function =?Utf-8?B?RGF2aWQgQS4=?= Microsoft Excel Programming 6 31st Jul 2007 06:38 PM
Lib parameter in Function Declare =?Utf-8?B?b2p2?= Microsoft Excel Programming 4 12th Jun 2007 07:40 AM
Declare and array in a function =?Utf-8?B?RGF2ZQ==?= Microsoft Excel Programming 3 30th Sep 2006 03:41 AM
Declare new function? Duane Hookom Microsoft Access Getting Started 4 30th Nov 2004 06:13 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:33 PM.