|
-
May 27th, 2009, 02:15 PM
#1
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.
-
May 28th, 2009, 08:10 AM
#2
Re: Get a String from an IntPtr from a WPARAM
We'll need much more information, like :
How did you implement this API function ¿
How is it called ¿
What do you want to do precisely in your program ¿
PS, please don't type in bold format, it's quite straineous on the eyes
-
May 29th, 2009, 07:28 AM
#3
Re: Get a String from an IntPtr from a WPARAM
 Originally Posted by HanneSThEGreaT
We'll need much more information, like :
How did you implement this API function ¿
How is it called ¿
What do you want to do precisely in your program ¿
PS, please don't type in bold format, it's quite straineous on the eyes
it is not an api , my program has a global hook proc , i moniter WM_SETTEXT messages and send the LPSTR to my program through SendMessage to my Form, the hook proc works fine because i moniter other messages, and i receive the pointer successfully the problem that when using that IntPtr (the pointer) in Marshal.PtrToStringAuto i don't get the string, i even tried to send a normal message with my string to the form but i couldn't get the string
PS, sorry for the bold font i modified the post it now
-
May 29th, 2009, 07:55 AM
#4
Re: Get a String from an IntPtr from a WPARAM
SendMessage is an API, so it is an API.
How did you implement this ¿
Show us some code please, otherwise we'll sit here guessing until eternity.
If we don't know how you have sent the message through the SendMessage API, we cannot know the format of the sent message, as well what you want to do with it.
-
May 29th, 2009, 08:04 AM
#5
Re: Get a String from an IntPtr from a WPARAM
 Originally Posted by HanneSThEGreaT
SendMessage is an API, so it is an API.
How did you implement this ¿
Show us some code please, otherwise we'll sit here guessing until eternity.
If we don't know how you have sent the message through the SendMessage API, we cannot know the format of the sent message, as well what you want to do with it.
I know that it is an API , i was talking in general i don't implement any thing , BUT I USE SendMessage IN THE C++ HOOK DLL NOT VB.NET
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 29th, 2009 at 08:10 AM.
-
May 29th, 2009, 08:59 AM
#6
Re: Get a String from an IntPtr from a WPARAM
 Originally Posted by komalo
I know that it is an API ,
Right, now we all know it is an API. I'm not here to argue, I just want the members to understand the situation.
 Originally Posted by komalo
i was talking in general i don't implement any thing , BUT I USE SendMessage IN THE C++ HOOK DLL NOT VB.NET
 Originally Posted by komalo
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);
}
If this was included in the first post, we wouldn't even hav had an argument. Now we all know what the situation is, now we can help, agree ¿
I'll play with this at home tonight
-
May 31st, 2009, 07:38 AM
#7
Re: Get a String from an IntPtr from a WPARAM
 Originally Posted by HanneSThEGreaT
Right, now we all know it is an API. I'm not here to argue, I just want the members to understand the situation.
If this was included in the first post, we wouldn't even hav had an argument. Now we all know what the situation is, now we can help, agree ¿
I'll play with this at home tonight
yes i know, i was bad in explaining it, any way i add the code to the main post
thanks in advance
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|