|
Gofur Halmurat wrote: Does anyone know how to get files list in a directory in c++?
Technically, C++ has no such functionality. You can, however, use FindFirstFile() and FindNextFile() .
"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
|
|
|
|
|
////////////Use of FindFirstFile/FindnextFile
WIN32_FIND_DATA win32;
BOOL Bool=1;
HANDLE handle;
handle=FindFirstFile(_T("*.*"),&win32);
if(handle!=INVALID_HANDLE_VALUE)
while(Bool!=0)
{
m_List.AddString(win32.cFileName);
Bool=FindNextFile(handle,&win32);
}
FindClose(handle);
/////////////use of DlgDirList for replace contents of ListBox with directorys
TCHAR lpt[260];
lpt[0]='\0';
DlgDirList(lpt,IDC_LIST1,NULL,DDL_DIRECTORY|DDL_ARCHIVE);
|
|
|
|
|
Hamid. wrote: BOOL Bool=1;
while(Bool!=0)
why don't you just write this:
BOOL isFileFound = TRUE;
while (!isFileFound) ??
in a general mean, prefer naming your variables with a representative name of what they are used for ?
|
|
|
|
|
I think this code is better:
WIN32_FIND_DATA win32;
HANDLE handle;
handle=FindFirstFile(_T("*.*"),&win32);
if(handle!=INVALID_HANDLE_VALUE)
do
{
m_List.AddString(win32.cFileName);
}while(FindNextFile(handle,&win32)!=0);
FindClose(handle);
and we dont need to any boolean variable.;)
|
|
|
|
|
Just looking for fancy C++ sockets library -- client side:
Must:
* Support SSL connections
* Support AES 128
Should:
* Use I/O Completion
* not create hidden windows
I already use the AsyncSocket classes -- but find I need a bit more than it offers.
Commercial Software OK -- can pay.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A> *
|
|
|
|
|
ACE is pretty nice, it's quite comprehensive. Docs are so-so (or used to be - I haven't used it in a while).
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
VCF Blog
|
|
|
|
|
Hello all.
I have a class Item and a typedef std::vector<Item> Items; . Both reside within a DLL. Then, from my exe, I do something like:
void FillList(Items& items)
{
}
bool Foo()
{
Items items;
FillList(items);
return true;
}
when ending Foo , the compiler (VC8) is throwing an assert. After a close research I found out that the problem is de std::vector 's destructor. Furthermore, the problem is when the destructor of the allocator deallocates my memory. Don't know why is this going on, I'd really appreciate any clue on this.
For more information, the Item class doesn't do any weird or exotic operations, it just has some members with the getters and setters. It has a default constructor and a copy constructor, as well as an overloaded assignment operator.
Thanks in advance.
-- modified at 1:16 Sunday 11th November, 2007
Solved
Well, it's solved now. As Nemanja suggested and gleat greatly explained, this was due because I was linking statically to the CRT. Didn't realized, my DLL projects already linked dynamically to the CRT, it was just the WTL app that didn't.
While I had this problem I made some research and it seems it's happening over many places (MySQL and Qt libraries, just to mention two). Hope this thread will be indexed soon in google and may it be able to help other fellows.
Thanks given to Mark, Gleat, Nemanja and David. You saved my life (literally as I was thinking on re-doing all this stuff in C# --don't tell anybody ).
Hope is the negation of reality - Raistlin Majere
|
|
|
|
|
Why is a destructor being called where you indicated?
Is there an object at the wrong scope?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Well, the scope of items is the Foo function, it is destroyed after the function finalizes.
Hope is the negation of reality - Raistlin Majere
|
|
|
|
|
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
|
|
|
|