473,396 Members | 2,098 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,396 software developers and data experts.

Implementing a Callback function (_cdecl) in VB.NET

--------------------------------------------------------------------------------

I need to do the exactly same thing in VB.NET.

Load a unmanaged C DLL dynamically and then call a function in which I pass the callback function as an argument. My C function being called callback as type _cdecl. Does anybody have any ideas?

Here is what I am trying to do:

-----------Native Code snippet----------------
typedef ErrorCode (__cdecl * CALLBACK_HANDLER)(
const int messageType, const char * message) ;

//This is the native function to be invoked
ErrorCode register(CALLBACK_HANDLER messageHandler, const char * parameters);
----------------------------------------------

-------------VB.NET code snippet-------------

......
Module CallbackHandler
Public Delegate Function Callback(ByVal messageType As Long, ByVal message As String) As Long
Public Declare Function register Lib "api.dll" (ByVal trafficType As Integer, ByVal listener As Callback) As Long
End Module
.....

......
Public Function myCallback(ByVal messageType As Long, ByVal message As String) As Long
Try
MsgBox(messageType)
MsgBox(message)
Catch ex As Exception
'MsgBox(ex)
Finally
End Try
End Function
.....
.....
Dim cb As CallbackHandler.myCallback
cb = AddressOf myCallback
CallBackHandler.register(2, cb)
......
----------------------------------------------

However I keep getting the error NullReferenceException which I guess is because my native declaration is _cdecl while I'm trying to make a _stdcall.

Any help would be greatly appreciated.

Peace!
Sep 7 '05 #1
0 8546

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: ThinkRS232 | last post by:
I have a Win32 DLL that has a standard _stdcall (WINAPI) exports. I am able to call these fine from C#. One call in particular however has a callback to a CDECL function. How would I set that up?...
5
by: Mark | last post by:
I'm trying to write a callback function, I've done it before, but this time I seem to be having problems... I define the following... typedef int (* ENUMINTERFACE)(char* szIP); void...
7
by: Frank Neuhaus | last post by:
Hi Iam trying to make a class where you can register callbacks to member functions of other classes. I declared the functions I wish to use like this: void SetMouseProc(ONMOUSEPROC proc, void*...
7
by: Amit Sharma | last post by:
Hi, I wanted to know when we call function with argument, Does the arguments stored in stack always or it compiler specific and could be stored in queue e.g. Does this program's output depends...
1
by: Roman Panas | last post by:
Hello! How to call function try_to_test() ? Anybody can to show the psevdo code? I tried next code but is doesn't work: try_to_test( func_test ); Thanks. typedef void( _cdecl *P_FUNC_TEST )(...
8
by: kurtcobain1978 | last post by:
-------------------------------------------------------------------------------- I need to do the exactly same thing in VB.NET. Load a unmanaged C DLL dynamically and then call a function in...
2
by: Jon E. Scott | last post by:
I've got a project where I need to create a C# project and a Delphi DLL, in which the DLL has a callback function to send statuses back to the C# application. It seems pretty straightforward in a...
6
by: smmk25 | last post by:
Before I state the problem, I just want to let the readers know, I am knew to C++\CLI and interop so please forgive any newbie questions. I have a huge C library which I want to be able to use in...
5
by: romcab | last post by:
Hi guys, I know function pointers but I'm having a hard time about callback function when it is associated with abstract class. I have an example code below which I got from a book. Kindly...
4
by: =?Utf-8?B?TGVvbg==?= | last post by:
Hi, I have a C exported function in a DLL that has the following proto-type: int _cdecl MyFunction( LPCSTR fmt, ... ); Does anyone know the DllImport declaration for this so that I can call...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.