473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Declare function problem

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.
Nov 21 '05 #1
3 4916

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.
Nov 21 '05 #2
In article <#R**************@TK2MSFTNGP10.phx.gbl>, 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]
Nov 21 '05 #3
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" <to*@YOUKNOWTHEDRILLmtogden.com> wrote in message
news:uj**************@TK2MSFTNGP12.phx.gbl...
In article <#R**************@TK2MSFTNGP10.phx.gbl>, 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]

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tomaz Rotovnik | last post by:
Hi I created very simple dll (vc++) which has three functions (start, stop and initialization). it starts capturing sound from soundblaster and when the buffer is filled with the data, dll calls...
5
by: Ian Davies | last post by:
Dear Access expert I am trying to use an mde application developed in Access2k with Access 2002. I get an Access error box: Function is not available.. Date() etc. Is Access 2002 back...
2
by: Lance Geeck | last post by:
I have many items that I lifted off from Microsoft's website several years ago. These samples were in VB6. I now want to convert an application to VB.NET. I am getting an error that says "As Any...
0
by: Benjamin Lukner | last post by:
Hi! I'd like to dynamically call API functions from different DLLs, depending on what platform the program runs. Now I'm wondering what the most simple way may be (without meta code and compiler...
4
by: Sakharam Phapale | last post by:
Hi All, I have written following code, but waveInOpen API call gives me error no 32. Can anyone help me to solve this? Public Delegate Function callback(ByVal hw As Integer, ByVal uMsg As...
2
by: Tany | last post by:
How can I declare function returning array of Integer pointers . Please help !!
2
by: syang8 | last post by:
Dear all, I am trying to design classes with stream support. Basically, I want the operator << work for the base class and all the derived classes. If the base class is a template class, and...
4
by: marss | last post by:
How to declare function that accepts any generic list as input parameter? I mean I need void foo(List<list) { } where: Valid parameters are List<SomeInfo>, List<string>, List<Guid>, e.t.c....
2
by: zzzxtreme | last post by:
hi i built a very simple dll with delphi library Printing; uses SysUtils, Classes, Dialogs; {$R *.res} function Hello: WideString; stdcall; begin ShowMessage('test'); result := 'blah';
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.