|
Hi Forum
How can i call function in thread.Situation is application make backup of moveing files/folder.And path is came one by one.So i try to use Thread.But i stop here(threading).Create a thread i use this code
CWinThread *co= new CWinThread();
co->CreateThread();
But How can i pass Copy Funtion in thread.Copy function is Copy(source path,Destination path)
Plz help me
|
|
|
|
|
If the "Copy" function is a global function, then you could call it straight from within your thread. If it is a member function of a class, then construct a class object and pass it to the thread as a parameter when you create your thread.
Also, read up on thread synchronization.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Thanks for reply
Now study more about Thread and do something like this.
void ThreadProc(void *param)
{
Copy(Source,Destination);
}
{
void CTestDlg::PathCame(const CString & FilePath)
{
HANDLE handle;
handle = (HANDLE) _beginthread( ThreadProc,0,0);
WaitForSingleObject(handle,INFINITE);
}
But only one thread run at the time.When fist thread is working and second is come then first thread destroy.
Plz help me
|
|
|
|
|
First things first: If you use things like _beginthread (or even CreateThread) along with MFC, all bets are off.
You must use the MFC functions instead. Like - to begin a thread, use AfxBeginThread()[^].
Have a look at the remarks section of CWinThread[^].
Can you tell me what is that you are looking to build? I don't get it.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Hi,
im using UrlDownload to file....to download a file from server..it worked fine before...but now it"s not working the reason i guess may be we have changed settings in internet options..ie related to ActiveX..but even when i reset the settings it"s not able to download file......(If possible please suggest any other API which cannot be dependent on internet settings...)
URLDownloadToFile(NULL,"http://(servername)/(virtualdirectory name)/(filename) , (path to store downloaded file), 0, NULL)
Please help me regarding the same......
|
|
|
|
|
We use a class that's based on WinInet that does this. See if it helps. I'm going to post the code below.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
class DownloadUrl
{
public:
DownloadUrl(const string& url);
~DownloadUrl();
int Get(void* buffer, int count);
int PercentageRead();
private:
DWORD m_Length;
int m_BytesReadTotal;
typedef auto_ptr<CInternetSession> apCInternetSession;
typedef auto_ptr<CHttpConnection> apCHttpConnection;
typedef auto_ptr<CHttpFile> apCHttpFile;
apCInternetSession m_pInternetSession;
apCHttpConnection m_pServer;
apCHttpFile m_pFile;
};
DownloadUrl::DownloadUrl( const string& url )
{
CString server, object;
DWORD service_type;
INTERNET_PORT internet_port;
AfxParseURL(url.c_str(), service_type, server, object, internet_port);
if (server.IsEmpty() || object.IsEmpty())
throw exception("Could not parse URL");
m_pInternetSession = apCInternetSession(new CInternetSession("Microsoft Internet Explorer 5.0"));
m_pInternetSession->SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, 15000);
m_pInternetSession->SetOption(INTERNET_OPTION_CONNECT_BACKOFF, 1000);
m_pInternetSession->SetOption(INTERNET_OPTION_CONNECT_RETRIES, 2);
m_pInternetSession->EnableStatusCallback(TRUE);
m_pServer = apCHttpConnection(m_pInternetSession->GetHttpConnection(server, internet_port));
if (m_pServer.get() == NULL)
throw exception("HTTP connection failed");
m_pFile = apCHttpFile(m_pServer->OpenRequest("GET", object, NULL));
if (m_pFile.get() == NULL)
throw exception("Request failed");
m_pFile->AddRequestHeaders("Accept: audio/x-aiff, audio/basic, audio/midi, audio/mpeg, audio/wav, image/jpeg, image/gif, image/jpg, image/png, image/mng, image/bmp, text/plain, text/html, text/htm\r\n");
m_pFile->AddRequestHeaders("User-Agent: GetWebFile/1.0\r\n", HTTP_ADDREQ_FLAG_ADD_IF_NEW);
m_pFile->SendRequest();
DWORD dwStatus;
m_pFile->QueryInfoStatusCode(dwStatus);
if (dwStatus != HTTP_STATUS_OK)
throw exception("URL was denied by server");
m_Length = 0;
m_pFile->QueryInfo(HTTP_QUERY_CONTENT_LENGTH, m_Length);
m_BytesReadTotal = 0;
}
DownloadUrl::~DownloadUrl()
{
}
int DownloadUrl::Get( void* buffer, int count )
{
UINT bytes_read = m_pFile->Read(buffer, count);
m_BytesReadTotal += bytes_read;
return bytes_read;
}
int DownloadUrl::PercentageRead()
{
if (!m_Length)
return 0;
double ratio = m_BytesReadTotal;
ratio /= m_Length;
ratio *= 100;
return (int) ratio;
}
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
try {
DownloadUrl download_url("http://example.com/content.html");
static const unsigned buffer_size = 64*1024;
char buffer[buffer_size+1];
ofstream tmpfile("c:\\file.html", ios::out | ios::binary);
while (int bytes_read = download_url.Get(buffer, buffer_size))
{
tmpfile.write(buffer, bytes_read);
}
}
catch (exception& ) {
}
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Thanks for ur support may i know how can use RegistryRegQueryValueExW with sample..as im a newbie and im struggling with this unicode can u suggest me any article on how to use Unicode in my applications.....
|
|
|
|
|
what does RegistryRegQueryValueEx have to do with downloading files?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Ya...this is a different doubt...Please try to calrify...
|
|
|
|
|
???
I don't understand what you're saying.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
The doubt What im going to ask is not related to Filedownload it is related to Registry access ...ie
Please let me know how can iread a value from registry using RegQueryValueExW() with sample.... and please let me know how can i use unicode in my applications ..really im struggling with this unicode....
|
|
|
|
|
You should start a new thread for this question.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
hi all
I am developing a directshow application through mfc .I am getting the error
Error 1 error C2664: 'ATL::CStringT<basetype,stringtraits>::CStringT(const VARIANT &)' : cannot convert parameter 1 from 'WCHAR [128]' to 'const VARIANT &' d:\visual c++ programs\mfc\pplayer\player.cpp 102
in the function
CString GetFilterName(IBaseFilter* pBF)
{
ASSERT(pBF!=NULL);
FILTER_INFO fi;
memset(&fi,0,sizeof(fi));
if(pBF!=NULL)
{
VERIFY(SUCCEEDED(pBF->QueryFilterInfo(&fi)));
}
return fi.achName; //here I am getting the error
}
please help me why i m getting this error
|
|
|
|
|
I'm guessing that you're using ASCII strings. fi.achName is a wide string, so isn't compatible with ASCII strings. When you attempt to pass it back as a CString, the compiler needs to find a constructor that will create an ASCII CString from a wide string. It can't, because there isn't one.
You need to convert the wide-string to a TCHAR string. The easiest way is to #include <atlconv.h> and convert the string like this:
return CW2CT(fi.achName);
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I have unsigned char variable that store hex values for image. but when i wrote it in binary file and save as jpg, the image is invalid. how exactly the way to convert hex to image?
|
|
|
|
|
suggesting some checkpoints.
1. is the hex string including file header part for jpg format?
2. is your code of (HEX string -> BYTE) ok?
3. which writing function do you use? fwrite or fputc etc?
...
|
|
|
|
|
thank you for the reply. here are my answers:
1.i don't know about the value of file header. how do i get it?actually the hex string values i retrieved from database and assign to CString variable.
2.do you mean i have to convert hex string to BYTE?
3.i am using fwrite function which i assigned hex string values into unsigned char variable
|
|
|
|
|
Basically you need a better undestanding on fundamental C/C++ data types. For instance your point (2) doesn't make any sense.
Possibly you're retrieving binary data, representing an image from the database. In such case, you've just to make sure that:
- The database contains what is expectded (i.e. what is the format of the image inside the db (
raw data , bitmap , jpeg ,...)?). - Your function(s) correctly transfer on file the data retrived from the database (i.e. the
binary content of the file matches the one of the record in the database).
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]
|
|
|
|
|
refine below
1. (JPG format may not have file header section; i might be wrong. )
1'. check byte sequence of original, database and generated from your code.
annese wrote: 2.do you mean i have to convert hex string to BYTE?
generally so. you need convert char[2] to unsigned char
like "FF" (char[]) -> 0xff (unsigned char)
annese wrote: 3.i am using fwrite function which i assigned hex string values into unsigned char variable
good. but to say, you must fwrite array of BYTE above.
example)
char HEX[9] = "FFD8FFE1"; //original string
BYTE BIN[4] = { 0xff,0xd8,0xff,0xe1 }; // converted one
x fwrite(HEX, 1, 8, fp); // wrong!
o fwrite(BIN, 1, 4, fp); // good!
check further.
|
|
|
|
|
thanks for the very helpful info
|
|
|
|
|
I got too long hex string because it is an image file, size about 4k. If there any standard function to convert hex to binary? If not it will take some times to convert it? tq
|
|
|
|
|
What is CPU Time?
Some body tell me that this program use 10% CPU Time.
what does him mean?
and
How can I write the code for check CPU Time of my program,
what's function support this issue.
|
|
|
|
|
Max++ wrote: What is CPU Time?
Here[^] you go! This was my first hit when I searched.
Max++ wrote: How can I write the code for check CPU Time of my program,
You can use types in time.h[^] to find the execution time.
|
|
|
|