I have a code sample showing how to retrieve text from an edit control that is then sized for length of the text, plus 1 byte. With the length determined by “text-length+1” that value is then used to size an Array of Global Byte(s) created as data container for the text in the edit control.
An Asciiz Pointer is then declared and given the handle of the Array of Bytes so that after the text is moved into the Array of Bytes the handle can then be passed to an external DLL as an Asciiz Pointer where text is retrieved.
I've never had to move text into an Array of Bytes, and while I could easily pass text into an Asciiz string, that won't work because the compiler defines the size of the Asciiz String at compile time and the DLL getting the text wants the message text trimmed before passing.
We can only dimension Asciiz variables at compile, but arrays can be sized during execution so it seems like a neat way to get around the fixed length variable sizing when the potential size of a message text length could be large or tiny and always is unknown at compile.
Here is the offered sample section of code that works great in a Dialog process:
For reference, I've tried passing the address handle of the variable length text data padded with a $Nul terminator to the DLL by using VarPtr to pass the handle of the padded string, but that didn't work. Tried Poke$ byBuffer(0), MsgTxt$, and lpBuffer = VarPtr(byBuffer(0)), but that GPFs nicely.
How do I solve this kind of an issue when I don't have a Control to act as an intermediary in the work?
An Asciiz Pointer is then declared and given the handle of the Array of Bytes so that after the text is moved into the Array of Bytes the handle can then be passed to an external DLL as an Asciiz Pointer where text is retrieved.
I've never had to move text into an Array of Bytes, and while I could easily pass text into an Asciiz string, that won't work because the compiler defines the size of the Asciiz String at compile time and the DLL getting the text wants the message text trimmed before passing.
We can only dimension Asciiz variables at compile, but arrays can be sized during execution so it seems like a neat way to get around the fixed length variable sizing when the potential size of a message text length could be large or tiny and always is unknown at compile.
Here is the offered sample section of code that works great in a Dialog process:
Code:
Local nLength As Long ' Determine the Size of the Message being sent by getting the ' length of the message text that was entered by the user Control Send hDlg, %IDC_MESSAGE, %WM_GETTEXTLENGTH, 0, 0 To nLength ' Allocate a temporary buffer that is large enough to contain the ' message text and a pointer to that buffer Dim byBuffer(nLength + 1) As Global Byte Dim lpBuffer As Asciiz Ptr ' Pass the buffer handle to the Asciiz Ptr lpBuffer = VarPtr(byBuffer(0)) ' Put the Message Text into the lpBuffer Control Send hDlg, %IDC_MESSAGE, %WM_GETTEXT, nLength + 1, lpBuffer
How do I solve this kind of an issue when I don't have a Control to act as an intermediary in the work?
Comment