|
|
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;
}
|
|
|
|
|
Start by indenting your code so it's readable:
#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;
} It makes it so much more obvious what is going on.
Then look at your code: where do you modify pound or kilogram ?
Since they do not change, it will always print the same values.
By the way, a better loop format for your application would be a for loop:
for (int i = 0; i <= 300; i++)
{
for (int j = 1; j <= 100; j++)
{
...
}
} Since you don't initialize i in your code at all, the value can be random depending on which compiler and / or compiler options you use.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
i try for loop you suggest
code:
#include <stdio.h>
# define POUNDTOKG 0.453592;
int main()
{
int i,j;
float pound, kilogram;
printf("Pound --------- Kilos\n\n");
for (int i = 0; i <= 300; i++)
{
for (int j = 1; j <= 100; j++)
{
kilogram = pound * POUNDTOKG;
}
printf("%.2f pound = %.2f Kilogram\n", pound, kilogram);
}
return 0;
}
but my expected output is like this,
======================
Pounds Kilos
======================
100.00 45.45
101.00 45.91
120.00 46.36
103.00 46.62
104.00 47.27
105.00 ........
.
.
.
300.00 136.08
but thanks
|
|
|
|
|
You never initialize the pound variable, so it will always have the same (random) value.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Can't you make simpler? Like this?
Hm, this was not supposed to be a reply to Richard, but to the OP. Sorry.
#include <stdio.h>
#define POUNDTOKG 0.453592
int main() {
printf("Pound --------- Kilos\n\n");
for (int pound = 100; pound <= 300; pound++) {
printf("%.2f pound = %.2f Kilogram\n", pound, pound * POUNDTOKG);
}
return 0;
}
modified 12-May-22 7:50am.
|
|
|
|
|
thanks, but i want like this output below, but when I run it in dev C++, pounds is not start 100 only kilos has a value I want to put 100 to 300 but how can I do that. but thanks a lot
======================
Pounds Kilos
======================
100.00 45.45
101.00 45.91
120.00 46.36
103.00 46.62
104.00 47.27
105.00 ........
|
|
|
|
|
your code is almost correct but in pound there is a no 100 to 300, how can I put it in my code, but thanks a lot
|
|
|
|
|
Well it is, kindof. The format specfier to printf is wrong.
Try this
#include <stdio.h>
#define POUNDTOKG 0.453592
int main() {
printf("Pound --------- Kilos\n\n");
for (int pound = 100; pound <= 300; pound++) {
printf("%d pound = %.2f Kilogram\n", pound, pound * POUNDTOKG);
}
return 0;
}
Pound --------- Kilos
100 pound = 45.36 Kilogram
101 pound = 45.81 Kilogram
102 pound = 46.27 Kilogram
103 pound = 46.72 Kilogram
...
298 pound = 135.17 Kilogram
299 pound = 135.62 Kilogram
300 pound = 136.08 Kilogram
...Program finished with exit code 0
Press ENTER to exit console.
|
|
|
|
|
That's great, thanks a lot for your help and finally I will pass my pre-final exam in c programming, thank you
|
|
|
|
|
it doesn't work setwindowsHookEx(), Getkeystate() and GetCursorPos().
please help me.
modified 12-May-22 0:51am.
|
|
|
|
|
Windows service applications do not have consoles so have no access to input or output devices.
|
|
|
|