digitalmars.D - Trying to cast string to lParm for use with WinApi call SendMessageA
-
Lynn Allan
(20/20)
Jul 16 2004
-
Matthew
(4/25)
Jul 16 2004
"Lynn Allan"
wrote in message - Lynn Allan (13/16) Jul 17 2004 To
- Russ Lewis (8/24) Jul 17 2004 Probably.
- Matthew (4/28) Jul 17 2004 I often declare overloaded wrappers for this kind of stuff. Check out
- Regan Heath (13/39) Jul 17 2004 (char *) is not the only type one might want to pass here, I have passed...
- Matthew (3/19) Jul 17 2004 Yes. Apologies for my arcane and sloppy advice. :)
<newbie alert> I'm attempting to expand on the WinApi winsamp.d gui example with some controls, such as a single line edit control and a multiline edit control. I can create the controls fine with CreateWindowA, but I'm having trouble using SendMessageA with a string for the lParam parameter. hTextViewerEdit = CreateWindowA("EDIT", "", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOVSCROLL | WS_VSCROLL | ES_LEFT | ES_MULTILINE | ES_NOHIDESEL, 115, 32, 260, 300, hWndMain, cast(HMENU) IDC_EDIT_TEXT_VIEWER, hInstance, null); SendMessageA(hTextViewerEdit, WM_SETTEXT, 0, "Test"); The compiler complains that "Test" isn't compatible with int parameter it expects. I've tried a variety of casts and temp variables to attempt to get SendMessageA to work, but haven't succeeded. I looked over the documentation, forum, and within phobos.d to try to figure out how to do this. How is this done? TIA, Lynn A.
Jul 16 2004
"Test" is a D string, which is a four-byte length and a four-byte pointer. To pass to Win32 API you need the pointer, so cast as (char*), as inSendMessageA(hTextViewerEdit, WM_SETTEXT, 0, (char*)"Test");"Lynn Allan" <l.allan att.net> wrote in message news:cd9seb$p5n$1 digitaldaemon.com...<newbie alert> I'm attempting to expand on the WinApi winsamp.d gui example with some controls, such as a single line edit control and a multiline edit control. I can create the controls fine with CreateWindowA, but I'm having trouble using SendMessageA with a string for the lParam parameter. hTextViewerEdit = CreateWindowA("EDIT", "", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOVSCROLL | WS_VSCROLL | ES_LEFT | ES_MULTILINE | ES_NOHIDESEL, 115, 32, 260, 300, hWndMain, cast(HMENU) IDC_EDIT_TEXT_VIEWER, hInstance, null); SendMessageA(hTextViewerEdit, WM_SETTEXT, 0, "Test"); The compiler complains that "Test" isn't compatible with int parameter it expects. I've tried a variety of casts and temp variables to attempt to get SendMessageA to work, but haven't succeeded. I looked over the documentation, forum, and within phobos.d to try to figure out how to do this. How is this done? TIA, Lynn A.
Jul 16 2004
Hi Matthew, Thanks for the info ... and your patience with this newbie."Test" is a D string, which is a four-byte length and a four-byte pointer.Topass to Win32 API you need the pointer, so cast as (char*), as inAlmost. Without the deprecated flag, the 0.95 compiler was unhappy without: cast(char*)"Test" and was still unhappy trying to coerce from char* to LPARAM. The following (hack?) works ok. char* p = "Test1"; SendMessageA(hTextViewerEdit, WM_SETTEXT, 0, cast(int)p); and this also works: SendMessageA(hTextViewerEdit, WM_SETTEXT, 0, cast(int)cast(char*)"Test2"); Is this the proper / appropriate way to accomplish this? Lynn A.SendMessageA(hTextViewerEdit, WM_SETTEXT, 0, (char*)"Test");
Jul 17 2004
Lynn Allan wrote:Probably. Just to speak up for D here, this is a problem with the Microsoft API, not with D. D implicitly casts char[] to char*, so if Microsoft had decided to declare the parameter as char*, you never would have seen this problem. Perhaps somebody should implement a wrapper function with a more sensible char* argument.Almost. Without the deprecated flag, the 0.95 compiler was unhappy without: cast(char*)"Test" and was still unhappy trying to coerce from char* to LPARAM. The following (hack?) works ok. char* p = "Test1"; SendMessageA(hTextViewerEdit, WM_SETTEXT, 0, cast(int)p); and this also works: SendMessageA(hTextViewerEdit, WM_SETTEXT, 0, cast(int)cast(char*)"Test2"); Is this the proper / appropriate way to accomplish this?SendMessageA(hTextViewerEdit, WM_SETTEXT, 0, (char*)"Test");
Jul 17 2004
"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message news:cdbkhi$1e3d$1 digitaldaemon.com...Lynn Allan wrote:I often declare overloaded wrappers for this kind of stuff. Check out std/windows/registry.dProbably. Just to speak up for D here, this is a problem with the Microsoft API, not with D. D implicitly casts char[] to char*, so if Microsoft had decided to declare the parameter as char*, you never would have seen this problem. Perhaps somebody should implement a wrapper function with a more sensible char* argument.Almost. Without the deprecated flag, the 0.95 compiler was unhappy without: cast(char*)"Test" and was still unhappy trying to coerce from char* to LPARAM. The following (hack?) works ok. char* p = "Test1"; SendMessageA(hTextViewerEdit, WM_SETTEXT, 0, cast(int)p); and this also works: SendMessageA(hTextViewerEdit, WM_SETTEXT, 0, cast(int)cast(char*)"Test2"); Is this the proper / appropriate way to accomplish this?SendMessageA(hTextViewerEdit, WM_SETTEXT, 0, (char*)"Test");
Jul 17 2004
On Sat, 17 Jul 2004 09:36:02 -0700, Russ Lewis <spamhole-2001-07-16 deming-os.org> wrote:Lynn Allan wrote:(char *) is not the only type one might want to pass here, I have passed classes/structs/ints/floats... Do you write a wrapper for each of those, or only 1 wrapper for (char *). If you write one wrapper wont you confuse someone who is looking for a way to pass something else, granted that is what this original function does.. writing lots of wrappers seems.. excessive when a cast will achieve what you need. This appears to be another instance where a 'variant' type would be useful. Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/Probably. Just to speak up for D here, this is a problem with the Microsoft API, not with D. D implicitly casts char[] to char*, so if Microsoft had decided to declare the parameter as char*, you never would have seen this problem. Perhaps somebody should implement a wrapper function with a more sensible char* argument.Almost. Without the deprecated flag, the 0.95 compiler was unhappy without: cast(char*)"Test" and was still unhappy trying to coerce from char* to LPARAM. The following (hack?) works ok. char* p = "Test1"; SendMessageA(hTextViewerEdit, WM_SETTEXT, 0, cast(int)p); and this also works: SendMessageA(hTextViewerEdit, WM_SETTEXT, 0, cast(int)cast(char*)"Test2"); Is this the proper / appropriate way to accomplish this?SendMessageA(hTextViewerEdit, WM_SETTEXT, 0, (char*)"Test");
Jul 17 2004
"Lynn Allan" <l.allan att.net> wrote in message news:cdbc1i$1bfo$1 digitaldaemon.com...Hi Matthew, Thanks for the info ... and your patience with this newbie.Yes. Apologies for my arcane and sloppy advice. :)"Test" is a D string, which is a four-byte length and a four-byte pointer.Topass to Win32 API you need the pointer, so cast as (char*), as inAlmost. Without the deprecated flag, the 0.95 compiler was unhappy without: cast(char*)"Test" and was still unhappy trying to coerce from char* to LPARAM. The following (hack?) works ok. char* p = "Test1"; SendMessageA(hTextViewerEdit, WM_SETTEXT, 0, cast(int)p); and this also works: SendMessageA(hTextViewerEdit, WM_SETTEXT, 0, cast(int)cast(char*)"Test2"); Is this the proper / appropriate way to accomplish this?SendMessageA(hTextViewerEdit, WM_SETTEXT, 0, (char*)"Test");
Jul 17 2004