![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
|
ala... (AT) gmail (DOT) com> wrote in message news:1176826301.501011.121310 (AT) q75g2000hsh (DOT) googlegroups.com... Hi Mike, You are really VB WINAPI expert, adding byval does help. However, I get this declaration from API viewer, it seems that the declaration from API viewer may not be correct. Oh, I realize that lParam can be pointer for POINT structure. No, the declaration in the viewer is correct, it's just "generic". What you pass for SendMessage's LParam can vary, even the data type. It might be a String, or a Long, or a structure (not just a POINT structure). That's why the declaration in the API Viewer has lParam As Any. It's more versatile this way, but also more error-prone and even somewhat dangerous (not too difficult to cause the app to crash if you don't pass lParam correctly for the message you're sending). What many people do is declare type-safe versions of SendMessage. For example Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long Public Declare Function SendMessageByLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Public Declare Function SendMessageByPOINTAPI Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As POINTAPI) As Long As you can see, this takes care of the ByVal keyword (to include or not include it) in the declaration. Since you didn't include the declaration in your original post, I couldn't be sure if this was the problem, or if it could be something, anything, else. You should always include API declarations when posting your code for this reason and others. Also, your code might have worked without the ByVal keyword IF you had assigned the return value of MAKELPARAM to a variable and used that variable in your call to SendMessage. Not sure about that, but it's probably a better way to go anyway. I am author of a pop shareware, to thank you, I can send you a free license. You can send me email atalanwo[at]gmail[dot]com. Appreciate the gesture, but that's quite alright. -- Mike Microsoft Visual Basic MVP |
#2
| |||
| |||
|
|
Hi Mike, when uprade this to vb.net, VarPtr is not support but the Help file provide no alternative to replace. Is there any safe handler to replace VarPtr? 'UPGRADE_ISSUE: VarPtr function is not supported. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm? keyword="367764E5-F3F8-4E43-AC3E-7FE0B5E074E2"' SendMessageTimeout HwndOver, WM_GETTEXT, 255, VarPtr(WindowTextArray(0)), 0, 1000, 0 Alan On Apr 18, 3:43 am, "MikeD" <nob... (AT) nowhere (DOT) edu> wrote: ala... (AT) gmail (DOT) com> wrote in message news:1176826301.501011.121310 (AT) q75g2000hsh (DOT) googlegroups.com... Hi Mike, You are really VB WINAPI expert, adding byval does help. However, I get this declaration from API viewer, it seems that the declaration from API viewer may not be correct. Oh, I realize that lParam can be pointer for POINT structure. No, the declaration in the viewer is correct, it's just "generic". What you pass for SendMessage's LParam can vary, even the data type. It might be a String, or a Long, or a structure (not just a POINT structure). That's why the declaration in the API Viewer has lParam As Any. It's more versatile this way, but also more error-prone and even somewhat dangerous (not too difficult to cause the app to crash if you don't pass lParam correctly for the message you're sending). What many people do is declare type-safe versions of SendMessage. For example Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long Public Declare Function SendMessageByLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Public Declare Function SendMessageByPOINTAPI Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As POINTAPI) As Long As you can see, this takes care of the ByVal keyword (to include or not include it) in the declaration. Since you didn't include the declaration in your original post, I couldn't be sure if this was the problem, or if it could be something, anything, else. You should always include API declarations when posting your code for this reason and others. Also, your code might have worked without the ByVal keyword IF you had assigned the return value of MAKELPARAM to a variable and used that variable in your call to SendMessage. Not sure about that, but it's probably a better way to go anyway. I am author of a pop shareware, to thank you, I can send you a free license. You can send me email atalanwo[at]gmail[dot]com. Appreciate the gesture, but that's quite alright. -- Mike Microsoft Visual Basic MVP- Hide quoted text - - Show quoted text - |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |