Can anyone see why my vb.net code ipc callback function isn't working? I am seeing messageLen = 0 when the function fires and the pointer address is something like 4283843843. It doesn't look like i'm getting the right data from madshi's hookprocesscreation.dll to my vb.net callback. My VB6 code below works just fine though, do I have things declared right in the .net side??
Here is my vb.net 2005 code for ipc functionality:
'FOR MARSHALLING
'Imports System.Runtime.InteropServices
Public Class Form1
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal pDst As IntPtr, ByVal pSrc As IntPtr, ByVal ByteLen As Long)
'THIS IS THE DLL FUNCTION CALL
Public Declare Function CreateIpcQueue Lib "MadCHook.dll" (ByVal ipc As String, ByVal callback As IPCDelegate) As Boolean
'THIS IS MY DELEGATE FUNCTION
Public Delegate Function IPCDelegate(ByVal IPCname As String, ByVal messageBuf As Long, ByVal messageLen As Long, ByVal answerBuf As Long, ByVal answerLen As Long) As Long
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim proc As New IPCDelegate(AddressOf TheRealCallback)
ret = CreateIpcQueue("IPC" & Chr(0), AddressOf TheRealCallback)
End Sub
Public Function TheRealCallback(ByVal IPCname As String, ByVal messageBuf As Long, ByVal messageLen As Long, ByVal answerBuf As Long, ByVal answerLen As Long) As Long
'THIS CALLBACK FIRES WHEN AN EXE IS RUN BUT THE messageLen is 0 and the pointer doesn't look right??? dunno why??
'TheRealCallback = 0
End Function
End Class
VB6 code that does work fine:
'FORM
Option Explicit
Private Sub Command1_Click()
Text1.Text = Empty
End Sub
Private Sub Form_Load()
Text1.Text = ""
If CreateIpcQueue("IPC" & Chr(0), AddressOf IPCCallbackFunction) Then
Text1.SelText = "IPC Started" & vbCrLf
Else
Text1.SelText = "IPC FAILED" & vbCrLf
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
If DestroyIpcQueue("IPC" & Chr(0)) Then
MsgBox "IPC Stopped"
Else
MsgBox "ICP Stop Failed"
End If
End Sub
'MODULE CODE
Option Explicit
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Public Declare Function CreateIpcQueue Lib "MadCHook.dll" (ByVal ipc As String, ByVal callback As Long) As Boolean
Public Declare Function DestroyIpcQueue Lib "MadCHook.dll" (ByVal ipc As String) As Boolean
Public Function IPCCallbackFunction(ByVal IPCname As String, ByVal messageBuf As Long, ByVal messageLen As Long, answerBuf As Long, ByVal answerLen As Long) As Long
Dim ByteArrayBuf(1 To 255) As Byte
Dim Msg As String
Call CopyMemory(ByteArrayBuf(1), ByVal messageBuf, ByVal messageLen)
Msg = Left$(StrConv(ByteArrayBuf, vbUnicode), messageLen)
Form1.Text1.SelText = Msg & vbCrLf
If answerLen <> 0 Then
Msg = "Reply back from VB" & Chr(0)
messageLen = Len(Msg)
Call CopyMemory(answerBuf, ByVal Msg, ByVal messageLen)
End If
End Function
Delphi dll to VB.net 2005 IPC working...almost!
-
- Posts: 87
- Joined: Thu Jun 02, 2005 3:46 am