|
|
This is silly! Yes it is necessary, but the programming language or the compiler vender may provide a method for doing it for you (another programmer). If you really want to be a programmer, then you should be able to recreate the code to do the conversion. The others have showed you the methods provided to do the conversion (which you should use), but you are not a programmer until you can write a method to do it your self.
INTP
Every thing is relative...
|
|
|
|
|
thank you for your help
|
|
|
|
|
Hi one, hi all!
I have recently ported from WiInet to WinHttp in my server application.
Everything works just fine but there is one major question regarding some flags that were set in the WinInet HttpOpenRequest(…). The dwFlags had values of INTERNET_FLAG_KEEP_CONNECTION and INTERNET_FLAG_NO_CACHE_WRITE which I need to use, the problem is I can not find the equivalent in the WinHttp API protocol!!! I was told to add it the Headers of the request in format of:
"Content-Type: application/x-www-form-urlencoded\r\n Connection : Keep-Alive\r\n Cache-Control: no-cache"
but it seems rather strange to set flags as part of the message sent to the server!
Any one?
Thanks
S
|
|
|
|
|
|
You've got a couple options here.
1. If the file is relatively small, read the entire file into a string and then use one of the string search functions (like strstr ) to find the opening marker <<A>>. Extract the data from where you find it.
2. If the file is large, read it a chunk at a time. Look for the first character in the marker in the chunk. If you find it, read enough more out of the file, appending to the chunk, that you're sure you have all of the data you're interested in. Extract the data.
3. Given your example, it almost sounds like you're trying to read XML. If that's the case, there's plenty of code around for helping you do that.
Software Zen: delete this;
|
|
|
|
|
1. no - I'm not trying to read an XML file. I'm trying to read a picture file that has a header from which I'm trying to extract the string... when I open the picture file with a text editor I see the string I have to read... and yes, the file is big...
2. How can I read chunk by chunk? with the read function?
right now, I'm reading like this:
int MaxBufferSize = 1000;
char cTemp[MaxBufferSize + 1];
cf.Read(cTemp, MaxBufferSize);
//then look for the string in the cTemp array.
is this the correct way to do this?
how can I search for the string in the cTemp array? with a for loop?
|
|
|
|
|
Try looking up the strstr function, which searches for one string within another.
You can also do the search yourself by looping through the data, something like this:
for (int offset = 0; offset < MaxBufferSize; offset++) {
if (CTemp[offset] == '<') {
if (strcmp(&CTemp[offset],"<<A>>") == 0) {
}
}
}
Software Zen: delete this;
|
|
|
|
|
This loop will not work. The strcmp function matches two NULL terminated strings - As such it will never match the sequence unless it's at the end of the buffer (the only place where it could be NULL terminated).
Steve
|
|
|
|
|
|
Try this:
CFile cf(sCurrImgPath, CFile::modeRead);
const int MaxBufferSize = 100000;
char cTemp[MaxBufferSize + 1];
const char *pStringToFind = "<<A>>";
size_t LengthOfStringToFind = strlen(pStringToFind);
while (pStr == NULL)
{
iBytesRead = cf.Read(cTemp, MaxBufferSize);
pStr = strstr(cTemp, pStringToFind);
if ( pStr != NULL )
{
pStr += LengthOfStringToFind ;
}
}
Steve
|
|
|
|
|
Ok - it still doesn't work....
I think the problem is that I am trying to read text from a file which is actually an image file.
I'll explain my problem in a different manner...
what I have is a *.png file (image file), which has a row of text somewhere in the file. This row starts with: >tEXtComment, and continues with the data I need to read...
how can I extract this row that starts with ›tEXtComment from the image file?
|
|
|
|
|
Before you worry about that test your code on a plain text file you create.
Steve
|
|
|
|
|
Ok - so I copied the string to a text file and renamed it as a *.png file, and it finds the string, and works fine...
|
|
|
|
|
Ok. Now open the .png file with Notepad and see it actually contains the string.
Steve
|
|
|
|
|
what .png file? I didn't understand what u meant..
I already opened the .png files with notepad, and they all contain the string. That includes the .png file that is the actual image, and the .png file I just created...
|
|
|
|
|
I can't think of what could be going wrong then. If it finds it the text file it should work for the image file - assuming the string is present. The only think I can suggest is to check that the cases are consistent. i.e. Search string is in upper cast but string in file is in lower case.
Steve
|
|
|
|
|
I'll tell u something - I copied all of the data from the .png file that is an image file(the original file), to the .png file I constructed from Notepad, and the search for the string works...
So I think the problem is in the fact that the original .png file was originally constructed as an image file...
|
|
|
|
|
Oops. That should have been strncmp .
Software Zen: delete this;
|
|
|
|
|
|
If you read the rest of #2, you'll see I tell him to read more data out of the file, appending to the original chunk. That covers the case where you haven't read enough of the data to include an entire marker.
Software Zen: delete this;
|
|
|
|
|
See here.
In summary:
CFile file;
char *pBuffer = new char[file.GetLength() + 1];
file.Read(sBuffer);
sBuffer[file.GetLength()] = '\0';
file.Close();
CString str(sBuffer);
int nIndex1 = str.Find(">>");
int nIndex2 = str.Find("<<", nIndex1 + 2);
CString strData = str.Mid(nIndex1 + 2, nIndex2 - nIndex1 - 2);
or
int nNumber = atoi(str.Mid(nIndex1 + 2)); This can also be done without using CString .
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
I never did properly read this chapter. With a lot of functions you are able to pass more than one paramater in the form of a xor. For example when setting a window style: WS_CHILD | WS_BORDER
If I was to make a function for which I could pass the same form of argument, how do you break them apart again?
I would like to make a function which can enable/disable more than one toolbar at a time. ie.
enable_button(ID_BUTTON1 | ID_BUTTON2);
within the function I would check the button id and send the approprate button a message.
SendMessage(hToolBar,TB_ENABLEBUTTON,ID_BUTTON?,FALSE);
So how do I find out which button id's were passed?
|
|
|
|
|
They are using bitwise OR to combine flags. A 32-bit integer would have 32 bits to tell them apart. You would assign values to the flags in powers of 2.
#define ID_BUTTON1 0x0001
#define ID_BUTTON2 0x0002 // ( 1 << 1 )
#define ID_BUTTON3 0x0004 // ( 1 << 2 )
#define ID_BUTTON4 0x0008 // ( 1 << 3 )
As you can see, there is a limited number of flags you can have (32 in this case).
To tell them apart you would do something like this
bool bButton1 = ((nFlags & ID_BUTTON1) == ID_BUTTON1);
|
|
|
|
|