473,587 Members | 2,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

NullReferenceEx ception with unmanaged DLL

Hi everyone,
I'm a newbie .NET developer with vb6 experience. I was toying myself with
the Howl open source library for Zeroconf networks and I stumbled across an
exception I can't quite figure out completely.
The library is a .dll and i'm using PInvoke (<DllImport>) to declare the
functions in the library; I've only declared the following so far:

<DllImport("ren dezvous.dll")> Public Function sw_rendezvous_i nit(ByRef
session As IntPtr) As Integer

End Function

<DllImport("ren dezvous.dll")> Public Function sw_rendezvous_f ina(ByVal
session As IntPtr) As Integer

End Function

'sw_result
'sw_rendezvous_ browse_services (
' sw_rendezvous session,
' sw_const_string type,
' sw_const_string domain,
' sw_rendezvous_b rowse_handler handler,
' sw_rendezvous_b rowse_reply reply,
' sw_opaque extra,
' sw_rendezvous_b rowse_id *id)
<DllImport("ren dezvous.dll")> _
Public Function sw_rendezvous_b rowse_services( ByVal session As
IntPtr, _
ByVal type As String, _
ByVal domain As String, _
ByRef handler As IntPtr, _
ByVal reply As sw_rendezvous_b rowse_reply, _
ByRef extra As IntPtr, _
ByRef id As IntPtr) As Integer

End Function

'typedef sw_result
'(*sw_rendezvou s_browse_reply) (
' sw_rendezvous_b rowse_handler handler,
' sw_rendezvous rendezvous,
' sw_rendezvous_b rowse_id id,
' sw_rendezvous_b rowse_status status,
' sw_const_string name,
' sw_const_string type,
' sw_const_string domain,
' sw_opaque extra);
Public Delegate _
Function sw_rendezvous_b rowse_reply( _
ByVal handler As IntPtr, _
ByVal rendezvous As IntPtr, _
ByVal id As Integer, _
ByVal status As Integer, _
ByVal type As String, _
ByVal domain As String, _
ByVal extra As IntPtr) As Integer

I did some research in Howl's headers and found out that most of the custom
types are simply either pointers (sw_opaque is void*, sw_const_string is
char*) or simple handles (such as sw_rendezvous or
sw_rendezvous_b rowse_id). Now, I tried putting this code in a form to see
what happens:

Imports Howl

Public Class Form1
Inherits System.Windows. Forms.Form
[cut on wf designer's code, there are no controls on the form]
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim rv As IntPtr, id As IntPtr, Repl As sw_rendezvous_b rowse_reply
= AddressOf Something.myRep ly
If (Howl.sw_rendez vous_init(rv) = 0) Then
MsgBox(Howl.sw_ rendezvous_brow se_services(rv, _
"_http._tcp .", Nothing, _
Nothing, Repl, Nothing, id))
End If
End Sub
End Class

Module Something
Public Function myReply( _
ByVal handler As IntPtr, _
ByVal rendezvous As IntPtr, _
ByVal id As Integer, _
ByVal status As Integer, _
ByVal name As String, _
ByVal domain As String, _
ByVal extra As IntPtr) As Integer
Stop
Return 0
End Function
End Module

Now, I have a Mac connected to my LAN which allows me to produce
Zeroconf/Rendezvous services for testing. The good part of this snippet is
that the init works and gives an IntPtr back; also, the call to
sw_rendezvous_b rowse_services apparently works because it returns 0
(SW_OKAY) which is always correctly displayed by the MsgBox, and because
myReply gets called (VB stops at the "Stop"); i can even inspect the
contents of myReply's args and they contain the proper data in IntPtr,
Integer or String form ? the service name, the domain, everything.

The problem is that, immediatly after returning from myReply, the whole
thing goes down crashing and burning reporting a NullReferenceEx ception on
the "End If" line of Form1_Load!

I tried googling for a solution but I couldn't find any. What's wrong?

- e "theta" v
Nov 20 '05 #1
0 1008

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

Similar topics

0
2254
by: Yoni Rabinovitch | last post by:
Hi, I am new to C#, so I apologise if this is a stupid question. I have some 3rd party C++ code, which gets built as static libraries (not DLLs). I want to create a C# form, which will call the C++ code. So, I understand that I need to create a Managed C++ Wrapper, for any
0
2670
by: monkey king | last post by:
I have a given dll file(PDFCreator.dll) - probably generated by VC++. I want to use its method(PDFCreator()) in dotNet environment. It works well in WindiowsApplication, but bad in WebApplication ,the line that calls the function results in the "Object reference not set to an instance of an object" error. The following is the VB.NET code I...
4
1903
by: James | last post by:
Greetings, I have a PowerBasic unmanaged library that I wish to call from C#. Here's the PB code... FUNCTION Hello(str AS STRING) EXPORT AS STRING FUNCTION = "Hello World " & str END FUNCTION Simple enough. I can successfully call it from a VB6 component but
0
2125
by: noe | last post by:
I have done a DLL in unmanaged code C++ and in that dll I have defined a function that use memcpy.This dll run ok.I use that dll in a aplication in C# managed code in Visual Studio .NET. I import the functions defined in the dll using DllImport and I have verified that when in my dll I use memcpy then I have one error...
1
1259
by: Klynt | last post by:
Project built using /CLR, but code is old and has not been converted specifically to "managed" (__gc or __value). Everything seemed to work great, until I got the following error. I have a class, let's call it CMyLegacyClass, that has some CString (NOT CString*) member variables. Problem is, when the destructor is called (which actually...
2
1029
by: ishekara | last post by:
Hi, Strange, I am having a .Net C++ managed dll project, where in i call a new on a non managed code. This however is giving a problem, I get an exception saying "An unhandled exception of type 'System.NullReferenceException' occured in Mydll.dll" "Additional information: Object reference not set to an instance of an object", class mycpp...
3
1429
by: andrew.bell.ia | last post by:
Hi, I'm trying to put together some managed and unmanaged code. Everything works fine until the program exits, and I suppose the garbage collector runs to finalize things. Then I get: Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. at std.list<int,std::allocator<int>
1
2020
by: razilon | last post by:
Hi, I've written a managed class that makes use of stl vectors of a few unmanaged structs for data handling/manipulation, but I'm getting a few very strange errors. I get an "Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object" occasionally when adding a new element to a vector. By
0
1331
by: razilon | last post by:
Hi, I've written a managed class that makes use of stl vectors of a few unmanaged structs for data handling/manipulation, but I'm getting a few very strange errors. I get an "Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object" occasionally when adding a new element to a vector. By
1
1250
by: Bruce | last post by:
I am using VC .NET 2003. I created a simple unmanaged class in C++. The class is contained in a library. I then created a simple managed class wrapper that calls a function in the unmanaged class. I am getting a System.NullReferenceException when instantiating the unmanaged class. What is causing this error? Unmanaged code:
0
7920
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7849
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8347
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6626
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.