|
thx for the reply
how would i implement a timer, so that after say 5secs if the thread hasnt finished, kill it?
|
|
|
|
|
Use WaitForSingleObject() for this.
CWinThread *pThread = AfxBeginThread(..., CREATE_SUSPENDED);
pThread->m_bAutoDelete = FALSE;
pThread->ResumeThread();
...
switch(WaitForSingleObject(pThread->m_hThread, 5000))
{
case WAIT_TIMEOUT:
break;
case WAIT_OBJECT_0:
break;
}
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
thx for the replys
i am having trouble implementing AfxBeginThread()
<br />
void CScanDlg::OnButtonScan() <br />
{<br />
AfxBeginThread(ThreadProc);<br />
}<br />
<br />
UINT CScanDlg::ThreadProc(LPVOID pParam)<br />
{<br />
if(wmi(strIP1))<br />
return 0;<br />
else<br />
return 1;<br />
}<br />
what is wrong above, sorry about these questions but this is new to me
|
|
|
|
|
viperlogic wrote: i am having trouble implementing AfxBeginThread()...
Aside from not suppling enough arguments, what troubles are you having?
viperlogic wrote: UINT CScanDlg::ThreadProc(LPVOID pParam)
Is this a static member?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
ok this is what i have..
static UINT CScanDlg::ThreadProc(LPVOID pParam); delcared in the header file
<br />
AfxBeginThread(ThreadProc,NULL,THREAD_PRIORITY_NORMAL,0,0,NULL);<br />
<br />
UINT CScanDlg::ThreadProc(LPVOID pParam)<br />
{<br />
if(wmi(strIP1))<br />
return 0;<br />
else<br />
return 1;<br />
}<br />
i get the following error
CScanDlg::wmi' : illegal call of non-static member function
|
|
|
|
|
Try:
AfxBeginThread(ThreadProc, this);
...
UINT CScanDlg::ThreadProc( LPVOID pParam )
{
CScanDlg *pDlg = (CScanDlg *) pParam;
if (pDlg->wmi(strIP1))
return 0;
else
return 1;
}
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
thx, that worked
can explain why thou?
|
|
|
|
|
Recently, I discovered that using cerr from console programs that are linked together by a pipe can produce garbled output. I have made two test programs that illustrate the problem. I have also made two programs that use fprintf and stderr instead of cerr -- and the output is fine. Does anyone know how to avoid the garbled output (see below) while still using cerr?
The first two programs that use cerr for log messages are called StdOutCpp and StdInCpp. When executing the command "StdOutCpp | StdInCpp" I get the following output (varies a little bit from execution to execution):
StdOut: Printing to stdout...
StdOut: Printing byte 1...
StdOut: Byte 1 printed.
StdIn: Reading from stdin...
StdIn: Reading byte 1...
StdIn: Byte 1 read.
StdOut: Printing byte 250001...
StdOut: Byte 250001 pStdIn: Rrinted.
eading byte 250001...
StdIn: Byte 250001 read.
StdOut: Printing byte 500001...
StdOut: Byte 500001 pStdIrinted.
n: Reading byte 500001...
StdIn: Byte 500001 read.
StdOut: Printing byte 750001...
StdOut: Byte 750001 pStdrinted.
In: Reading byte 750001...
StdIn: Byte 750001 read.
StdOut: Finished printing to stdout.
StdIn: Finished reading from stdin.
As you can see from the above printout, some lines are mixed together.
The next two programs that use fprintf and stderr for log messages are called StdOutC and StdInC. When executing the command "StdOutC | StdInC" I get the following output:
StdOut: Printing to stdout...
StdOut: Printing byte 1...
StdOut: Byte 1 printed.
StdIn: Reading from stdin...
StdIn: Reading byte 1...
StdIn: Byte 1 read.
StdOut: Printing byte 250001...
StdOut: Byte 250001 printed.
StdIn: Reading byte 250001...
StdIn: Byte 250001 read.
StdOut: Printing byte 500001...
StdOut: Byte 500001 printed.
StdIn: Reading byte 500001...
StdIn: Byte 500001 read.
StdOut: Printing byte 750001...
StdOut: Byte 750001 printed.
StdIn: Reading byte 750001...
StdIn: Byte 750001 read.
StdOut: Finished printing to stdout.
StdIn: Finished reading from stdin.
A perfect output, exactly as I want it.
Code listings:
--- StdOutCpp.cpp begin ---
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int n = 1000000;
cerr << "StdOut: Printing to stdout..." << endl;
for (int i = 0; i < n; i++)
{
if (i % (n / 4) == 0) cerr << "StdOut: Printing byte " << i+1 << "..." << endl;
cout << 'A';
if (i % (n / 4) == 0) cerr << "StdOut: Byte " << i+1 << " printed." << endl;
}
cerr << "StdOut: Finished printing to stdout." << endl;
return 0;
}
--- StdOutCpp.cpp end ---
--- StdInCpp.cpp begin ---
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int n = 1000000;
cerr << "StdIn: Reading from stdin..." << endl;
for (int i = 0; i < n; i++)
{
if (i % (n / 4) == 0) cerr << "StdIn: Reading byte " << i+1 << "..." << endl;
cin.get();
if (i % (n / 4) == 0) cerr << "StdIn: Byte " << i+1 << " read." << endl;
}
cerr << "StdIn: Finished reading from stdin." << endl;
return 0;
}
--- StdInCpp.cpp end ---
--- StdOutC.cpp begin ---
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int n = 1000000;
fprintf(stderr, "StdOut: Printing to stdout...\n");
for (int i = 0; i < n; i++)
{
if (i % (n / 4) == 0) fprintf(stderr, "StdOut: Printing byte %i...\n", i+1);
cout << 'A';
if (i % (n / 4) == 0) fprintf(stderr, "StdOut: Byte %i printed.\n", i+1);
}
fprintf(stderr, "StdOut: Finished printing to stdout.\n");
return 0;
}
--- StdOutC.cpp end ---
--- StdInC.cpp begin ---
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int n = 1000000;
fprintf(stderr, "StdIn: Reading from stdin...\n");
for (int i = 0; i < n; i++)
{
if (i % (n / 4) == 0) fprintf(stderr, "StdIn: Reading byte %i...\n", i+1);
cin.get();
if (i % (n / 4) == 0) fprintf(stderr, "StdIn: Byte %i read.\n", i+1);
}
fprintf(stderr, "StdIn: Finished reading from stdin.\n");
return 0;
}
--- StdInC.cpp end ---
Stian
|
|
|
|
|
Hi
I've the following code to generate permutations of my vector v:
<br />
while (next_permutation(v.begin(), v.end() ) ) { <br />
copy(v.begin(), v.end(), ostream_iterator<int>(cout, ""));
How can I make it output to a vector instead?
I know I need to change to ostream_iterator, but what to?
cheers
-- modified at 11:14 Monday 3rd April, 2006
|
|
|
|
|
back_inserter
0 bottles of beer on the wall, 0 bottles of beer, you take 1 down, pass it around, 4294967295 bottles of beer on the wall.
Awasu 2.2 [^]: A free RSS/Atom feed reader with support for Code Project.
|
|
|
|
|
What does the CAuxThunk and CAuxStdThunk classes do? What purpose does InitThunk have and why do we have to pass a Procedure name to it? What does TMPF stand for and what does it do?
Thanks...
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
|
Hi friends,
I've done a project which is dialog based application.Now I need to connect databases.So how do I proceed now.Do Ineed to redo the whole project in SDI.Pls help me in solving this problem.
bye
swapna_signsin
|
|
|
|
|
What sort of database are you trying to connect to?
|
|
|
|
|
|
|
swapna_signsin wrote: Now I need to connect databases.So how do I proceed now.
If you already have a DSN created, just derive a class from CRecordset using ClassWizard (Ctrl+W).
swapna_signsin wrote: Do Ineed to redo the whole project in SDI.
No, not at all.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Thanx for the reply,
but how do u create a DSN in Dialog based application.I mean how do u make use of ODBC Connection,bcoz u don't have a document/view when u'r using dialog based.
|
|
|
|
|
swapna_signsin wrote: but how do u create a DSN
Use SQLConfigDataSource() .
swapna_signsin wrote: I mean how do u make use of ODBC Connection...
CRecordset handles the details for you. Just derive a class from it.
swapna_signsin wrote: ...u don't have a document/view when u'r using dialog based.
Whether you use document/view or not is irrelevant.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
HI,
Actually Iam a beginner,Sorry to trouble u again,So how do u connect to DSN in Dialog Based applications,bcoz u don't have a Doc/View in this and u can't connect ODBC thru that.I've to connect to MSACCESS database.
Pls do reply,
bye
swapna_signsin
|
|
|
|
|
swapna_signsin wrote: So how do u connect to DSN in Dialog Based applications...
In exactly the same way you would in any other application.
swapna_signsin wrote: I've to connect to MSACCESS database.
After you've got a DSN created (see here for an example), use ClassWizard to derive a class from CRecordset .
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Hi again,
I've tried it and I get the following errors :
1. 'CRecordSet' is not a class or a namespace namefor foll code: CRecordset::Dump(dc);
CRecordset::AssertValid();
2.'CFieldExchange':Undeclared Identifier
3.'CDatabase': Undeclared Identifier
and many of taht sort.
swapna_signsin
|
|
|
|
|
You failed to include afxdb.h .
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Thanx,I'll try it and reply soon.
bye
swapna_signsin
|
|
|
|
|
I have
CDialog::PostNcDestroy();
m_pParentWnd->SendMessage(UDM_LISTCLOSED,0,0);
delete this;
and in the .h file
public:
virtual BOOL OnInitDialog();
protected:
virtual void DoDataExchange(CDataExchange* pDX);
virtual void PostNcDestroy();
The dialog was created by:
if(!m_tgtInfo)
{
m_tgtInfo = new CTargetInfo(this, caseStudy);
if(!m_tgtInfo) return true;
m_tgtInfo->Create(IDD_DLGTGTINFO, (CWnd*)this);
m_tgtInfo->ShowWindow(SW_SHOW);
}
When I close this modeless dialog, execution does not enter the PostNcDestroy function. However if I close the whole app, then the code does go into this function. What am I missing? I looked at sample code and there does not seem to be anything else I need to do...
thanks,
sb
-- modified at 9:00 Monday 3rd April, 2006
|
|
|
|
|
ns wrote: CDialog::PostNcDestroy();
delete this;
Switch these two statements.
ns wrote: When I close this modeless dialog, execution does not enter the PostNcDestroy function.
Have you called m_tgtInfo->DestroyWindow() ?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|