|
od@ananzi.co.za wrote: Err, which link would that be ?
sorry for not answering, I was on a holiday. You get a user's page with the "person" icon next to a nickname (here a direct link to mine).
|
|
|
|
|
I am having a problem reading binary files.
Basically, everything works fine as long as the byte I read from the binary file is not a 0x00 byte. For example, reading the following (in hex): A0, 30, C0, C0 ... works fine.
But, reading: A0, 34, 03, 00 ... does not work fine.
When I concatenate the strings, instead of sticking "rec" at the end of "data", it concatenates it BEFORE the end of "data" - I assume this is so because one of the bytes I read (00) is treated like '\0' (null). How do I fix this? I have tried using unsigned chars, but that didn't work, I can't use read with them. The string/char array MUST contain everything I read from the binary file (even 0x00), so it can be like "somebyteshere0x00morebyteshere" which is why i need "rec" added to the END of "data", even if "data" contains nulls before its end.
I am using Visual Studio 2005.
A snippet of my code is posted below
string data = "";
char lr[5];
char rec[1028-4];
...
pageFile.read(lr, 4);
lr[4] = '\0'; // terminate string
...
pageFile.read(rec, length-4); // "length" is extracted from "lr"; it is correct, checked many times
rec[length-4] = '\0'; // terminate string
...
data = lr;
data = data + rec; // <----------- problem happens here
Thanks for any help!
|
|
|
|
|
dfn wrote: I assume this is so because one of the bytes I read (00) is treated like '\0' (null)
it's not just "treated like" a null, it is a null. C-style strings end on zero bytes.
short answer: if your data contains 0's, don't treat it as a C string.
long answer: if you need to read non-text data, you're going to have to read the data into byte arrays (char/u-char) and manipulate it there, with pointers - don't put it in std::strings or CStrings or anything like that because those objects are going to see those 0's and treat them as string terminators.
|
|
|
|
|
Thanks for your help!
I tried strcat on "lr" and "rec" (char arrays), but that resulted in the same thing as adding them to "data" (string).
I couldn't get unsigned chars to work with read().
Every attempt I made, trying to work with chars & strings, or chars only, had the same result.
|
|
|
|
|
dfn wrote: I tried strcat on "lr" and "rec" (char arrays), but that resulted in the same thing as adding them to "data" (string).
right, because binary data is not a string (strcat = string-concatenate).
you are not going to be able to use any function or object that manipulates C-style strings - no "str*" functions, no "string" objects, no *scanf, or *printf functions.
|
|
|
|
|
Ah good ol' for loops.
Thank you very much for your help. I actually learned something
|
|
|
|
|
Are you using Unicode? If so, can you use wstring instead of string ?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks for the reply.
Not using Unicode, the file is ANSI-encoded.
|
|
|
|
|
you have to write a short function that change all 00 bytes in a so called "string" into the real string "0x00". To do this, read or copy your char array into a unsigned char array that is much longer. then manipulate this unsigned char array (change all 00 bytes into 4 bytes "0x00", then copy the unsigned char array back to your designated string.
|
|
|
|
|
Before I solved it, I was thinking about something like this. Luckily, I solved the problem.
Thanks for the reply!
|
|
|
|
|
Hi,
I have to read a binary file in my projecto too. And then use the values of the binary to complete the names of my elements. I put you a bit of my code, I hope it helps
UINT nObj = 0, nSub = 0;
BYTE byteData = 0x00;
BYTE* pDataBuf;
for (nObj = 0; nObj < Header[6]; nObj++)
{ BYTE aReadSet [8] = {0};
pDataBuf = &aReadSet[0];
for (nSub = 0; nSub < pDoc->m_cmlObjSet[nObj].m_cmlSubSet.GetCount (); nSub ++)
{
file->Read (pDataBuf, 8 * sizeof (BYTE));
aReadSet[0] = *pDataBuf;
CString szNameUnit = "";
szNameUnit.Format (_T("%X"), aReadSet[0]);
pDoc->m_cmlObjSet[nObj].m_cmlSubSet[nSub].m_szSubName = "SubObject"+szNameUnit;
}
}
With that I read every block of data, use the first member of the array (binary ID) to differenciate/identify every element is being saved... The IDs may have values from 00 to FA, and ALL are readen and written correctly.
Ahm... I'm using VC++ 6
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
Already solved the problem, but appreciate the help! Thanks!
|
|
|
|
|
I have a program where sometimes I need a button to launch a different program.
I used WinExec() for the job, even though I get the impression that it is out of date and I should be using something else. So, first of all, if there is a better choice, please let me know. WinExec() does the job nicely since it is so simple.
Here is my real question. The second application takes a lot of memory and I don't want to launch multiple instances of it. So I would like something to check to see if it is running. If not, launch it. If yes, jump to the instance which is running.
Is there an easy way to do this?
Thanks,
Ilan
|
|
|
|
|
|
IlanTal wrote: I don't want to launch multiple instances of it
See this[^] thread for your question and you said you used of WinExec,its of MSDN :
"This function is provided only for compatibility with 16-bit Windows. Applications should use the CreateProcess function"
|
|
|
|
|
IlanTal wrote: So, first of all, if there is a better choice, please let me know. WinExec() does the job nicely since it is so simple.
See here.
IlanTal wrote: Here is my real question. The second application takes a lot of memory and I don't want to launch multiple instances of it. So I would like something to check to see if it is running. If not, launch it. If yes, jump to the instance which is running.
Is there an easy way to do this?
See here.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
You can use CreateProcess or ShellExecute or ShellExecuteEx depending on ur req.
|
|
|
|
|
Thanks to all for the replies. It is nice to receive so many replies.
They were useful and the problem is now solved (using a mutex).
Ilan
|
|
|
|
|
Use CreateProcess() and keep the handle around. If the handle is NULL, don't let the program be executed again.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi,
I have the need for true WYSIWYG text output using VC++ 2003. I am using text boxes. I have seen the WYSIWYG example on Codeguru, but it does not expand tabs. I either need to know how to expand tabs like the CEdit control does (without using DrawText), or implement the RichTextBox. Does anyone know if the RichTextBox supports WYSIWYG printing - or how to do it?
Even the knowledge of a third party ActiveX control would be helpful.
Thanks,
-Gabe
|
|
|
|
|
If you use the same font as the "text box" (edit control?) then you should be able to render the
text the same as the system control does.
Maybe the TabbedTextOut() API will help if you need more control over tabs.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thanks Mark. I am doing all that. Problem is that Windows has inherent issues with these functions (DrawText, TabbedTextOut) due to the integer-based text metrics. (See p 972 in Feng Yuan's Windows Graphics Programming book). DrawText handles tabs and works OK until you want to zoom or print. Due to the rounding errors you get slightly different results. He has some examples that are a little difficult to follow and do not support things such as tabs, DT_CENTER, etc. Never thought this would be so difficult. -Gabe
|
|
|
|
|
Hi,
The first is about the member "palVersion" in the struct LOGPALETTE. MSDN says:
The LOGPALETTE structure defines a logical color palette.
typedef struct tagLOGPALETTE { // lgpl
WORD palVersion;
WORD palNumEntries;
PALETTEENTRY palPalEntry[1];
} LOGPALETTE;
palVersion: Specifies the version number of the system.
palNumEntries: Specifies the number of entries in the logical color palette.
palPalEntry: Specifies an array of PALETTEENTRY structures that define the color and usage of each entry in the logical palette.
But... what is exactly this parameter for? I guess is something it may change depending on the computer where my application is being executed. How can I determine in Runtime this value? I have seen an example that writes 0x300 but I don't know if it is a good idea to write the same as in the example.
The case is that I want to make DIBs from the Bitmaps I made in the resource editor because of the problem I explain in other message ( Printing Problems[^] if possible I would like to have answers for the other quesion I made there). As those .rc Bitmaps are made in 20-Colors... Do I really need the Palette? Or may I use
hPal = (HPALETTE) GetStockObject (DEFAULT_PALETTE);
to make the DIB of those bitmap-resources? I think it will be much easier, and I suppose it won't give me any problem about compatibility with printers... Or am I wrong?
I know is difficult to answer a message, specially in Forums with such a volume of posts like this but, I need a bit of help with this (and the other message) at least to understand things. I will make the rest by myself.
Thanks
Edit: Default are 20 colors not 16...
-- modified at 11:27 Wednesday 9th May, 2007
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
|
Nelek wrote: But... what is exactly this parameter for?
I've never found any documentation on LOGPALETTE.palVersion. I've always used 0x0300
Nelek wrote: As those .rc Bitmaps are made in 20-Colors... Do I really need the Palette?
This depends on the format of the DDB. If it's 1, 4, or 8 bitsperpixel then the data for each
pixel is an index into the palette associated with the device that the bitmap is dependent on.
For 16+ bits-per-pixel bitmaps, the color info is stored in each pixels data so no mapping to
a palette is necessary when converting to a DIB.
Since resource bitmaps are meant for display devices, the default system palette should work fine
if you need it for conversion.
If you use GetDIBits to do the conversion, GetDIBits will use the palette associated with the
DC passed to the function.
Here's another article: How To Convert Between Device-Dependent Bitmaps and DIBs[^]
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|