|
Dont put it in stdafx.h
Cause when you put it on top, the compiler hasn't encountered the included header files yet
Make it a member variable of the class where you are using the critical section
Nish
I am looking for a free racing game. Old style racing game without any complicated 3D stuff. Around 4 MB download. If anyone has such a game, please inform me.
|
|
|
|
|
No, because you're creating the critical section on the stack. Each thread has its own stack, so when two threads enter the function they use different critical sections.
You need to have one critical section and then access it in all threads.
--Mike--
It's hammer time!
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan and Jamie Salé.
|
|
|
|
|
Hi,
Thanks for all your replies.......
But I'm not quite understand........can you give me some example codes???
Thanks
|
|
|
|
|
Tell you what, since you seem to have trouble making it a member of your class, for whatever reasons do this then :-
Make it a member of the CWinApp derived class.
Now use AfxGetApp(), cast the pointer returned to your CWinApp derived class and access the critical section variable.
Nish
I am looking for a free racing game. Old style racing game without any complicated 3D stuff. Around 4 MB download. If anyone has such a game, please inform me.
|
|
|
|
|
Nish [BusterBoy] wrote:
Make it a member of the CWinApp derived class.
Now use AfxGetApp(), cast the pointer returned to your CWinApp derived class and access the critical section variable.
I'm not quite understand how to make it a member of the CWinApp, or even make it global. Can you give me some examples??
LOTS OF THANKS!!!!!!!!!
|
|
|
|
|
Dear Friend
I don't know whether this is going to solve your problem , This is how to make a variable global. double click the "theApp" Global variable in your project.then you can see the declaration
eg:
CMyApp theApp;
//Put your variable as follows
CCriticalSection cs;
//Now this is global
Then go to the implimentation file of the class where you want to use this varialble,and put is as follows
eg:
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
//Global Variable, Now use this in your function
extern CCriticalSection cs;
// CMyApp
BEGIN_MESSAGE_MAP(CMyApp, CWinApp)
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
Gaurika Wijeratne
|
|
|
|
|
ChiYung wrote:
CCriticalSection cs;
If you just want to protect what is happening inside this function then simple change it to:
static CCriticalSection cs;
As others have said it can't be on the stack under any circumstances.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
I use the following code:
/////////////////////////////////////
this->GetDC()->SetBkColor( RGB(0,0,255) );
this->SendMessage( WM_PAINT, 0, 0 );
//////////////////////////////////////
But no efforts, what's the matter?
I'm amumu, and you?
|
|
|
|
|
|
hi,
Take a look the structure of my array first:
struct WAITQUEUE_STRUCT
{
CWinThread* pThread;
int LockType;
LARGE_INTEGER start_time;
};
struct LOCK_TABLE
{
CWinThread* CurrentThread;
int CurrentLock;
std::vector<WAITQUEUE_STRUCT> WaitQueue;
};
std::vector<LOCK_TABLE> LockTable;
In my program:
std::vector <WAITQUEUE_STRUCT>::iterator Iter;
for (int i=0; i<NumOfDBObject; i++)
{
Iter = LockTable[i].WaitQueue.begin();
if (*Iter.pThread != NULL) <- one of the error here
{ .......
.......
.......
i got the error message :
"error C2228: left of '.pThread' must have class/struct/union type"
What happened??????
|
|
|
|
|
ChiYung wrote:
for (int i=0; i{
Iter = LockTable[i].WaitQueue.begin();
if (*Iter.pThread != NULL) <- one of the error here
{ .......
(*iter).pThread
or
iter->pThread
|
|
|
|
|
DEar Friends
I always refer Charles Petzold book fo basic programming code. So I want to get a complete .dsw file. Kindly give/send me any such zip file which reads a bitmap file and then display it after getting hdc. I am working on Win32API only.
Thanking you in advance.
Binay
|
|
|
|
|
after you use LoadImage to load the bitmap, use this code in your window procedure to draw it:
case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);
RECT rt;
GetClientRect(hWnd, &rt);
HDC DC = CreateCompatibleDC(hdc);
HBITMAP oldBitmap = (HBITMAP)SelectObject(DC, hBitmap);
BitBlt(hdc, 0, 0, rt.right, rt.bottom, DC, 0, 0, SRCCOPY);
SelectObject(DC, oldBitmap);
DeleteDC(DC);
EndPaint(hWnd, &ps);
}
HTH
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
It may be that your sole purpose in life is simply to serve as a warning to others.
|
|
|
|
|
If I did that, I would be doing your homework for you. It should be very easy to figure out with the code I have given you. If you have any more specific questions, ask the in this forum, there are lots of people who will help you.
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
It may be that your sole purpose in life is simply to serve as a warning to others.
|
|
|
|
|
Hi,
I would like to terminate the FOR loop at the middle of the loop. E.g.
for (i=0; i<100; i++)
{
if (i == 50)
break;
}
Is it use break???? Or.........
Thanks!!!!
|
|
|
|
|
Yes.
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
Hi,
Is there a function to set a timer?? In my case, I want to keep track of the time that a thread is being suspended, so that it would be suspended forever.
Or, can you give me any suggestion to do that??
Thank you!
|
|
|
|
|
You can use SetTimer and then in the handler do your custom time tracking.
Nish
I am looking for a free racing game. Old style racing game without any complicated 3D stuff. Around 4 MB download. If anyone has such a game, please inform me.
|
|
|
|
|
Thank you so much for your reply..!
But, I still have problem with SetTimer(). I always got error messages like "function does not take 1 (or 2) parameters". Can you please give me an example of using SetTimer?? For example: what I can do if I want to count in 5 sec??
Thank you !
|
|
|
|
|
SetTimer(1000,5000,NULL);
1000 is the ID of this particular timer
5000 means 5 seconds
NULL means the WM_TIMER handler of the CWnd object gets called
Nish
I am looking for a free racing game. Old style racing game without any complicated 3D stuff. Around 4 MB download. If anyone has such a game, please inform me.
|
|
|
|
|
Thank you very much!
|
|
|
|
|
If you want to keep track of the time, you better use GetTickCount()
Michel
If I am wrong or said something stupid, I apologize in advance
|
|
|
|
|
As long as you watch out for overflow in the count.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
I have a C++ program that has some context information for an HTML page. How can I pass parameters to an HTML page?
Thanks,
Hawk
|
|
|
|
|
I'm not entirely sure what you mean about context information and what HTML page you're talking about.
If you've got a HTML control and you're using Navigate() to open a page, you just need to append the CGI parameters to your target path. For example for the page:
http:
you can just append parameters to set the variable 'Name' to 'Joe Blow' and 'Age' to 25 as follows:
http:
You need to replace ' 's with '+'s. Also, technically, you need to replace any unprintable characters with escape sequences '%2F'. To find out more, search MSDN for CGI and ISAPI information.
Hope this helps.
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|