|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
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.
|
|
|
|
|
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
|
|
|
|
|
Yes it is. As with most MFC stuff, the code is just a wrapper for the Win32 SDK. In fact you could use the Win32 code in your MFC application to confirm that it returns exactly the same value.
|
|
|
|
|
Richard
When I first started on this endeavor I was a IBM Mainframe assembler programmer
I worked for software vendors and had job instability. I was told to expand my horizons. I choose windows then moved on to C\C++ albeit MFC
Along the way I got a job with federal government IRS. This helped alleviate
My job insecurity. Now I would rather use Windows C Win32 Sdk
I have or purchased thru Zpdt offering a personal z/os mainframe on my PC
The version I have allows me to sell software I write.
Most my data is from z/os i.e. big endian.
I display the results on windows via tcp sockets
Couldn’t of done this without your help
Thanks
|
|
|
|
|
My background was also in mainframes (Univac 1100/2200 series), using Assembler and their proprietary high level (C-like) language. I was recruited to my last position specifically because of that background experience. I then transitioned into C, C++ and Java on Unix and Windows systems. Since retiring I have stuck at it and tried to learn new languages/frameworks (Android, C#, .NET, Python, SQL ...) for my own amusement. Much of my knowledge has been gained from articles here on CodeProject and elsewhere, and the help of other experts. So I could not have helped you without the help I received. After all, that is why most of us stick around here.
Thanks for your kind comments. And, as always, happy to help where I can.
|
|
|
|