-
April 9th, 2015, 03:04 PM
#1
sending usigned char to listbox
Got something like the following. A button that read characters from a thrid party tool and sends it to a listbox.
But the contant is not readable.
Code:
void dlg::sendtolistbox()
{
unsigned char buf[250];
thirdparty.GetData(buf, len);
Sendmessage(hndl, listboxupdate,0 , (LPARAM)buf);
}
void Mydlg::UpdateListBox(wparam a,laparm b)
{
m_listbox.AddString((LPCTSTR)b);
}
the characters show up in the list box as short unreadable characters. like it is chopped.
If i change to : Sendmessage(hndl, listboxupdate,0 , (LPARAM)&buf[15]);
Then I can see readable valid strings of up to 50 characters and then empty unreadable characters afterwards. I tried all kinds of things , including using CString, still did not work.
-
April 9th, 2015, 03:27 PM
#2
Re: sending usigned char to listbox
What is len?
Does GetData() append a NULL terminator to the end of the data obtained into buf?
Have you debugged the program using the debugger and examined the contents of buf in hex to see exactly what is there?
Are you mixing Unicode from GetData() and multi-char in the program (or vice/versa)?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
April 10th, 2015, 12:10 AM
#3
Re: sending usigned char to listbox
when I write the buf to file using WriteFile, the content of file is: 15 unreadable characters followed by 50 readable characters and the rest are I'..
When I do the following, I get the 50 readable characters in the listbox.
buf[len]='\0;
Sendmessage(hndl, listboxupdate,0 , (LPARAM)&buf[14]);
-
April 10th, 2015, 03:21 AM
#4
Re: sending usigned char to listbox
Have you examined the contents of the file in hex with something like HxD to see exactly what is being received? What would you expect to be received against what you are actually receiving?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
April 11th, 2015, 12:16 PM
#5
Re: sending usigned char to listbox
Good suggestion. Looked the file up under an hex editor. The first 8 bytes where the number of bytes. Then after, the bytes for the actual text that seem to be correct and the then the 2FEF bytes. Now how one can display all the bytes as readable in the listbox without subclassing the listbox?. As of now , in the list box, I can only display/read the text that comes after the number of bytes?.
Last edited by tcp1; April 11th, 2015 at 12:47 PM.
-
April 11th, 2015, 03:08 PM
#6
Re: sending usigned char to listbox
What you are seeing is a length-prefixed string (or sometimes called a Pascal string) as opposed to a null-terminated string as used in c/c++.
See http://en.wikipedia.org/wiki/String_...ength-prefixed
However, if the first 8 bytes is the number of bytes in the string what about the next 7 bytes before the readable characters start - as you said in post #3 that the first 15 chars were unreadable followed by 50 readable chars?
Can you attach the file?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
April 11th, 2015, 09:38 PM
#7
Re: sending usigned char to listbox
I do not have the access to the file at this moment. This is a new protocol, 8 bytes + the appended string... This is the new library ... with new protocol ... That 15 bytes is replaced with 8 bytes ... ...
-
April 11th, 2015, 10:13 PM
#8
Re: sending usigned char to listbox
As I remember, with the new protocol the first 8 bytes in the file, when I used the notepad as the viewer, were extended ASCII characters and maybe these are not supported by Microsoft, VS?.
http://www.theasciicode.com.ar/
-
April 12th, 2015, 01:54 AM
#9
Re: sending usigned char to listbox
As long as this is about file, the non-askii bytes are most probably BOM (http://en.m.wikipedia.org/wiki/Byte_order_mark)
Best regards,
Igor
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
|