|
Actually in processing my DLL_THREAD_ATTACH I only want to process certin threads and I was thinking of Getting the thread name and comparing it to see if its the thread I want to process
However there doesn't seem to bet a GetThreadName API
|
|
|
|
|
Then don't think about debugger SetThreadName, It is available for debugging purpose, if the debugger is not attached then no use you should not use that for final product.
You may use [Thread Local Storage win32 API^] to store the name of the thread at a particular index and retrieve the value.
|
|
|
|
|
Problem is in DLL_THREAD_ATTACH
I only want to Process certin threads so...... I want to know the nature of the thread
Tried StackWalk but go to KiAPC.... it was an asyncourous procedure call which lost track of the stack
When going throgh the debugger I get the thread id, the statement after CreateThread or in this case since the orignal app is in C is _beginThreadx it would be nice if some how using the thread id I could some how tell the DLL_THREAD_ATTACH message the nature of the thread
Thankx
|
|
|
|
|
Hi all,
What is the counter part of the FtpCommand function for http? I need this inorder to find out if a certain http site supports pause and resume
BOOL bRet = ::FtpCommand(hConnect,FALSE,FTP_TRANSFER_TYPE_ASCII, "REST 0",0,&,hResponse);
This is the line
Thanks,
Jj
|
|
|
|
|
Hello again monsieur_jj,
You can use the code I posted yesterday[^] to pause/resume your download. You can easily implement it yourself. First you need to acquire some knowledge about HTTP. The ability to pause/resume a file download is actually taking an advantage of a function of the HTTP 1.1 RFC[^] over at the world wide web consortium[^].
If you take a look at section 14[^] and scroll down to 14.16 Content-Range you will see the description of how to obtain a range of bytes from the requested file. For example:
1.) When the HTTP download begins you should store the content length.
DWORD dwFileSize;
pSession->QueryInfo(HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,dwFileSize);
2.) Open the URL with the sample code I provided in my last post and begin writing the bytes.
3.) If the user pauses the download close the CInternetSession in the middle of writing to the file. Save the number of bytes written to a variable for later use.
4.) User resumes the download and you compare content-length with amount you previously wrote to disk. Re-open the file on disk and reopen the CInternetSession and URL.
But this time we add the Range header! For example:
"Range: bytes=1024-2048"
"Range: bytes=1024-"
"Range: bytes=-1024"
Any library which allows to add HTTP headers can be made to pause/resume HTTP downloads by simply adding the correct headers. Hope this helps!
Best Wishes,
-David Delaune
|
|
|
|
|
Hello David,
May i ask you one question? actually i am working on project suggestion list and for every hit a request is send to server and than responce occur. this is done using http connection.now we are using thread for sending the request because we do not want that user will wait for responce while typing and one more condition i use is that i am taking an Id for requset and responce. when they are equal than only suggestion list is display.
It is working fine but after typing some lines a crash appear. IT is because of thread that is created everytime. I dont find any clue why is it so. bcause it take time to destroy a thread but on every hit thread is created.
Can yo please suggest me what is wrong .I am regularly checking your reply
Thanks
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
Hello Shilpi,
It is very difficult to say what is wrong without looking at the code. To eliminate the possibility of deadlocks and race conditions I always recommend using PostThreadMessage/PostMessage for communication between application dialogs and threads.
If you are creating a very large number of threads you may want to research STACK_SIZE_PARAM_IS_A_RESERVATION. When you use CreateThread it defaults to reserving 1 MB of stack space each thread. This can limit the amount of threads available to your application. I always reduce the stack size to 512 kilobytes for low-duty worker threads. For example:
CWinThread *pTmpThread = NULL;
...
...
if (NULL != pTmpThread)
{
ASSERT_VALID(pTmpThread);
if (!pTmpThread->CreateThread(CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION ,524288,NULL))
{
delete pTmpThread;
*pOldThread=NULL;
return;
}
pTmpThread->m_bAutoDelete = TRUE;
VERIFY(pTmpThread->SetThreadPriority(THREAD_PRIORITY_NORMAL));
pTmpThread->ResumeThread();
PostThreadMessage(pTmpThread->m_nThreadID,WM_THREAD_START,0,0);
}
Once again it is very difficult to say what is the problem without having a look at your code. If you continue to have this same problem I would suggest creating a new post here on the C++ forum and maybe add some source code.
Best Wishes,
-David Delaune
|
|
|
|
|
Hi David,
Thanks for reply
I got the issue that was my mistake actually i am not tackle one condition and after fixing that bug it is working fine.
I am not using CWinThread. I am using one simple function as a thread.It is another way to create a thread.
Thanks Soo much
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
|
Hi David,
Can you give me an example on how those headers are used?
Thanks,
Jj
|
|
|
|
|
You simply need to pass the header text in OpenURL(). Have a look at the function GetHttpFile() in this example[^].
Best Wishes,
-David Delaune
|
|
|
|
|
Thanks David I got it now
|
|
|
|
|
why i cannot close a dialog? the close operation by a button which sendmessage the WM_CLOSE message.
|
|
|
|
|
xqhrs232 wrote: why i cannot close a dialog?
Without seeing the relevant code, who knows.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Are you wanting to close another dialog from your dialog? You need to give us a little more information (and relevant code to support it).
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Hi,
Try
SendMessage(hWnd,WM_COMMAND,IDCANCEL,0)
thanks
Nitheesh
|
|
|
|
|
Whats your code for this action?
|
|
|
|
|
I am gonna gonna take a stab at it... maybe what you are looking for is EndDialog()
|
|
|
|
|
the following is my code,give me some advise.
sometimes the dialog can close by this,sometimes doesnot work like i want.
LRESULT CSettingDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_COMMAND:
//I use the button to exit the dialog,which is static create by me!
if(wID==IDC_Btn_SetEsc) //static create the button
{
this->SendMessage(WM_CLOSE,NULL,NULL);
return TRUE;
//break;
}
case WM_CLOSE:
// case WM_DESTROY://2008--4--24 xqh_xg
DeleteObjects(); //free the used object
break;
}//switch(message)
return CDialog::WindowProc(message, wParam, lParam);
}
|
|
|
|
|
Why, oh WHY are you using a WindowProc() override in an MFC dialog?
Or is this not MFC?
MFC modal dialogs are closed with CDialog::EndDialog().
MFC modeless dialogs are closed with CWnd::DestroyWindow().
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Because the button which is used to close the Diaolg is created by myself.
I donot use the ok button and cancel button which are displayed on the Dialog by default.I want to close the Dialog by just send WM_CLOSE message.AS we all know ,when we send the WM_CLOSE message, the WM_Destory and WM_QUIT message will occur following.so i think i can close the Dialog by just send WM_CLOSE.But the idea sometimes work well ,sometimes it doesnot.
I donot know what is the wrong.
|
|
|
|
|
xqhrs232 wrote: Because the button which is used to close the Diaolg is created by myself.
There's rarely a need to override WindowProc(). If you're using MFC,
why not just use MFC's message handling instead of doing it the Win32 way?
Regardless, your code snip is incomplete so it's not much help.
The WM_CLOSE message should be posted, not sent from your window proc.
BEGIN_MESSAGE_MAP(CSettingDlg, CDialog)
ON_BN_CLICKED(IDC_Btn_SetEsc, &CSettingDlg::OnBnClickedBtn_SetEsc)
ON_WM_CLOSE()
END_MESSAGE_MAP()
LRESULT CSettingDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
return CDialog::WindowProc(message, wParam, lParam);
}
void CSettingDlg::OnBnClickedBtn_SetEsc()
{
PostMessage(WM_CLOSE);
}
void CSettingDlg::OnClose()
{
DeleteObjects();
CDialog::OnClose();
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
modified on Saturday, May 10, 2008 11:18 PM
|
|
|
|
|
if the button which i used to exit the dialog is created by dynamic.what can i do?if this, i must use windproc function which can capture the WM_COMMAND which is sended by common control.
|
|
|
|
|
You can do it the same way I showed since you know the ID of the
button (IDC_Btn_SetEsc) at compile time
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
if i want to use the WM_COMMAND message to dispose the common control's press message.what can i do?i think my idea is good,but something is wrong which i donot know now!Because the MFC message is a way,the win32 Messge is another way.i think that my way which uses the Winproc( ) function(in WIN32 message way)is good way.may be i make a mistake in some another positon which i donot know now!
you think that my win32 message way is wrong?that in MFC Appication we cannot use the win32 message way(Winproc( ) function).
|
|
|
|