Porting A Callback Function

R

RFleming

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
 
K

kimiraikkonen

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
 
L

Lloyd Sheen

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.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)>
_
Public Structure HDDEDATA__

'''int
Public unused As Integer
End Structure

<System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)>
_
Public Structure HCONV__

'''int
Public unused As Integer
End Structure

<System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)>
_
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top