|
John
I actually want both threads to finish, not one of them. So if I use TRUE for Parm 3 of WaitForMultipleObjects, then as soon as one thread exists, won't my statement return?
I acutally tried this:
<br />
HANDLE hEvents[2] = {NULL,NULL};<br />
CWinThread *pThread1,*pThread2;<br />
<br />
try<br />
{ <br />
m_bRestartMode = IsRestartMode();<br />
<br />
if(!m_bRestartMode)<br />
{<br />
if(GetPendingANI() == SAL2UNI_RETCODE_SUCC)<br />
{<br />
pThread1 = AfxBeginThread(BeginWorker,(LPVOID)this);<br />
pThread2 = AfxBeginThread(CRMWorker,(LPVOID)this);<br />
}<br />
}<br />
else<br />
{<br />
if(Restart())<br />
{<br />
pThread1 = AfxBeginThread(BeginWorker,(LPVOID)this);<br />
pThread2 = AfxBeginThread(CRMWorker,(LPVOID)this);<br />
}<br />
}<br />
<br />
hEvents[0] = pThread1->m_hThread;<br />
hEvents[1] = pThread2->m_hThread;<br />
<br />
}<br />
catch(CDaoException *daoe)<br />
{<br />
CString sErrorMsg,sErrNo;<br />
CDaoErrorInfo *errInfo = daoe->m_pErrorInfo;<br />
<br />
<br />
sErrNo.Format("%d", errInfo->m_lErrorCode);<br />
sErrorMsg = "Error No.: " + sErrNo + " - " + errInfo->m_strDescription;<br />
sErrorMsg += " occurred in application " + errInfo->m_strSource;<br />
LogActivity(CA_MSG_SEVERITY_INFORMATION,sErrorMsg);<br />
daoe->Delete();<br />
<br />
}<br />
<br />
WaitForMultipleObjects(2,hEvents,FALSE,INFINITE);<br />
LogActivity(CA_MSG_SEVERITY_INFORMATION,"Both threads returned");<br />
<br />
And my code just got hung....none of the two worker threads did any work and I never got to LogActivity(...) below WaitForMultipleObjects.
Thanks
ashish
|
|
|
|
|
He was probably assuming that you were running this in a loop.. checking every so often to see if both the threads exited.. You could set the Infinate flag and not even use the loop.. then it would wait until both exited.. Could be infinate if for some reason one of your threads hung..
HANDLE hThreads[2];
hThreads[0] =
hThreads[1] =
while(true)
{
DWORD dwCode = WaitForMultipleObjects(2,hThreads,TRUE,100);
if ( dwCode == WAIT_TIMEOUT )
{
}
else
{
break;
}
}
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
achandra007 wrote:
So if I use TRUE for Parm 3 of WaitForMultipleObjects, then as soon as one thread exists, won't my statement return?
You do want TRUE for param 3 because that means to wait for both threads to finish. Are you sure that the threads are finishing? I have used this technique in the past with CreateThread() but not AfxBeginThread but the result should be the same.
John
|
|
|
|
|
I am currently looking for the highest quality, easiest to implement, most secure and most reliable peer to peer c++ package avaliable to implement peer to peer networking in c++.
The company I work for already has a very robust and complex program which operates under a client-server network architecture. I am exploring migrating that architecture to peer to peer.
I have so far come across what appear to be the three best packages avaliable online:
1) P2PToolkit - www.p2ptoolkit.com
2) Howl - http://www.swampwolf.com/products/
3) JXTA-C - http://jxta-c.jxta.org/servlets/ProjectHome
Obviously, there is always the option of coding it up ourselves and not using a pre-defined package but I estimate that would take more time and money than necessary.
We have done some initial testing of P2PToolkit sample programs and have found them to be extremely unstable and unreliable. Then again, those were just the sample programs given online. HOWL seems encouraging as it uses the Zeroconf "standard" adopted by Apple Computer, but there is a discouraging amount of documentation avaliable.
I am very excited by the JXTA program and we have other projects which have used it in java-implementations of peer to peer networking. JXTA-C would be a definite choice, especially in light of its claims of interoperability, except according to the JXTA-C program site, its not finished and has not had any kind of final release. In fact, according to the program site, the majority of the project hasn't been touched in at least a year, which implies forward progress stopped in some way.
Does anyone out there have any suggestions about any of the three aforementioned Peer to Peer packages, either from experience or knowledge? Has anyone worked on a large scale project involving peer to peer networking and could share their experience?
Thanks in advance.
-EEder
|
|
|
|
|
Well, it is really project specific. While "peer to peer" is a beautiful term, it can mean million different things. Judging by your java reference I assume you prefer RMI, in which case why don't you go with Corba (COM/ DCOM) or even RPC?
|
|
|
|
|
Actually, my Java reference was to a different, although similar, project. Although the potential of that project and my current one being able to easily operate together if need be (part of my reason for being excited about JXTA) is nice.
I did use the term 'peer-to-peer' loosely and thats becuase I think its a pretty standard 'peer-to-peer' application. I'm looking for -
1) Self realizing network - discovery of peers when they arrive on the network, although a nameserver may be necessary.
2) standard message sending, data transfer
3) security is a factor, although not a driving one
The project currently handles all the data transfer properly, it just does it between a client and server.
Thanks for the comments!
|
|
|
|
|
HI,Guys
I tried all methods I know,but it seems all the methods don't work?Could anyone help me?
YES, I am here.
|
|
|
|
|
float f =-89.567;
char * a = (char*)f;
|
|
|
|
|
thank you very much
YES, I am here.
|
|
|
|
|
That won't work at all.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
char buffer[100];
sprintf(buffer,"%f",floatvalue);
bb |~ bb
|
|
|
|
|
thank you.But it seems that must include the file stdio.h
YES, I am here.
|
|
|
|
|
When I look at the answers I see that both answers are completly different. The first casts the float to a char* so that you can look at the bits of how the processor encoded the float. I am not sure why you would want that.
[EDIT]
Also if you want that you should use BYTE or unsigned char instead.
[/EDIT]
The second returns a string that represents the float number. This is more likely what you want.
Which one are you looking for?
John
|
|
|
|
|
<br />
char* ConvertBSTR(BSTR text)<br />
{<br />
return (char*)_T(text);<br />
}<br />
I've got this function, but when I call:
<br />
char* temp;<br />
temp=ConvertBSTR(BSTRTEXT);<br />
MessageBox(NULL,temp,"",MB_OK);<br />
It only converts the first character
Does somebody know how to resolve this problem???
|
|
|
|
|
[edit] This solution won't work because the converted string is actually on the stack, so the returned string will be invalid. The macros will have to be used inline, not in separate functions [/edit]
You can't use a BSTR like that. A BSTR is a unicode string. To convert BSTR to a char* , use the ATL conversion macros:
[edit]You have to include "atlconv.h" first[/edit]
char *ConvertBSTR(BSTR text)
{
USES_CONVERSION;
return W2A(text);
} In your case, you only need a const char* , so you can do this
const char *ConvertBSTR(BSTR text)
{
USES_CONVERSION;
return W2CA(text);
} Hope this helps,
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
No, still doesn't work
Any other options?
|
|
|
|
|
That won't work because the converted string is stored on the stack, and it goes out of scope as soon as the function returns. Use the macros inline, instead of in separate functions like that.
--Mike--
"So where does that leave us? Well, it leaves us right back where we started, only more confused than before." -- Matt Gullett
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
|
|
|
|
|
That's the problem, the macro's won't work here... and they are to slow I'm making a game engine so that need to be fast With COM, that's the reason for using a BSTR. And now I call a DirectX function that needs a LPCWSTR. So I have to convert it, but how??? :S
|
|
|
|
|
You can pass a BSTR to a function expecting a LPCWSTR , because both strings are in the same format (zero-terminated Unicode string)
--Mike--
"So where does that leave us? Well, it leaves us right back where we started, only more confused than before." -- Matt Gullett
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
|
|
|
|
|
But then I get the error that the format isn't right
|
|
|
|
|
Michael Dunn wrote:
That won't work because the converted string is stored on the stack, and it goes out of scope as soon as the function returns
Aargh. Of course . I should have known that
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
BSTR a = SysAllocString (L"asdfghj12345");
MessageBoxW (NULL,(LPCWSTR)a,NULL,NULL);
|
|
|
|
|
hello @all,
how can i convert a double value into a string?
can anybody help me???
thank you very much!
sunny
|
|
|
|
|
With this function I think
_gcvt();
Convert double number to string; store string in buffer
|
|
|
|
|
Try using sprintf (or _stprintf to support UNICODE as well):
char buf[16];
sprintf(buf, "%f", doubleValue);
TCHAR tbuf[16];
_stprintf(buf, _T("%f"), doubleValue); If you're using MFC, you can do this:
CString str;
str.Format(_T("%f"), doubleValue); Hope this helps,
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|