|
No, this is definitely not normal behavior. I don't have any compiler at hand, but you might be so kind as to give this a try. Delete the const in getStr , as this:
string getStr( void ) { return m_byteStr; } Does the error persist?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Interesting you should ask this question as I was just having problems with std::string today (see my post below). I think your problem may have to do with the fact that MS's implementation of string uses reference counting. You might want to have a look here -- scroll down to the "Xstring" section. It details how reference counting can be disabled, which may be more expensive but worth the cost IMHO.
In any case, the bug fixes listed on that page should be useful to you if you are using MS's version of the STL.
--DG
|
|
|
|
|
Hello,
Check this answer posted in codeguru forums by John Barton (thanks John)
[quote]
It is normal behaviour for a string class to not copy the data but instead to do reference counting (unless the strings are different, there is no need to have multiple copies of the data).
The problem with your program is that you declared the operator<< incorrectly.
You should have made the first argument a reference:
friend std::ostream& operator<<(std::ostream& os, const CHexString& hs)
You were having a problem because when you called operator<< without the first argument being a reference, it made a local copy of the stream, and then returned a reference to the local copy (which was destroyed when the function exited).
Best regards,
John
|
|
|
|
|
CFileDialog dlg(TRUE, NULL, lastPath, OFN_ALLOWMULTISELECT,
_T("Text file (.txt)|*.txt|")
_T("All files (*.*) |*.*|")
);
...
if (dlg.DoModal() != IDOK)
DoSomething();
...
The above code works fine in the debug version, but curiosly enough, the dialog box hangs in the release version when a file is selected and the 'Open' button is pressed. Any ideas?
------------------------
Secondly, I have a set up like the following:
CClass1 {
...
vector<cclass2> data;
...
}
CClass2 {
//member funcs
private:
std::string str;
int x;
... (member variables)
}
CClass1* obj;
...
delete obj; //crash here
In my code I have a pointer to a CClass1 object (which I know is valid) that I am trying to deallocate. The program crashes when I call delete.
After much time spent, I know the problem arises when the last object in the data vector is deleted. I've tried using the default destructor to take care of deallocating the vector, I've tried calling data.resize(0);, data.clear();, and while (data.size()) data.pop_back(); -- all with the same result. Deleting the last object in the vector causes an assertion in dbgheap.c Expression:_CrtIsValidHeapPointer(pUserData)
More specifically, the assertion always occurs when the str member of CClass2 is being deallocated. Note that this is not a pointer to a string being deleted - it is a string object. Thus there should not be an issue with deleting the same string twice.
I thought maybe I had done something stupid and corrupted the heap along the way, but I've been looking over my code for a long time now and I'm fairly certain there are no double deletes, dangling pointers, etc. I know the above might not be very clear, but any insight would be appreciated.
Thanks,
DG
|
|
|
|
|
1. with multi-select, you have to provide a buffer big enough to store all the filenames.
2. hard to tell. try reposting with your code in PRE, /PRE brackets, or turn off the HTML stuff - looks like you lost some formatting.
-c
Cheap oil. It's worth it!
|
|
|
|
|
Tried the change you suggested for multi-select -- I removed it completely. The result is still the same. The dialog box still hangs with only one file selected.
As for the other code:
CClass1 {
...
vector data;
...
}
<BR>
CClass2 {
private:
std::string str;
int x;
... (member variables)
}
<BR>
CClass1* obj;
...
delete obj;
It's just code stubs, but hopefully that will look better for you. The main issue is just that it always fails when the str member is being deallocated. When unwinding the stack the last calls before the crash are:
1. The string destructor
2. basic_string::_Tidy()
3. std::allocator::deallocate
4. operator delete (void*)
(note that those are cleaned up names since everything is templatized...)
--DG
|
|
|
|
|
As for the first question, the strings must end with "||".
As for the second question, could you please repost checking the option "Display this message as-is (no HTML)" right below the edit area? That will bring the missing portions of the code into the light. Thank you.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi - does anyone know how to get the body type (RTF, HTML, TXT, etc.) of an message using Extended MAPI like you can in OOM? Also is there a way to duplicate the SavsAS in OOM with MAPI?
Thanks - BN
|
|
|
|
|
Hey...
I'm trying to make a simple little program that takes a string, searches for that string in a different string, and once that string is found, replace it with a different string. I want it to do this to the end of the string.
I'm kinda stuck right now, cause I don't know how to use the CString::Insert() and Find() functions right. I had a function that Replace()'d everything, but the problem was that I was trying to replace "\r\n" with "<br>\r\n", so it kept looping around and inserting till I had something that looked like: "Hello World<br><br><br><br><br><br><br><br><br><br>\r\n".
Also, in the replace function I'm using it uses lstrlen() functions, and I'm not *exactly* sure what those do.
If someone could point me to an article where it talks about things like this, or gave me some advice in a reply, I'd be very thankful.
Thanks, Emearg
The function I'm using:
CString CMFC2Dlg::Replace(LPCTSTR instr, LPCTSTR oldstr, LPCTSTR newstr)
{
CString output(instr);
CString input_lower(instr);
CString oldone_lower(oldstr);
input_lower.MakeLower();
oldone_lower.MakeLower();
int pos=0;
while ( (pos=input_lower.Find(oldone_lower,pos))!=-1 )
{
input_lower.Delete( pos, lstrlen(oldstr) );
input_lower.Insert( pos, newstr );
output.Delete( pos, lstrlen(oldstr) );
output.Insert( pos, newstr );
}
return output;
}
Called by:
LogConvert = Replace(LogString, "\r\n", "<br>\r\n");
|
|
|
|
|
|
Since you make a call to Insert when you replace the the search string with newstr you need to move pos past the newly inserted string. So, try this:
while ( (pos=input_lower.Find(oldone_lower,pos))!=-1 )
{
input_lower.Delete( pos, lstrlen(oldstr) );
input_lower.Insert( pos, newstr );
output.Delete( pos, lstrlen(oldstr) );
output.Insert( pos, newstr );
pos += lstrlen(newstr)
}
lstrlen returns the length of the argument you pass it (i.e. the number of characters contained in the string.
--DG
|
|
|
|
|
Awesome that worked. Thanks alot
|
|
|
|
|
I'm making an app where i need to search thru all the files in a folder, and also all the files in it's subfolder and it's subfolder's subfolders etc. I'm having some problems developing an algorithm for this. can anyone shoot me in the right direction? I don't need a complete set of code, just some advice on how to handle it. I know how to add all the files from a folder when i have the ITEMIDLIST of it.
Thanks
|
|
|
|
|
try looking in the Files and Folders section of this site. there are probably half a dozen classes that will do this (including mine).
-c
Cheap oil. It's worth it!
|
|
|
|
|
Well, the thing is that i want to make my own code, but i'm having some problems on how to do it so i just need a little advice...
Thanks
|
|
|
|
|
func FindDirs(array DirArray string curDir)
file = FindFirstFile(curDir)
if (file is dir)
add file to DirArray
FindDirs(DirArray, file)
end if
file = FindNextFile(curDir)
while (file is ok)
if (file is dir)
add file to DirArray
FindDirs(DirArray, file)
end if
file = FindNextFile(curDir)
end while
-c
<hr><font size=-2 color="#000060">
Cheap oil. It's worth it!
</font><div align=right><font size=-2 color="#000060"><a href="http://www.smalleranimals.com/iseffects/isesamples.htm">ISEffects - effects for images</a></font></div>
|
|
|
|
|
redeemer wrote:
Well, the thing is that i want to make my own code, but i'm having some problems on how to do it so i just need a little advice...
You have to write recursive function.
Mazy
"The more I search, the more my need
For you,
The more I bless, the more I bleed
For you."The Outlaw Torn-Metallica
|
|
|
|
|
redeemer wrote:
... I don't need a complete set of code ...
but here it is (I hope it works). You will get files from folder 'pstr' in 'files' array.
void RecurseAdd(CStringArray & files,LPCTSTR pstr)
{
CFileFind finder;
files.RemoveAll();
// build a string with wildcards
CString strWildcard(pstr);
strWildcard += _T("\\*.*");
// start working for files
BOOL bWorking = finder.FindFile(strWildcard);
while (bWorking) {
bWorking = finder.FindNextFile();
// skip '.' and '..' files
if (finder.IsDots())
continue;
// if it's a directory, recursively search it
if (finder.IsDirectory()) {
RecurseAdd(files,finder.GetFilePath());
} else {
files.Add(finder.GetFilePath());
}
}
finder.Close();
}
|
|
|
|
|
If i have a function, that with the id of a folder, it goes through all of the elements of the folder, if it is a file it adds it to a list, and if it is a folder it calls itself. wouldn't that work?
BTW, thanks all!
|
|
|
|
|
How do I get an enumeration of all the audiocodex available using the AVIFile API?
This works for video codex but returns no codex for audio.
ICInfo(ICTYPE_AUDIO,count,compressorInfo)
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
Is there anyway to set the text color for inidividual ListView subitem? You can change the text color of the whole listview using SetTextColor method of listview, but it seems that it sets the whole list...is there anyway to set the color for individual items?
thanks
|
|
|
|
|
|
I'm writing an MFC VS 6.0 program that passes text variables to BRIO a reporting tool.
I know how to return a variable with a C++ program but how do you call an external program in MFC??
MSDN is as much help as it usually is.
Thanks
|
|
|
|
|
CreateProcess is the best way
-c
Cheap oil. It's worth it!
|
|
|
|
|
I am working on a C++ app to populate acrobat fields. I have figured it out in VB and that code could be posted if needed. What I need is how to use the AForm32.api plug-in in C++. Are there headers? Is there a way to #import. I have played with #import but don't seem to have exposure to the objects. Thanks for any guidance.
Bill
|
|
|
|