By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,761 Members | 1,183 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,761 IT Pros & Developers. It's quick & easy.

Porting A Callback Function

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.