|
Is there something in Items (like a pointer) that gets shallow copied then
deleted twice?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Nope. It is something like:
class __declspec(dllexport) Items
{
public:
Items();
Items(const Items& items);
virtual ~Items();
int GetId() const;
void SetId(int id);
private:
int _id;
};
typedef std::vector<Item> Items;
Mmm... well, the only thing is that I use ATL::CString. And many Item-derived classes uses AT::CString members. Could that be?
Thanks.
Hope is the negation of reality - Raistlin Majere
|
|
|
|
|
Yes, that could be the problem. STL and DLLs aren't really the best of friends! You need to be careful about the CRT you use. The problem has to do with the Win32 heap that's used by the CRT that you link to from the DLL and EXE. Whenever we use the the C++ new and delete operators, ultimately, they just translate into calls to HeapAlloc and HeapFree both of which require a handle to the heap. The CRT creates and maintains this handle as a global variable some place. If the DLL and the EXE are using different CRTs and you new up some memory from the former and try to delete it from the latter or vice versa, then the Heap * APIs respond with a big fat undefined behavior i.e., if you did this for instance:
- Allocate a
char buffer from the EXE using new
- Pass a pointer to that buffer to a DLL routine
- Delete the memory from the DLL routine via
delete
you would typically see what your seeing. This happens because we are allocating memory from one heap and freeing it from another!
In your case I guess the CString objects new up some memory from the Item class's constructor from the EXE which then gets deleted from the virtual destructor defined in the DLL. As Nemanja Trifunovic has pointed out, you might want to dynamically link to the multi-threaded CRT from both the DLL and the EXE. That might solve the problem. A nasty kind of issue to run into though!
|
|
|
|
|
I see. Yes, indeed CString allocates and de-allocates by using new . So does CSimpleArray and std::vector .
I did some research and I found several questions regarding this issue, at least with some MySQL and Qt libraries. This particular assert seems to be a feature that was introduced with VC8: the compiler uses an internal (virtual perhaps?) heap in order to locate possible flaws of one application. That's why it only happens when launching the app from within VC, whereas it runs with no problemo if launched outside VC.
In five years this is the first time that it happens to me. I feel like a rookie . Anyway, it's solved now. Thanks for your help and the explanation.
Hope is the negation of reality - Raistlin Majere
|
|
|
|
|
Fernando A. Gomez F. wrote: Both reside within a DLL. Then, from my exe,
Uh, oh! Are you maybe statically linking the CRT?
|
|
|
|
|
Hello,
in the project property pages it says it is linking to the "multi-threaded [debug]" runtime library, yet there is another option which says "multi-threaded [debug] DLL". Is that what you mean, that I should link to the latter one?
Man, I feel like a complete rookie...
-- modified at 1:23 Sunday 11th November, 2007
Solved , thanks a lot.
Hope is the negation of reality - Raistlin Majere
|
|
|
|
|
Fernando A. Gomez F. wrote: when ending Foo, the compiler (VC8) is throwing an assert.
What line of what file is asserting?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello,
template<class _Ty,
class _Alloc> inline
void _Destroy_range(_Ty *_First, _Ty *_Last, _Alloc& _Al)
{
_Destroy_range(_First, _Last, _Al, _Ptr_cat(_First, _Last));
}
The bolded line, which is in the line 226 of the "xmemory" file.
Thanks.
Hope is the negation of reality - Raistlin Majere
|
|
|
|
|
Hi,
I want to connect two combo boxes, it means that when i choose a data from the list of first combo box, the list box or edit box of second combo box change according to first combo box.
my program is on C++ language(MFC).
(i use embedded software)
please help me.
thanks a lot
|
|
|
|
|
Handle ON_CBN_SELCHANGE on the first combo and populate the second combo in the handler.
|
|
|
|
|
Hi,
Thanks a lot for your answer, it works.
|
|
|
|
|
Hello guys!
I`m working with a file from which i read data. I don`t know its encoding (to be honest I`m not sure I know exactly what`s the difference between encodings), all I know it`s a simple .xml another application gets data from.
Its structure is like:
< var> value < /var>
each var on a line
Some vars have filepaths stored in them, like:
< path> filepath < /path>
I read this file line by line and process the data, copying into another .txt file only those filepaths.
I`ve seen that in the .xml I have HTML character sequences for some characters, and by this I mean that all & characters (from the physical path) are replaced with & # x 2 6 ; (without the spaces - the same thing happens in this field where I write this question)
The question is ... is there any simpler solution to translate these sequences into characters rather than write a function that searches for them and replaces them with the right special character (that is, some specification for when I read the file so that my string gets only the character and not all the characters composing the special character)
Specifically: gets only & rather than 6 characters compsosing it: &,#,x,2,6,;
Thanks for your time!
Shpid3r
|
|
|
|
|
Is there any particular reason why you are not using an XML parser to parse the XML file?
|
|
|
|
|
Oh my god,
I agree -- just use a darn XML parser. There's one I found here on codeproject which I think is fantastic -- TElemW[^]
It saves me all kinds o time.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
Thanks for the suggestions!
I have already wrote all the code to parse this xml file myself, except that unicode / multi-byte - ascii. Moreover, the .xml has a very simple structure, with only 4 tags... <start> <file> <files> <path> (and closing versions). So i really don`t need all the parsing logic (well, i didn`t even know that something like this exists)..
End of the line: at this moment integrating that program to suit my needs would be killing. All I need now would be to convert those sequences into their characters. As a last resort, I`d rather use a switch than studying how that thing works... Though in future projects i`ll remember it!
Any other ideas ?
|
|
|
|
|
There is to my knowledge no MFC etc function available to do this. But, hey, you effectively rolled your own parser! That means that you have to write all functions to deal with stuff that XML can throw at it. If you leave something out, you will sooner or later become a cropper. The writing of a function to convert the simple escapes you mentioned appears to me to be a relatively minor issue in the greater scheme of things you are taking on.
regards,
Bram van Kampen
|
|
|
|
|
shpid3r wrote: to be honest I`m not sure I know exactly what`s the difference between encodings
If your going to parse XML from a windows box and attempt to do something with the data, you will need to understand the differences between UTF-8, UTF-16, UCS-2, and code pages if your compiling for MBCS. There is no compromise on this if you want your parser to work and your results to display correctly, without corruption in your Visual C++ program.
Even from my little experience in XML processing, it is obvious based on your post that you are attempting to tackle a non-trivial subject with a trivial approach thats likely to end in frustration. Do yourself a favor and use an already existing and well supported XML parser. You will still likely need to understand encodings anyway, but it will save you a lot of headaches early on.
|
|
|
|
|
ON_COMMAND_RANGE(IDC_RELAY1, IDC_RELAY8, ChangePin)
hi there,
the Above code will call the function ChangePin() when checkbox's in the range IDC_RELAY1 to IDC_RELAY8 are changed, can anybody tell me what kind of message is sent when a user clicks one of the checkbox's?
i am trying to progmaticaly send the "BN_CLICKED" message to trigger the ChangePin function from my code without having to physicaly use the mouse to heck the checkbox.
thanks chris
|
|
|
|
|
try simply checking the checkbox programatically and see.
AFAIK that should automatically call the associated function.
good luck.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
i tried checking the checkbox,by setting its value to TRUE,and then Updating the dialog using UpdateData(false); sure enough the checkbox checked but it failed to call the ChangePin function.
any other idieas?
thanks
chris
|
|
|
|
|
You can always use SetCheck() to change the check state of the
checkbx then call ChangePin direcly, passing the id of the checkbox.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello everyone,
I want to confirm that on a 32-bit machine,
1. compare the value of two byte to see whether they are equal or not;
2. compare the value of two integer (4-byte) to see whether they are equal or not.
(1) and (2) should have the same performance, right? I am using x86 32bit Windows machine to develop native unmanaged C++ application.
thanks in advance,
George
|
|
|
|
|
Depends a bit on allignment,and on the precise processor on the target machine, but the difference should be insignificant for most purposes.
regards
Bram van Kampen
|
|
|
|
|
Hi Bram,
I am interested to learn what do you mean alignment. Could you provide more information please?
regards,
George
|
|
|
|
|
Allignment
I thought this was a quite Basic, Simple and well understood topic, but I must admit, cannot find any articles about it. Must write a short one myself to fill this void. Watch this space, and I get something together soon.
Regards,
Bram van Kampen
|
|
|
|