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

Porting A Callback Function

Hello,

I am trying to change a DDEML callback function I have used in VB6
successfully for years now to vb.net. However, I can't seem to get my
mind around how to setup a delegate and pointers to get the
DDEInitialize to start the callback. I was hoping a more
seasoned .net programmer might be able to help translate the following
snippet of code from VB6 to VB.net.

API Declare Below:
Public Declare Function DdeInitialize Lib "user32" Alias
"DdeInitializeA" (pidInst As Long, ByVal pfnCallback As Long, ByVal
afCmd As Long, ByVal ulRes As Long) As Integer

Private Sub Start_DDECallback()

DDEML_CallBack_Handle = DdeInitialize(g_lInstID, AddressOf
DDECallback, APPCLASS_STANDARD Or APPCMD_CLIENTONLY Or MF_SENDMSGS Or
MF_POSTMSGS Or MF_CONV Or MF_ERRORS, 0)

End Sub

Public Function DDECallback(ByVal uType As Long, ByVal uFmt As Long,
ByVal hConv As Long, ByVal hszString1 As Long, ByVal hszString2 As
Long, ByVal hData As Long, ByVal dwData1 As Long, ByVal dwData2 As
Long) As Long

********CODE HERE TO HANDLE DDE STUFF

END FUNCTION
Any help would be greatly appreciated!

Thanks

Ryan
Jun 27 '08 #1
2 1873
On Jun 13, 4:21*pm, RFlem...@nationalsteel.com wrote:
Hello,

I am trying to change a DDEML callback function I have used in VB6
successfully for years now to vb.net. *However, I can't seem to get my
mind around how to setup a delegate and pointers to get the
DDEInitialize to start the callback. *I was hoping a more
seasoned .net programmer might be able to help translate the following
snippet of code from VB6 to VB.net.

API Declare Below:
Public Declare Function DdeInitialize Lib "user32" Alias
"DdeInitializeA" (pidInst As Long, ByVal pfnCallback As Long, ByVal
afCmd As Long, ByVal ulRes As Long) As Integer

Private Sub Start_DDECallback()

* * * *DDEML_CallBack_Handle = DdeInitialize(g_lInstID, AddressOf
DDECallback, APPCLASS_STANDARD Or APPCMD_CLIENTONLY Or MF_SENDMSGS Or
MF_POSTMSGS Or MF_CONV Or MF_ERRORS, 0)

End Sub

Public Function DDECallback(ByVal uType As Long, ByVal uFmt As Long,
ByVal hConv As Long, ByVal hszString1 As Long, ByVal hszString2 As
Long, ByVal hData As Long, ByVal dwData1 As Long, ByVal dwData2 As
Long) As Long

* * *********CODE HERE TO HANDLE DDE STUFF

END FUNCTION

Any help would be greatly appreciated!

Thanks

Ryan
Ryan,
Just to test, could you change your "Long" data types into "Integer"
in your API decleration for using in VB.NET and see if it helps.

Thanks,

Onur Güzel
Jun 27 '08 #2

"kimiraikkonen" <ki*************@gmail.comwrote in message
news:4f**********************************@79g2000h sk.googlegroups.com...
On Jun 13, 4:21 pm, RFlem...@nationalsteel.com wrote:
Hello,

I am trying to change a DDEML callback function I have used in VB6
successfully for years now to vb.net. However, I can't seem to get my
mind around how to setup a delegate and pointers to get the
DDEInitialize to start the callback. I was hoping a more
seasoned .net programmer might be able to help translate the following
snippet of code from VB6 to VB.net.

API Declare Below:
Public Declare Function DdeInitialize Lib "user32" Alias
"DdeInitializeA" (pidInst As Long, ByVal pfnCallback As Long, ByVal
afCmd As Long, ByVal ulRes As Long) As Integer

Private Sub Start_DDECallback()

DDEML_CallBack_Handle = DdeInitialize(g_lInstID, AddressOf
DDECallback, APPCLASS_STANDARD Or APPCMD_CLIENTONLY Or MF_SENDMSGS Or
MF_POSTMSGS Or MF_CONV Or MF_ERRORS, 0)

End Sub

Public Function DDECallback(ByVal uType As Long, ByVal uFmt As Long,
ByVal hConv As Long, ByVal hszString1 As Long, ByVal hszString2 As
Long, ByVal hData As Long, ByVal dwData1 As Long, ByVal dwData2 As
Long) As Long

********CODE HERE TO HANDLE DDE STUFF

END FUNCTION

Any help would be greatly appreciated!

Thanks

Ryan
Ryan,
Just to test, could you change your "Long" data types into "Integer"
in your API decleration for using in VB.NET and see if it helps.

Thanks,

Onur Güzel
Using the following:

HDDEDATA CALLBACK DdeCallback( UINT uType,
UINT uFmt,
HCONV hconv,
HSZ hsz1,
HSZ hsz2,
HDDEDATA hdata,
ULONG_PTR dwData1,
ULONG_PTR dwData2
);

and the MS provided P/Invoke Interop Assistant I get the following
generated:
<System.Runtime.InteropServices.StructLayoutAttrib ute(System.Runtime.InteropServices.LayoutKind.Sequ ential)>
_
Public Structure HDDEDATA__

'''int
Public unused As Integer
End Structure

<System.Runtime.InteropServices.StructLayoutAttrib ute(System.Runtime.InteropServices.LayoutKind.Sequ ential)>
_
Public Structure HCONV__

'''int
Public unused As Integer
End Structure

<System.Runtime.InteropServices.StructLayoutAttrib ute(System.Runtime.InteropServices.LayoutKind.Sequ ential)>
_
Public Structure HSZ__

'''int
Public unused As Integer
End Structure

Partial Public Class NativeMethods

'''Return Type: HDDEDATA->HDDEDATA__*
'''uType: UINT->unsigned int
'''uFmt: UINT->unsigned int
'''hconv: HCONV->HCONV__*
'''hsz1: HSZ->HSZ__*
'''hsz2: HSZ->HSZ__*
'''hdata: HDDEDATA->HDDEDATA__*
'''dwData1: ULONG_PTR->unsigned int
'''dwData2: ULONG_PTR->unsigned int
<System.Runtime.InteropServices.DllImportAttribute ("<Unknown>",
EntryPoint:="DdeCallback",
CallingConvention:=System.Runtime.InteropServices. CallingConvention.StdCall)>
_
Public Shared Function DdeCallback(ByVal uType As UInteger, ByVal uFmt
As UInteger, ByVal hconv As System.IntPtr, ByVal hsz1 As System.IntPtr,
ByVal hsz2 As System.IntPtr, ByVal hdata As System.IntPtr, ByVal dwData1 As
UInteger, ByVal dwData2 As UInteger) As System.IntPtr
End Function
End Class
Hope this helps
LS

Jun 27 '08 #3

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

Similar topics

4
by: ma740988 | last post by:
// file sltest.h #ifndef SLTEST_H #define SLTEST_H class CallbackBase // herb shutters gotW source .. { public: virtual void operator()() const { }; virtual ~CallbackBase() = 0; };
15
by: Felix Kater | last post by:
Hi, in a given library I register callback functions with this function: bool set_callback(int index, int (*callback_function)(long)); I need the callback function to also pass the index...
0
by: Scott Chang | last post by:
Hi all, I tried to use Managed C++ coding of VC++.NET (2002)and OpenGL version 1.2 to draw a hexagon shape of benzene. My OpenGLdrawBenzene.cpp is the following: // This is the main project file...
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...
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...
2
by: Pradeep | last post by:
Hi all, Can any one explain me what is callback function.... I have written some code after reading some tutorials from internet... But I am not sure is it a right way to write a call back...
10
by: SQACPP | last post by:
Hi, I try to figure out how to use Callback procedure in a C++ form project The following code *work* perfectly on a console project #include "Windows.h" BOOL CALLBACK...
6
by: jmDesktop | last post by:
In a function that takes another function (function pointer) as a argument, or the callback function, which is the one that "calls back"? I'm having a hard time understanding the language. Am I...
5
by: Jef Driesen | last post by:
I have a C DLL that I want to use from a C# project. The C header file contains these declarations: typedef void (*callback_t) (const unsigned char *data, unsigned int size, void *userdata);...
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:
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
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,...
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
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,...

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.