|
The only problem seems to be the CreatePrinterDC call. I copied that code from a procedure and moded it to use a CPrintDialog object to get the DC without checking it.
The MSDN says that you could get a HDC like this:
CPrintDialog dlg(FALSE) ;
HDC hdc = dlg.CreatePrinterDC() ;
The CDC created earlier in the procedure will be used to wrap the HDC returned from CreatePrinterDC() on the line dc.Attach(hdc), so you can use a standard CDC object when printing as expected by OnPrint() etc
Roger Allen
Sonork 100.10016
If I had a quote, it would be a very good one.
|
|
|
|
|
plz check my new post for a continuation of this, thanks for yer help
-dz
|
|
|
|
|
Hi,
Could anyone tell me how to add a macro to active document in MFC?
thanks
Muddu
|
|
|
|
|
Could someone please tell me how one adds methods and properties(not functions and variables) in Visual C++7.0? In 6.0, we use to select the Automation tab in the Class Wizard and add methods and properties. It would also update the odl for us. What is the equivalent procedure or trick in 7.0?
Kind regards,
Tim
|
|
|
|
|
I discovered the answer to my own question and I'll answer it here in case someone else needs to do the same thing. I was expecting to add properties and methods by selecting the class in the ClassView and right clicking for the popup menu, but you can only add class member variables and functions. To add methods and properties to any interfaces in your classes, you need to find and select the application's type library listed in the ClassView. It is represented by a gray rectangle with rounded corners with a node extruding from the left side. If you expand the library, you will see a list of interfaces that exist in your project. Select the appropriate interface, right click, and add your methods and properties.
I hope this helps someone else.
Kind regards,
Tim
|
|
|
|
|
Hi,
I'm very surpised when I realized that std::string copy-costructor doesn´t create a new instance, just point to the older one
Try this code please.
You will get a memory fault error (VC6) when printing the copied string because destructor of first one has been called before
[code]
class CHexString {
private:
string m_byteStr;
public:
CHexString(const CHexString& hs) : m_byteStr(hs.m_byteStr) {}
CHexString(const char * hs) : m_byteStr(hs) {}
CHexString() {}
~CHexString( void ) { std::cout << "destroying " << m_byteStr << std::endl; }
const string getStr( void ) { return m_byteStr; }
friend std::ostream& operator<<(std::ostream os, const CHexString& hs) {
return os << hs.m_byteStr;
}
};
int main ( void ) {
CHexString hs0("JONNY");
CHexString hs1(hs0);
string hs2(hs1.getStr());
std::cout << "hs0 " << hs0 << " hs2 " << hs2 << std::endl;
//same error printing hs1 instead of hs2
return 1;
}
[/code]
Is this the normal behaviour to expect to?
Regards
Carlos.
|
|
|
|
|
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!
|
|
|
|