|
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
|
|
|
|
|
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.
|
|
|
|
|
#include <stdio.h>
int main()
{
int i,j;
float pound, kilogram;
printf("Pound --------- Kilos\n\n");
do{
j=1;
do{
printf("%5d\t",i*j);
printf("%.2f lbs = %.2f Kg\n", pound, kilogram);
j++;
}while(j<=100);
printf("\n");
i++;
}while(i<=300);
return 0;
}
|
|
|
|