|
I don't want to pass the CFtpConnection* pointer to a thread proc because that may be dangerous. Although I can get the handle of the FTP connection from the (HINTERNET) operation, I cannot construct a CFtpConnection object from the handle I've got because there's no such function. What should I do? Please help me out.
Thanks in advance.
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|
|
I don't know anything about these classes, but I've decided to look into your problem as it appears to be more of a C++ issue than anything else.
The MFC header file for CFtpConnection shows that the class has a couple of constructors. The one you would probably use looks like this:
CFtpConnection(CInternetSession* pSession, HINTERNET hConnected, LPCTSTR pstrServer, DWORD dwContext);
Again, I don't know anything about these parameters but the second one looks like the one you'd be passing from the other thread. If this doesn't work I'd suggest you to derive a class from CFtpConnection. Since m_hConnection is protected in CInternetConnection, you'd have access to it in your derived class.
Good luck!
Alvaro
|
|
|
|
|
Thank you very much!
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|
|
Hi,
I'm trying to get my MDI app to use splitter windows:
My ChildFrame class is called CDesignFrame:
I removed the CView derived member and added a CSplitterWnd member instead.
I overrode the CDesignFrame::OnCreateClient and added this:
m_splitWnd.CreateStatic(this,
2,
1,
WS_CHILD | WS_VISIBLE,
AFX_IDW_PANE_FIRST);
SIZE sInitSize;
sInitSize.cx = lpcs->cx;
sInitSize.cy = lpcs->cy / 2;
m_splitWnd.CreateView(0,
0,
RUNTIME_CLASS(CDesignView),
sInitSize,
pContext);
m_splitWnd.CreateView(1,
0,
RUNTIME_CLASS(CDesignView),
sInitSize,
pContext);
CDesignView is simply the default AppWizard created view class. it doesn't do anything yet. All i did to it was declare and implement dyncreate on it.
Anyway. All compiles nicely, but when i run it, clicking file|new causes app to crash with an unhandled exception: Traceing through the app step by step shows the error comes from the CMDIFrameWnd::CreateNewChild function, when it calls pFrame->InitialUpdateFrame(NULL, TRUE);
The docs for InititalUpdateFrame say it'll update all views in the frame window. but there are none. but if i remove this function call, my frame isn't displayed.
I'm a bit lost. How should I do this?
Jon
|
|
|
|
|
|
I finally figured it out... Because I disabled the Doc/View architecture support in appwizard, My CView derived class was in fact CWnd derived.
Part of the InitialUpdateFrame function casts this CWnd Pointer to a CView, and then calls a member function which plainly doesnt exist. This causes the exception.
Nice to have it sorted.
Thanks again
|
|
|
|
|
There are normally three buttons on the right most upper corner of a window
1) Minimize
2) Small / Large
3) Close (cross)
I want to add another button adjacent to these three buttons (supposedly .) that will minimize the application to task bar (adjacent to clock)
How can I possibly add this button?
Maliha
|
|
|
|
|
You'll have to handle WM_NCPAINT. Have a look at Jan'97 issue of MSJ, C++ Q&A column - it has a code that draws custom caption bar. The article should be in the 'Periodicals' section of VC++ help.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
how to list efficiently TIDs (or handles) of all threads
running within a specified process ?
Thanx in advance
Michal Januszczyk
|
|
|
|
|
There's no method that will work on all 32-bit Windows versions. On 9x and 2000 you can use ToolHelp32's Thread32First/Thread32Next. On NT4 you'll have to get perf data with PdhEnumObjects.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I had written a dialog based application.
It contained a button named "Try"
When I clicked the "Try" button,opened an other
dialog named "Test" which contained a button named "Open".
When I first clicked "Open" button and clicked the "OK"
button in Open File Dialog,everything is ok,and then
close the "Test" Dialog.
But When I click "Try" button again,it showed me wrong.
Who can please tell me what's wrong with my code??
******************************************************************
void CFirstDlg::OnButtonTry()
{
// TODO: Add your control notification handler code here
CTestDialog* dlg;
dlg=new CTestDialog;
dlg->DoModal();
}
******************************************************************
BOOL CTestDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CString sCon;
_ConnectionPtr m_pCon;
_RecordsetPtr m_pRs;
sCon="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=main.mdb";
CoInitialize (NULL);
HRESULT hr=S_OK;
try
{
hr=m_pCon.CreateInstance(__uuidof(Connection));
if(FAILED(m_pCon->Open(_bstr_t(sCon),"","",adModeUnknown)))
AfxMessageBox("Can not open the database!");
}
catch(_com_error e)
{
CString errormessage;
errormessage.Format("Failed!\r\nError Message:%s",e.ErrorMessage());
AfxMessageBox(errormessage);
}
m_pRs.CreateInstance("ADODB.Recordset");
if(FAILED(m_pRs->Open("SELECT * FROM employeer",_variant_t((IDispatch*)m_pCon,true),adOpenStatic,adLockOptimistic,adCmdText)))
AfxMessageBox("Can not open the record set!");
if((m_pRs->State & adStateOpen) == adStateOpen)
m_pRs->Close();
if ( (m_pCon->State & adStateOpen) == adStateOpen)
m_pCon->Close();
CoUninitialize();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
***********************************************************************
void CTestDialog::OnButtonOpen()
{
// TODO: Add your control notification handler code here
static char BASED_CODE szFilter[]="Bitmap Files (*.bmp)|*.bmp||";
CFileDialog *fd;
fd=new CFileDialog(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFilter,this);
if(IDOK!=fd->DoModal())
return;
else
AfxMessageBox(fd->GetFileName());
delete fd;
}
|
|
|
|
|
You didn't delete the dlg object in the CFirstDialog::OnButtonTry(). That should be the problem. Why do you want to use the heap object rather than stack object? If you do it like this:
void CFirstDialog::OnButtonTry()
{
CTestDialog dlg;
dlg.DoModal();
}
you won't be worried about the work of releasing object. I think this form is better.;)
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|
|
The wrong still happened,what should I do?
|
|
|
|
|
So could you send your piece of codes to me? I think looking into the codes will be more clear.
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|
|
Thank you,under the help of others,I had solved the problem.
Thanks again.
A beginner of Visual C++,and need your help.
|
|
|
|
|
After seeing code,
I think you are not destroying dialog (delete dlg). This should be your problem.
CTestDialog* dlg;
dlg=new CTestDialog;
dlg->DoModal();
////add line...
delete dlg;
--------------------------------------------------
Say Whatever You Know.
Helping other people is good for health.
=========
Manish
=========
---------------------------------------------------
|
|
|
|
|
The wrong still happened.
|
|
|
|
|
Hi All,
I have a line of code
WaitForSingleObject(hSem,INFINITE);
which i want to replace it for some tracing purpouses with
while(1)
{
if(WaitForSingleObject(hSem,300)==WAIT_OBJECT_0)
break;
//A single trace stmt
TRACE(" ");
}
However, if i do this, my CPU utilization runs to 100% in NT.
Am i doing something wrong? Thanks all for ur help.
cheers ... Sriram M R
|
|
|
|
|
I had the same pb in this loop which was implemented in a thread :
while(TRUE)
{
...something to do
}
I found the solution by adding a Sleep() inside the loop like this :
while(TRUE)
{
... your code
Sleep(1); // 0 has no effect
}
Now, is it a bug from Microsoft ?
Hope that can help you.
|
|
|
|
|
i don't really think that this is a bug.. i think it is made per design.. in an endless loop you have to install a wait - object (sleep(1)) so that the other threads have got any chance to handle their messages... (think this is a general window - programming rule.. never use endless loops without a sleep)
i had that problem in some multithreaded programs too.. after insert sleep(1) it worked perfectly..
if anybody else has another workaround you're welcome
bernhard
stolen sig#16:
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."
|
|
|
|
|
This is what the documentation says abt WaitForSingleObject:
"The WaitForSingleObject function checks the current state of the specified object. If the object's state is nonsignaled, the calling thread enters the wait state. It uses no processor time while waiting for the object state to become signaled or the time-out interval to elapse."
It states that no processor time is used for timing out.Meaning WaitForSingleObject should sleep for altleast 300 Ms in this case till the object gets singnalled which it seems it is not doing.
Please correct me if i am wrong.
|
|
|
|
|
I think there are two possibilites for high CPU utilization:
1) TRACE - it may scroll and repaint the Output window. It's easy to check, just remove the call and check the utilization.
2) while WaitForSingleObject doesn't tax the processor during wait, it may use some cycles when entering and exiting the wait state. However, 300ms is quite long time to amortize these costs.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hi,
In actual code i use a home grown version TRACE that logs to a file and is pretty fast enough.I just added the TRACE to make my point.The CPU utilization is still high.
|
|
|
|
|
see i can create event objects from my programme using createevent api.. it can create an event,good thing is i can name this event also, out side user mode of winnt or winx.
and i can access this event object from any of my other process provided this event object is inheritable, and u know the name of the object. so far things are fine.
now lets come to my problem, i want to access such an event object from one of my processes, but i dont know the name of the object. so that i have to write some piece of code which could enumerate all the event objects created at kernel/system level. so that i can choose the name of the event object and proceed further. if u see any solutions pls forward that to me as soon as possible.
exwhiz
|
|
|
|
|
Did you want to use OpenEvent() to open your event object? If you created the event object using the form CreateEvent(...,...,...,NULL), you had created an event object without a name. You should replace the last NULL with a string to specify the name of the event object, then you can use OpenEvent() using the name. Hope it can help you.
Law is meaningless without chaos.
Chaos without Law is equal to destruction.
Chaos and Law create our rich and colorful world.
|
|
|
|