|
cedric, my program is too complex.. even i'm worn out looking at the code..
can u post a simple program which wil explain it clearly?
should i declare the thread inside the class? just like we do for member functions?
i.e
class test
{
public
UINT Thread(LPVOID lp);
}
??
do we have any alternative for CWinThread?
vivek
|
|
|
|
|
|
bob,david,cedric,michael, and paul........
paul the link u gave is ultimate.. thank u so much. really resourceful.i think i wont be disturbing u guys again.. everything's there
The Thread Solution
It is almost always the case that you can use threads to do the job more easily. This is not without certain costs and hazards, but it ultimately is the better method.
Here's a solution to handling the invert-everything. Note that we have to move from the pure-C domain (which we interface to via a static method) to the MFC domain.
To the class (in this example, a CView-derived class), add the following declarations:
static UINT run(LPVOID p);
void run();
volatile BOOL running;
To start a thread, your handler does
void CMyView::doInvert()
{
running = TRUE;
AfxBeginThread(run, this);
}
UINT CMyView::run(LPVOID p)
{
CMyView * me = (CMyView *)p;
me->run();
return 0;
}
void CMyView::run()
{
for(int x=y = 0; running && y < image.height; y++)
for(int x = 0; running && x < image.width; x++)
changePixel(x, y);
running = FALSE;
}
The command to stop the thread is very simple:
void CMyView::OnStop()
{
running = FALSE;
}
That's all there is to it!
vivek
|
|
|
|
|
|
|
My situation is where I have a java application which is using the heap memory (we tuned by Xms and Xmx settings). Even the memory is cleared by System.gc()the memory is not freed and is not retured back to OS. We are able to see the heap increasing as we run our application.
To free that memory what sort of approch i can do using C++ /VC++/VB. Can any one helpe in writting a program to do the same
|
|
|
|
|
Jreko2003 wrote:
We are able to see the heap increasing as we run our application.
What are you using to verify this? If it's Task Manager, see here.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Jreko2003 wrote:
My situation is where I have a java application which is using the heap memory (we tuned by Xms and Xmx settings). Even the memory is cleared by System.gc()the memory is not freed and is not retured back to OS.
Memory is never returned back to OS. You can only re-use freed memory within the program.
|
|
|
|
|
we know we can access a file(dload, create, delete...) on a ftpsite
by some software, but i try to write a program with error for filename:...
The Codes i wrote can not found file "My Projectinfo.inf", Why?
Are there some way to access file has filname have space?
My_Fun()
{
...
pFtpConn = mysession.GetFtpConnection( my_ftpserver, my_user, my_pass );
CFtpFileFind finder(pFtpConn);
BOOL bWorking = finder.FindFile("/My Projectinfo.inf" );
...
}
Thanks!!!
|
|
|
|
|
lewislewis_lewis wrote:
BOOL bWorking = finder.FindFile("/My Projectinfo.inf" );
If FindFile() returns FALSE , what does GetLastError() return?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
if( !bWorking )
{
DWORD errcode = GetLastError();
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
errcode, //GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
LocalFree( lpMsgBuf );
}
the MessageBox dispaly :"There are no more files"
What is wrong?
|
|
|
|
|
Does your code work for files with no spaces in the name?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
YES, I tested it maney times.
|
|
|
|
|
Did you remember to call FindNextFile() before using any of the other CFtpFileFind methods? What does the following produce:
BOOL bWorking = finder.FindFile("*.*");
while (bWorking)
{
bWorking = finder.FindNextFile();
TRACE("]%s[\n", (LPCTSTR) finder.GetFileURL());
} Does it show the name of the file with spaces in its name?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
If I get FileURL, Every thing is OK, But I can not manipulate the file
with space filename.
|
|
|
|
|
Define "manipulate." Has the original problem been fixed, and now you have encountered another?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
My_Fun()
{
...
pFtpConn = mysession.GetFtpConnection( my_ftpserver, my_user, my_pass );
CFtpFileFind finder(pFtpConn);
BOOL bWorking = finder.FindFile("/*.*" );
while( bWorking )
{
bWorking = finder.FindNextFile();
sURL = finder.GetFileURL();
pFtpConn->GetFile( sURL, "C:\Dloadfile.inf" );
}
...
}
Nothing donwload!!!
|
|
|
|
|
lewislewis_lewis wrote:
pFtpConn->GetFile( sURL, "C:\Dloadfile.inf" );
You need to use two backslashes.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
My_Fun()
{
...
pFtpConn = mysession.GetFtpConnection( my_ftpserver, my_user, my_pass );
CFtpFileFind finder(pFtpConn);
BOOL bWorking = finder.FindFile("/*.*" );
while( bWorking )
{
bWorking = finder.FindNextFile();
sURL = finder.GetFileURL();
pFtpConn->GetFile( sURL, "C:/Dloadfile.inf" );
}
...
}
No work. I think GetFileURL return URL only, can not use as file name.
For file name, only work for normal file name. Why?
How to manipulate a file with filename have space?
|
|
|
|
|
lewislewis_lewis wrote:
sURL = finder.GetFileURL();
pFtpConn->GetFile( sURL, "C:/Dloadfile.inf" );
Is sURL non-empty? What does GetFile() return?
Have you tried to retrieve the file using command line FTP (to isolate if the problem is in your code or in the FTP process)?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
the sURL = "ftp://ftp.ftpserver.com/Dloadfile.inf"
|
|
|
|
|
lewislewis_lewis wrote:
the sURL = "ftp://ftp.ftpserver.com/Dloadfile.inf"
There are no spaces in the name.
Have you tried the command-line FTP?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
the sURL = "ftp://ftp.ftpserver.com/My Projectinfo.inf"
When I use MS explorer, in adreess box, I type in: ftp://ftp.ftpserver.com, I can see all files, and use copy-paste will download any files!
|
|
|
|
|
Ok, what does GetFile() return? If it's FALSE , what about GetLastError() .
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Error code is 12003, but string is empty
|
|
|
|