CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    Nov 2008
    Location
    Cairo , Egypt
    Posts
    24

    Get a String from an IntPtr from a WPARAM

    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
    Code:
    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);
    }
    VB.NET Code
    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
    Last edited by komalo; May 31st, 2009 at 07:39 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured