i am using SendMessage to send a message with a LPTSTR in WPARAM from a dll to my vb.net form and i get it by overriding WndProc but the problem is when using Marshal.PtrToStringAuto on the WPARAM it doesn't work, the strange thing is that if i monitor WM_SETTEXT of the form and use PtrToStringAuto to get the string from LPARAM it works, i guess mine doesn't work that's because the dll is loaded by other application.
C++ DLL Proc
VB.NET CodeCode:LRESULT CALLBACK CallWndProc(int nCode,WPARAM wParam,LPARAM lParam) { if( (lParam!=NULL) && (nCode == HC_ACTION)) { CWPSTRUCT *CwpStruct = (CWPSTRUCT *) lParam; switch(CwpStruct->message) { case WM_SETTEXT: SendMessageTimeout(hWnd,WM_USER + 2,WPARAM(CwpStruct->lParam),LPARAM(CwpStruct->hwnd),SMTO_ABORTIFHUNG,100,0); break; } } return CallNextHookEx(hHook,nCode,wParam,lParam); }
Code:Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Try Select Case m.Msg Case MyMsgs.WM_SETTEXT 'i successfully get the pointer but can't get the text Me.Text = System.Runtime.InteropServices.Marshal.PtrToStringAuto(m.WParam) Catch ex As Exception Debug.WriteLine("Error Messages : " & ex.Message ) Finally MyBase.WndProc(m) End Try End Sub




Reply With Quote