|
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);
|
|
|
|
|
|
Hello,
I'm looking for a way to capture the sound from the microphone in real time, modify it by applying an effect and output it back to the microphone stream so that other applications which might be recording from the microphone would receive the modified audio. Does anyone have any ideas on how to approach this task?
Thanks.
|
|
|
|
|
As far as I know the microphone is not a shared resource in Windows. That means that an application that needs to use the microphone input would have to get exclusive ownership of that resource. That being said, in the user mode, only one application may have access to the microphone at a time. Also I don't think that user mode applications are given permission to modify the input buffer (the memory arrea allocated to store data from the microphone input).
To cut to the chace, my opinion is that for the type of functionality you seek, you need to write a Kernel Mode application (a virtual driver) that hooks into the sound driver and intercepts writes to the input buffer and applies whatever effects you need to apply, then let the user mode applications "get" their chance at the mic input buffer.
www.muzikstor.com
|
|
|
|
|
Thanks for pointing me in the right direction. I'll read some articles on driver development now (I found many great ones on this web-site) because I've never developed drivers before.
|
|
|
|
|
I have decided to change much of my code from C string (char *) to the C++ style string. So far I have noticed that they are pretty easy to use, and much faster when it comes to searching for sub strings, converting string (BSTR to string).
Now a lot of functions in C++ expect C style strings, this is no problem when using c_str(), but what about those functions that would fill a string? c_str() returns a const pointer, this cannot be changed. For example
SendMessage(hwnd,WM_GETTEXT,0,buffer);
normally the buffer would be filled with the text, how do you make this work with the string class?
|
|
|
|
|
I'm not sure if there is any portable way of doing this. The reason is that all of the strings characters need not actually be sequentially stored in all implementations. For example an implementation may use a deque like structure to avoid having to copy the entire contents of the string across to a new buffer when the string length exceeds its capacity. I think you'll have to read into a normal char array then assign to a string.
Steve
|
|
|
|
|
I figured as much, its a shame, these basic_strings are very adaptable, you can do just about anything with them except send them to a frequently used function.
Thanks for the reply anyway
|
|
|
|