|
|
I downloaded it built it debug x64 and as I was stepping thru that code it got an exception it was somewhere in MFC code the call stack indicated it was from an Additem Ill go back and try to fix it up thank you
|
|
|
|
|
Hi,
In my trying on understanding semaphores I am looking on the following example:
DWORD WINAPI ChildThreadProc( HWND hWnd )
{
TCHAR szBuffer[256]; DWORD dwSemCount = 0; HANDLE hSemaphore = OpenSemaphore( SYNCHRONIZE, FALSE, "TEST SEMAPHORE");
wsprintf(szBuffer, "Thread %x waiting for semaphore %x", GetCurrentThreadId(), hSemaphore );
SendMessage(hWnd, WM_USER, 0, (LPARAM)szBuffer);
WaitForSingleObject( hSemaphore, INFINITE );
wsprintf(szBuffer, "Thread %x got semaphore", GetCurrentThreadId() );
SendMessage(hWnd, WM_USER, 0, (LPARAM)szBuffer);
Sleep(5000);
ReleaseSemaphore( hSemaphore, 1, (LPLONG)&dwSCount );
wsprintf( szBuffer, "Thread %x is done with semaphore. Its count was %ld.", GetCurrentThreadId(), dwSemCount );
SendMessage( hWnd, WM_USER, 0, (LPARAM)szBuffer );
CloseHandle( hSemaphore );
ExitThread ( TRUE );
}
And I am having 2 problems here:
-first, the dwSemCount value si always printed as 0, even if the semaphore works fine
-second, incrementing the counter with ReleaseSemaphore function from inside of thread doesn't working, I can't explain why.
Can you please help me with some advices?
Thank you very much,
|
|
|
|
|
|
Thank you Mircea,
I had changed the access rights for OpenSemaphore and the ReleaseSemaphore is working now.
Please help me and with the displaying of the semaphore counter:
ReleaseSemaphore( hSemaphore, 1, (LPLONG)&dwSCount );
wsprintf( szBuffer, "Thread %x is done with semaphore. Its count was %ld.", GetCurrentThreadId(), dwSemCount );
SendMessage( hWnd, WM_USER, 0, (LPARAM)szBuffer );
The displayed value of the dwSemCount is always 0, but it should be equal with the initial value, or with the decremented value, where is the mistake or where I am wrong?
Thank you,
|
|
|
|
|
Hmm, dwSCount vs dwSemCount . Could that be a typo?
Mircea
|
|
|
|
|
Good catch!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Sorry,
I made some test with SCount as global variable because of the problems, but yes, I had replaced this variable
and is ok now.
Thank you very much,
|
|
|
|
|
You should avoid using SendMessage form a worker to a main thread. It could lead to a deadlock. In most cases PostMessage is more preferable.
|
|
|
|
|
|
Hi
with the combobox it seems that drawitem function is only called after I click the icon of drop down.
My combobox displays with the first entry in the editbox (unformatted i.e. font and color).
Is there any to have drawitem invoked before it displays as I would like to format the entry in the edit control
Thanks
|
|
|
|
|
Perhaps your implementation/override of DrawItem is not complete?
Have a look at some of the CP articles describing the ownerdraw comboboxe, like this one:
Group Combo Box
|
|
|
|
|
Hi . Recently i've got to make a game called gomoku between two players and I don't know where to start. Could you please assist with the steps or at least a C++ code for the Gomoku game with comments so that I can at least be able to follow what has been coded.
|
|
|
|
|
The first thing you need to do is to study the game so you understand the rules. You can then start to figure out what each step of the game can do. From that you should be able to create a basic design document. Until you have done all that there is no point in thinking about actual code.
|
|
|
|
|
|
Hi
I put my ownerdraw code in a C dll upon exiting it I got a Security check stack overflow. I turned the /GS complier option off looked to work fine under VS debugger. The Calling code is MFC C/C++
The DLL is in C
Here is the MFC code
CMystatic::CMystatic()
{
width = 0;
mod = LoadLibrary(TEXT("C:\\SYSADATA\\SYSADATA\\x64\\Debug\\SYSADATA.DLL"));
drawptr = (fownerdraw)GetProcAddress(mod, "ownerdraw");
strsize.cx = 0;
strsize.cy = 0;
myexitparm = &exitparm;
}
void CMystatic::DrawItem(LPDRAWITEMSTRUCT pdi)
{
exitparm.pdi = pdi;
exitparm.sizeptr = &strsize;
(drawptr)(myexitparm);
}
Here is the C DLL
typedef struct EXITPARM
{
LPDRAWITEMSTRUCT pdi;
SIZE* sizeptr;
};
typedef struct EXITPARM* exitparmptr;
__declspec(dllexport) void ownerdraw(exitparmptr parmptr);
void ownerdraw(exitparmptr parmptr)
{
LPDRAWITEMSTRUCT pdi = parmptr->pdi;
SIZE* mysize = parmptr->sizeptr;
|
|
|
|
|
I never saw such an error/warning in my code.
What I see in your code snippet (and it is was I don't like) is this expression:
void ownerdraw(exitparmptr parmptr)
{
LPDRAWITEMSTRUCT pdi = parmptr->pdi;
What happens when the function argument parmptr is nullptr? Yes, the program crash!
|
|
|
|
|
Right upon exiting the C DLL it crashed really don’t think there is any stack storage corruption when I turned if /GS option all was okay
Just wondering going from inside a MFC C++ method to C DLL any special calling convention think__cedcl is the default
|
|
|
|
|
I have an block of code which already defined classes. And I want to define their cardinalization. Searched through the internet and books for 2 days but could not find anything. Please help me. Help my poor brain .
|
|
|
|
|
I haven’t encountered the notion of “cardinalization” in programming. The only thing close is “cardinality” and that refers to the number of objects of a certain class that are or can be created.
In this context the only frequently encountered case is the case of “singletons”, objects they you need to create only once (Google “C++ singleton” and you’ll find tons of information and examples). Otherwise there is no language construct that limits you to create only 3 or 10 objects of a certain class. It is up to your program to limit that.
Mircea
|
|
|
|
|
Member 15637771 wrote: And I want to define their cardinalization. I'm thinking the source of this requirement should be able to help you know what the word means (i.e., the overall intent).
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Member 15637771 wrote: I have an block of code which already defined classes. And I want to define their cardinalization. I think your question may be about object-oriented "one-to-one, one-to-many and many-to-many" C++ class/object relationships.
Cardinality (data modeling) - Wikipedia[^]
|
|
|
|
|
I have a number of ownerdraw controls and wanted to put the DrawItem function code in one function. Richard MacCutchan gave me the idea of moving code to my C DLL and have the Drawitem call it.
I had to remove a lot of MFC stuff to get the main body of code to my DLL most of it was straight forward except for Cwnd::GetStyle is the windows Call for that GetWindowLong(HWND,GWL_STYLE)
so for the CStatic Ownerdraw code which I have
DWORD dwStyle = phwnd->GetStyle();
if (dwStyle & SS_NOPREFIX)
nFormat |= DT_NOPREFIX;
LPDRAWITEMSTRUCT lpdi;
I could subsitute DWORD dwStyle = GetWindowLong(lpdi->hwndItem,GWL_STYLE);
|
|
|
|
|
Is there a question here?
|
|
|
|
|
Just wanted to know if getwindowlong GWL_STYLE is analogous CWnd::GetStyle
Thanks
|
|
|
|