D - strings & windows programming
- Robert M. Münch (36/36) Jul 08 2002 Hi, I'm trying to do some Windows programming by hand to get a feeling h...
- Sean L. Palmer (18/48) Jul 08 2002 the
- Robert M. Münch (15/35) Jul 09 2002 that
- Sean L. Palmer (14/51) Jul 09 2002 this
-
OddesE
(13/26)
Jul 13 2002
Hi, I'm trying to do some Windows programming by hand to get a feeling how to use D with the MS SDK. Well, I have some problems/questions. This is the code snippet. I try to read the user input from an edit-control: // get the number of characters int numInput = (WORD) SendDlgItemMessageA(hWnd, IDC_NUMPEOPLE, EM_LINELENGTH, (WPARAM) 0, (LPARAM) 0); D stores the length of a string first in an array. Am I right that this informaiton is internal to D and can only be access thru the .legnth attribute or can the size of the array be accessed with something like length = myarry[0]? So if the length is internal, than it's necessary to store the length in the array for Windows: // Put the number of characters into first entry of buffer. For this we have to expand the string by hand char people[]; people.length = numInput + 1; people[0] = (char)numInput; Wouldn't it be convinient to be able to do? char people[]; people[0] = (char)numInput; Here the array should be expanded automatically. The index is known so that it's clear how big people[] needs to be at least. Ok, now I want Windows to copy the text from the edit control into my string: SendDlgItemMessageA(hWnd, IDC_NUMPEOPLE, EM_GETLINE, (WPARAM) 0, (LPARAM) &people); Well this line ends up with rubish in people[]. I have to call it this way: SendDlgItemMessageA(hWnd, IDC_NUMPEOPLE, EM_GETLINE, (WPARAM) 0, (LPARAM) &people[0]); Why do I have to use the &people[0] syntax? Shouldn't this be the same &people = &people[0]? -- Robert M. Münch IT & Management Freelancer Mobile: +49 (0)177 2452 802 Fax : +49 (0)721 8408 9112 Web : http://www.robertmuench.de
Jul 08 2002
"Robert M. Münch" <robert.muench robertmuench.de> wrote in message news:agceq3$b2r$1 digitaldaemon.com...Hi, I'm trying to do some Windows programming by hand to get a feeling how to use D with the MS SDK. Well, I have some problems/questions. This isthecode snippet. I try to read the user input from an edit-control: // get the number of characters int numInput = (WORD) SendDlgItemMessageA(hWnd, IDC_NUMPEOPLE, EM_LINELENGTH, (WPARAM) 0, (LPARAM) 0); D stores the length of a string first in an array. Am I right that this informaiton is internal to D and can only be access thru the .legnth attribute or can the size of the array be accessed with something like length = myarry[0]?You're right. It can only be accessed via .length attribute. In fact, it's not a char either; I believe it's an int.So if the length is internal, than it's necessary to store the length inthearray for Windows:If you mean null-terminate it, well, that's easy: mystring ~= cast(char)0;// Put the number of characters into first entry of buffer. For thiswehave to expand the string by hand char people[]; people.length = numInput + 1; people[0] = (char)numInput; Wouldn't it be convinient to be able to do? char people[]; people[0] = (char)numInput; Here the array should be expanded automatically. The index is known sothatit's clear how big people[] needs to be at least.I don't know why you'd want to be able to do this.Ok, now I want Windows to copy the text from the edit control into my string: SendDlgItemMessageA(hWnd, IDC_NUMPEOPLE, EM_GETLINE, (WPARAM) 0, (LPARAM) &people); Well this line ends up with rubish in people[]. I have to call it thisway:SendDlgItemMessageA(hWnd, IDC_NUMPEOPLE, EM_GETLINE, (WPARAM) 0, (LPARAM) &people[0]); Why do I have to use the &people[0] syntax? Shouldn't this be the same &people = &people[0]?No, and you shouldn't depend on undocumented compiler-dependent stuff like that anyway. If you want the address of the first character in a string, you should say so explicitly. The string (like any struct) could have other things in it before the actual string data. In this case, the length. If this is too tedious, remember that you can write a wrapper class that deals with edit controls, and you only have to write that class *once*. Sean
Jul 08 2002
"Sean L. Palmer" <seanpalmer earthlink.net> schrieb im Newsbeitrag news:agcm7b$isb$1 digitaldaemon.com...thatWouldn't it be convinient to be able to do? char people[]; people[0] = (char)numInput; Here the array should be expanded automatically. The index is known soHi, IMO if we have dynamic arrays these are either dynamic or not but no mish-mash. So why can't I write the following: char test[]; test[123] = 'a'; If test.length was 0 than after this line it will be at least 123. IMO this makes sense. Why should I have to start at the beginning?it's clear how big people[] needs to be at least.I don't know why you'd want to be able to do this.way:Well this line ends up with rubish in people[]. I have to call it thisThis is undocumented? Hm... didn't knew about this. So what's the correct way to do it in D?SendDlgItemMessageA(hWnd, IDC_NUMPEOPLE, EM_GETLINE, (WPARAM) 0, (LPARAM) &people[0]); Why do I have to use the &people[0] syntax? Shouldn't this be the same &people = &people[0]?No, and you shouldn't depend on undocumented compiler-dependent stuff like that anyway.If you want the address of the first character in a string, you should say so explicitly.That's what I tried first with &people but this didn't worked.If this is too tedious, remember that you can write a wrapper class that deals with edit controls, and you only have to write that class *once*.I know but first I need to get the basis right and than I think about re-using :-)). Robert
Jul 09 2002
"Robert M. Münch" <robert.muench robertmuench.de> wrote in message news:age639$24ld$1 digitaldaemon.com..."Sean L. Palmer" <seanpalmer earthlink.net> schrieb im Newsbeitrag news:agcm7b$isb$1 digitaldaemon.com...thisthatWouldn't it be convinient to be able to do? char people[]; people[0] = (char)numInput; Here the array should be expanded automatically. The index is known soHi, IMO if we have dynamic arrays these are either dynamic or not but no mish-mash. So why can't I write the following: char test[]; test[123] = 'a'; If test.length was 0 than after this line it will be at least 123. IMOit's clear how big people[] needs to be at least.I don't know why you'd want to be able to do this.makes sense. Why should I have to start at the beginning?Because you don't want the compiler to have to insert hidden checks to make sure the array is big enough and potentially reallocate it before *every* single element assignment.likeway:Well this line ends up with rubish in people[]. I have to call it thisSendDlgItemMessageA(hWnd, IDC_NUMPEOPLE, EM_GETLINE, (WPARAM) 0, (LPARAM) &people[0]); Why do I have to use the &people[0] syntax? Shouldn't this be the same &people = &people[0]?No, and you shouldn't depend on undocumented compiler-dependent stuffThe location in physical memory of the length property is undocumented and compiler-specific. Or it should be.that anyway.This is undocumented? Hm... didn't knew about this. So what's the correct way to do it in D?That's because you asked for the address of the dynamic array, not the address of the first element. Say what you mean. And when programming D, you have to say it in D, not some other language. ;)If you want the address of the first character in a string, you should say so explicitly.That's what I tried first with &people but this didn't worked.hehehe SeanIf this is too tedious, remember that you can write a wrapper class that deals with edit controls, and you only have to write that class *once*.I know but first I need to get the basis right and than I think about re-using :-)). Robert
Jul 09 2002
"Sean L. Palmer" <seanpalmer earthlink.net> wrote in message news:agcm7b$isb$1 digitaldaemon.com..."Robert M. Münch" <robert.muench robertmuench.de> wrote in message news:agceq3$b2r$1 digitaldaemon.com...<SNIP>otherWhy do I have to use the &people[0] syntax? Shouldn't this be the same &people = &people[0]?No, and you shouldn't depend on undocumented compiler-dependent stuff like that anyway. If you want the address of the first character in a string, you should say so explicitly. The string (like any struct) could havethings in it before the actual string data. In this case, the length. If this is too tedious, remember that you can write a wrapper class that deals with edit controls, and you only have to write that class *once*. SeanAnd I think Pavel is busy doing just that, writing classes for interfacing with Windows stuff such as windows, edit controls etc... -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net _________________________________________________ Remove _XYZ from my address when replying by mail
Jul 13 2002