|
Hi All
How can i copy folder?I have a folde A whic have 9 file and 4 folder.And detination folder is B.I want to copy folder A in B.Plz help me
|
|
|
|
|
I haven't tried it myself, but I'm sure SHFileOperation will do this for you.
«_Superman_»
|
|
|
|
|
|
Davitor wrote: can you give example?
Since he's given you the name of the function to use, why not just search for an example?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
|
Try this code
bool CMainFrame::CopyFun(LPCTSTR lpctszSrc_i,LPCTSTR lpctszDetn_i)
{
int nSrcLen = _tcslen(lpctszSrc_i);
int nDetnLen = _tcslen(lpctszDetn_i);
TCHAR *pszFrom = new TCHAR[nSrcLen];
TCHAR *pszTo = new TCHAR[nDetnLen];
_tcscpy(pszFrom, lpctszSrc_i);
_tcscpy(pszTo, lpctszDetn_i);
pszFrom[nSrcLen] = 0;
pszFrom[nSrcLen+1] = 0;
pszTo[nDetnLen] = 0;
pszTo[nDetnLen+1] = 0;
SHFILEOPSTRUCT stFileop;
if("Copy" == m_csType )
{
stFileop.wFunc = FO_COPY;
}
else
{
stFileop.wFunc = FO_MOVE;
}
stFileop.pFrom = pszFrom;
stFileop.pTo = pszTo;
stFileop.fAnyOperationsAborted = FALSE;
stFileop.lpszProgressTitle = NULL;
stFileop.hNameMappings = NULL;
int ret = SHFileOperation(&stFileop);
return(ret == 0);
}
Here lpctszSrc_i & lpctszDetn_i are the src & detn full path.
|
|
|
|
|
I'm having a problem with getting a template class's code split into a header and source file. The following three files below simply refuse to compile, error (using Eclipse Ganymede on Kubuntu Hardy Heron) below.
W.r.t. the 3 files below, when I include the GenArray.cpp 's code INTO the GenArray.h file or include both GenArray.h and .cpp 's contents into the TestDemo, it works
just fine! Any help on how to use this header file correctly would be greatly appreciated !
gvanto
[CODE]
Compiler output:
make all
Building file: ../src/GenArray.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/GenArray.d" -MT"src/GenArray.d" -o"src/GenArray.o" "../src/GenArray.cpp"
Finished building: ../src/GenArray.cpp
Building file: ../src/TestDemo.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/TestDemo.d" -MT"src/TestDemo.d" -o"src/TestDemo.o" "../src/TestDemo.cpp"
Finished building: ../src/TestDemo.cpp
Building target: STLTest
Invoking: GCC C++ Linker
g++ -o"STLTest" ./src/GenArray.o ./src/TemplateClassDemo.o ./src/TemplateFunctionDemo.o ./src/TestDemo.o ./src/VirtualClassDemo.o ./src/rectangle.o
./src/TestDemo.o: In function `main':
/home/pacific/workspace/STLTest/Debug/../src/TestDemo.cpp:21: undefined reference to `GenArray<int, 10>::operator[](int)'
/home/pacific/workspace/STLTest/Debug/../src/TestDemo.cpp:22: undefined reference to `GenArray<int, 10>::operator[](int)'
/home/pacific/workspace/STLTest/Debug/../src/TestDemo.cpp:25: undefined reference to `GenArray<double, 15>::operator[](int)'
/home/pacific/workspace/STLTest/Debug/../src/TestDemo.cpp:26: undefined reference to `GenArray<double, 15>::operator[](int)'
collect2: ld returned 1 exit status
[/CODE]
[CODE]
/*
* TestDemo.cpp
*
* Created on: 1/02/2009
* Author: pacific
*/
#include <iostream>
#include <cstdlib>
#include "GenArray.h"
using namespace std;
int main() {
GenArray<int, 10> intob; //int array of size 10
GenArray<double, 15> doubleob; //double array of size 15
int i;
cout << "Integer array: ";
for(i=0; i<10; i++) intob[i] = i;
for(i=0; i<10; i++) cout << intob[i] << " ";
cout << '\n';
cout << "Double array: ";
for(i=0; i<15; i++) doubleob[i] = (double) i/3;
for(i=0; i<15; i++) cout << doubleob[i] << " ";
return 0;
}
[/CODE]
[CODE]
/*
* GenArray.h
*
* Created on: 1/02/2009
* Author: pacific
*/
//A Generic Safe-Array
#include <iostream>
#include <cstdlib>
using namespace std;
template <class AType, int size> class GenArray {
AType a[size]; //length of array is passed in size
public:
GenArray() {
register int i;
for(i = 0; i < size;i++) {
a[i] = i;
}
}
AType &operator[](int i);
};
[/CODE]
[CODE]
/**
* Source for GenArray.h
*/
#include "GenArray.h" //this already includes iostream and stuff
//Provide range-checking for GenArray
template <class AType, int size> AType &GenArray<AType, size>::operator[] (int i) {
if(i<0 || i> size-1) {
cout << "\nIndex value of ";
cout << i << " is out-of-bounds.\n";
exit(1);
}
return a[i];
}
[/CODE]
Get A job in Australia now, Free!
http://www.webcv.com.au
|
|
|
|
|
When template classes are instantiated, a new class is created at compile time.
For example, GenArray<int, 10> intob; will create a new class.
Internally this class will have some mangled name (maybe .?AV?$GenArray@H$09@@ )
And GenArray<double, 15> doubleob; will create another class (maybe .?AV?$GenArray@N$0P@@@ )
So now you have 2 different classes.
In order to create a new class, the compiler needs the full information about the template class.
Since these classes are created when compiling the main function in the file TestDemo.cpp, the whole template information is necessary in the TestDemo.cpp file.
So you either put the whole template class in the GenArray.h file or include both GenArray.h and GenArray.cpp in TestDemo.cpp.
You will notice that template libraries like STL, ATL etc. have only .h files with all template class information in the header file iteself.
«_Superman_»
|
|
|
|
|
Hi Superman,
Wow thanks a million for a great response! This makes sense ...
I guess I've just been taught never to use executable code in a header file (purely for prototype purposes)
but I guess template classes are the exception eh?!
Thanks again!
Gvanto
|
|
|
|
|
Hi,
i work in c++ using Visual Studio 2005.
I'd like to know if the assignment operation to int (like int i; i=5; ) is atomic. If yes, can you show me proof for that?
It is the same in x64 OS?
|
|
|
|
|
it can be, but i doesn't have to.
if you want to be sure use the volatile keyword.
[code]
volatile int test;
int main(int argc, const char *argv[])
{
test = 5; // this is atomic!
}
[/code]
Don't try it, just do it!
|
|
|
|
|
Why the volatile keyword make it atomic?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Definitely not.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Not true.
All volatile does is to tell the compiler to write the value back to memory when it's changed AND that something else may change the variable. Without volatile, under some circumstance it could optimize it a register and only write and/or fetch it periodically.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Dudi Avramov wrote: I'd like to know if the assignment operation to int (like int i; i=5; ) is atomic.
No, absolutely not. There is much more to atomic operations.
1.)The LOCK[^] prefix must be present to instruct the processor that it has exclusive memory access to the variable location.
2.) Modern processors perform speculative fetching and instruction reordering so the code being executed should be serialized before the atomic operaration with SFENCE[^]/LFENCE[^]/MFENCE[^] The volatile keyword[^] should give the compiler a hint that it needs to prevent out-of-order execution which may result in a Memory Barrier[^].
Interlocked Variable Access[^]
Synchronization and Multiprocessor Issues[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Is it possible that the mov assembly instruction is not atomic?
|
|
|
|
|
It is possible that it's not atomic - if the processor doesn't have the bus locked while performing the MOV, some other bus attached hardware (like, for example, the other core of the processor, or some hardware performing a DMA) could theoretically write to that memory location if it has precedence over the current processor.
|
|
|
|
|
can u plz advice me how i can decode pdf format and add it into device..that it gonna used as firmware... it is a prestigious matter for me because i was insulted bitterly in a electronics forum for this question of making a pdf reader device.. so it became a challenge to make it possible.. can u just help me to establish my dream??
Every man is unique
|
|
|
|
|
Do you want to make a device able to understand the PDF format?
Have a look to this article [^], with in turn will shortly redirect you to the PDF specifications.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
i am so greatful to u, thanks thanks....if u have any other idea or article known plz let me know..
Every man is unique
|
|
|
|
|
I enumerate all open windows with Enumwindows. In the processor function I try to check if the title of the window contains a certain string. If yes, put the handle in a list of handles(m_wndList).
if(hwnd)
{
CWindow win(hwnd);
CHAR str[100];
win.GetWindowText((LPTSTR)(str),100);
if (strncmp(str,"searchstring", 13) == 0)
dlg->m_wndList.push_back(hwnd);
}
It compiles, but I get the following error messages:
Run-time Check Failure #2: Stack around the variable str is corrupted
and/or
Run-time Check Failure #2: Stack around the variable win is corrupted
What is the problem? How should I change my code?
|
|
|
|
|
There's some problems with your code. What's with the (LPTSTR) nonsense? My guess is that you're building a Unicode application and casting away the compiler warnings (the (LPTSTR) cast I mentioned before) which were informing you of the real problem: that CHAR str[100]; is not a Unicode string. Try this:
if(hwnd)
{
CWindow win(hwnd);
TCHAR str[100];
win.GetWindowText(str, 100);
if (_tcsncmp(str, _T("searchstring"), 13) == 0)
dlg->m_wndList.push_back(hwnd);
}
Don't cast unless you're sure what the cast actually means, and don't try to cast away error messages.
Steve
|
|
|
|
|
To complement the answer from Stephen, I suggest you read this excellent article[^]. You'll be able to really understand why your code is wrong.
|
|
|
|
|
Thanks guys, you both helped me a lot. At the moment I just cut & paste any code I find, but this will change I hope.
|
|
|
|
|
keret wrote: if (strncmp(str,"searchstring", 13) == 0)
Why 13?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|