|
I use a CCriticalSection to handle synchronization issues. You could declare a singleton instance of a CCriticalSection , and lock/unlock that before/after executing your function. Competing threads will be blocked until the function is available for use.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Accessing the same function from two threads is generally ok. You only have to take care about shared resources - so variables inside the thread functions (on the stack) are ok, because each thread have it's own stack. Problem can be with accessing global variables, instances that more than one thread can access etc. Here you should use some synchronization.
Critical section is best (IMHO) on windows system, if you do not need to share the synchronization object for interprocess communication (one critical section can be used only inside one process).
Generally it's best to use some sort of RAII for the synchronization, although it have also it's problems.
There are some articles about synchronization issues around on CP, so you can check for them. In case, don't worry to ask.
|
|
|
|
|
I have a small dialog meant to be an interactive ordered checklist with check boxes that check themselves as each of 4 steps are performed. It's called from my main app when a menu item is chosen. What's the best way to start the chain of execution? I currently am calling each function that does each step in a nested if statement in the constructor but that doesn't feel like the best way because these functions are the meat and potato's of the dialogs purpose, and they are definitely not initialization procedures. If there's a proper way, I don't have the particular way existing now so I'd have to override something.
|
|
|
|
|
Perform the tasks in a separate thread while the dialog is executing.
The thread can post messages to the dialog so the boxes get checked.
Make sure to catch if user tries to close dialog, cancel out thread and possibly undo your work. You can start thread at end of OnInitDialog() so all the dialog controls exist at that time.
|
|
|
|
|
I think I have an idea which is a combination of your solution and PJ Arjends'. I don't have an OnInitDialog function, I assume I need to override the CDialog function but I'm not sure how that's done, can you enligthen me? I'm relatively new to this stuff.
I do have a catch in my code:
CTransmitProgram transmitDlg(NULL, pPackage);<br />
if (transmitDlg.DoModal() != IDOK) {<br />
if (AfxMessageBox(IDS_UNKNOWNSTATE, MB_YESNO | MB_ICONQUESTION) == IDYES) { return TransmitProgram(); }<br />
return false;<br />
} else { return true; }
There's an OK and Cancel Button and OK button is disabled until all steps are completed. If anything happens except the OK button is pressed, it'll prompt the user and then try again, else OK was pressed meaning all steps were completed.
Thanks in advance, Nate.
|
|
|
|
|
It appears that you are using MFC.
Use the ClassWizard to add the WM_INITDIALOG, which will end up as OnInitDialog() member function, to the dialog's class for you automatically.
|
|
|
|
|
I did that, I created a static UINT thread function in the class and timed the it to do the check boxes and enable the OK button and it works pretty well. I'm working on the actual functionality so thanks for the advice, you too PJ Arjends.
|
|
|
|
|
If I understand your problem correctly what you want to do is have your dialog's WM_INITDIALOG handler post a user defined message to itself. In the message handler you initialize your chain of execution.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
hi,I'm using WinHTTP to connect a https server and I want to visit one web page of it.
However,error 12175 occurred.
I kown that the certificate sent by the server is not trusted by the client because the certificate is not issued by a trusted provider.
But how can i fix the problem in my program?
|
|
|
|
|
You have to obtain the certificate that is sent by your server and install it on the Trusted Providers. The following code will do the job:
bool InstallCertificationAuthority()<br />
{<br />
HCERTSTORE hSystemStore;<br />
hSystemStore = CertOpenSystemStore(NULL, _T("ROOT"));<br />
if (hSystemStore == NULL)<br />
return false;<br />
<br />
HRSRC hRSRC;<br />
hRSRC = FindResource(AfxGetResourceHandle()MAKEINTRESOURCE(IDR_CERTIFICATE), _T("CERTIFICATE"));<br />
if (hRSRC == NULL)<br />
return false;<br />
<br />
DWORD dwSize;<br />
dwSize = SizeofResource(AfxGetResourceHandle(), hRSRC);<br />
if (dwSize == 0)<br />
return false;<br />
<br />
HGLOBAL hCertificate;<br />
hCertificate = LoadResource(AfxGetResourceHandle(), hRSRC);<br />
if (hCertificate == NULL)<br />
return false;<br />
<br />
LPBYTE lpCertificate;<br />
lpCertificate = (LPBYTE) LockResource(hCertificate);<br />
if (lpCertificate == NULL) {<br />
FreeResource(hCertificate);<br />
return false;<br />
}<br />
<br />
if (!CertAddEncodedCertificateToStore(hSystemStore, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, lpCertificate, dwSize, CERT_STORE_ADD_USE_EXISTING, NULL)) {<br />
logRPCCore.Output("Cannot install certificate!\n");<br />
}<br />
<br />
UnlockResource(hCertificate);<br />
FreeResource(hCertificate);<br />
<br />
CertCloseStore(hSystemStore, 0);<br />
return true;<br />
}<br />
As you see, the code install the certification from a resource of your application into the ROOT Store.
|
|
|
|
|
Hi everybody,
Does anybody know how to catch Microsoft word application events in a non MFC application (specifically WTL application) ?
thanks in advance,
Roozbeh
|
|
|
|
|
Getting file information like author, subject i.e
|
|
|
|
|
How do you know when you are supposed to draw the focus on a control?
I'm referring to controls on dialog boxes.
At first when you click on a control with the mouse, the control doesn't draw the focus rectangle. It only draws it once you start navigating the dialog with the keyboard.
I'd like to be able to find out from within the control using its hWnd.
(I'm trying to skin Win98-style buttons in VC++ 6.0 to give them a WinXP look by overriding drawing messages [WM_PAINT, BM_SETSEL, etc.] in the button's windows-class wnd proc. I've got everything done so far, except this, and I've spent hours searching MSDN and the internet trying to find it.)
|
|
|
|
|
The DRAWITEMSTRUCT passed to OnDrawItem() contains this information. Specifically, the itemState member, whose ODS_FOCUS bit indicates the item has focus. You may also want to check the ODS_SELECTED bit to render the control appropriately. See this[^] MSDN article.
Alternatively, you could call GetFocus() to determine if the control has focus, although the preferred way is to check the DRAWITEMSTRUCT .
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
|
does anyone know of a function that i can pass 2 numbers to ie, 1 and 3, which would return a random float between the 2 parameters ie 2.3. perhaps a function that would return a random int would also work, i could just pass it 1000 and 3000 instead. any ideas? thanks.
|
|
|
|
|
Off the top of my head...
int randInterval
(int nStart,
int nEnd)
{
int nInterval = abs (nEnd - nStart);
int nRand = rand() % nInterval;
return (nStart + nRand);
}
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
//linear transformation
#define GetRandom(min,max) rand()*((float)((max)-(min)))/(float)(RAND_MAX)+(min)
//this only works when min and max are small
/* GetRandom returns a random integer between min and max. */
#define GetRandom( min, max ) ((rand() % (int)(((max) + 1) - (min))) + (min))
http://blog.joycode.com/jiangsheng
http://blog.csdn.net/jiangsheng
Command what is yours
Conquer what is not
---Kane
|
|
|
|
|
I'm trying to make an icon editor, but i don't know which colors to use for the palettes. Do you use the standard windows system palette? Is there any way to find out what the color values are for it? For example:
COLORREF stdpal16[] = {/*color values*/};
COLORREF stdpal256[] = {/*color values*/};
thanks.
|
|
|
|
|
i need to be able to read a line from a text file and store what is read in int.
|
|
|
|
|
|
Try this,
CFileException ex;
CFile myfile;<br />
<br />
myfile.Open("c:/b.txt", CFile::modeRead, &ex);<br />
<br />
int z=myfile.GetLength();<br />
char* data=new char[z];<br />
myfile.Read(data,z);<br />
<br />
int* value=new int[z/3];<br />
for(int i=0;i<z;i=i+3)<br />
value[i/3]=atol(&data[i]);
<br />
myfile.Close();
|
|
|
|
|
what header file to i need for this code?
|
|
|
|
|
No header is required. Stdafx.h is sufficient i think. CFile is a class of MFC. Refer to MSDN
|
|
|
|
|
what do you man when you say that you want to store the data in int.
do you want to store the number of bytes you read from a file in int'or do you want to store the data in int(in that case -> ???????)?
regards,
Eli
|
|
|
|