NO

Author Topic: Using incompatible types 'int __stdcall (*)(...) and 'long long int __stdcall (.  (Read 7287 times)

finzi

  • Guest
Hello,
I'm new in PellesC.
I'm using it to move my old programs form 32 to 64 bit.
Some of thes have problem at run time: i get an exception C000041D (don't know that is that).
The only significant worning while building is relevant to window or dialog creation:
warning #2145: Using incompatible types 'int __stdcall (*)(HWND, unsigned int, unsigned long long int, long long int)' and 'long long int __stdcall (*)(HWND, unsigned int, unsigned long long int, long long int)'.

Any suggestion?
Thanks,
Andrea

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Hello welcome  :)
32 and 64 bits versions of MS compiler have different sizes for standard types (i.e. a 'long' is 32 bits in 32bits compilation, and 64bits in 64bit case).
To compile one to one for 32 and 64 bits you must apply some small fixes, avoid to use basic types, and use predefined ones (DWORD, DWORD_PTR, INT, INT_PTR, etc.)
In your specific case give us more info, a code sample (short please!), to have a more detailed answer.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

finzi

  • Guest
Thank for the prompt reply   :)

The program is big and confused (I started developping it while learning C .....).
It is a finite element model viewer based on OpenGL.
It includes a menu system, and here is the problem:
the second call the the routine managing the menu (starting the second menu) generate the access violation, calling CreateWindow.

In 32 bit everythink worck fine.
 
Annex. the routine and the structure where menue information are store.

Thank you very much for the support,
Andrea

Code: [Select]
int ReturnMenu(F_menu *m)
{
static unsigned int   first=0;
hInst=GetModuleHandle(NULL);

if(!first){
base_color=CreateSolidBrush(m->base_color);
if(InitMenu()){
first=1;
Menu_level=0;
}
}
else{
if(Menu_level==DLGINPUT_MAX_level-1){
MessageBox(m->parent,"Too many menu levels!","MENU",MB_OK);
return 0;
}
Menu_level++;
}

ghF_menu[Menu_level]=m;

if(m->Prop==0){
gProp=1;
}
else if(m->Prop<0){
gProp=-1.0/m->Prop;
}
else{
gProp=m->Prop;
}
gWidth=(m->Width-3*spazio)*gProp/(gProp+1);

gParent=m->parent;
strcpy(gitem_description,m->comando);
strcpy(gresults,m->inizio);

Menu_ID[Menu_level]=m->menu_id;
Menu_Type[Menu_level]=m->menu_type;
if(m->wtitle)strcpy(gwtitle[Menu_level],m->wtitle);
if(m->min_lines)gmin_lines=m->min_lines;


        //Here the access violation generates
hwndMenus[Menu_level]=CreateWindow("win_menu",m->wtitle,
WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_TABSTOP|WS_BORDER,
m->x,m->y,200,200,
m->parent,
NULL,
hInst,
NULL);

                 if(Menu_level)ShowWindow(hwndMenus[Menu_level-1], SW_HIDE);

return (int)hwndMenus[Menu_level];
}

// Menu
typedef struct tagF_menu {
char wtitle[80];
int menu_id;
int menu_type;
char comando[DLGINPUT_MAX];
char inizio[DLGINPUT_MAX];
char risultato[DLGINPUT_MAX];
int Width;
int Prop;
HWND parent;
int x;
int y;
int min_lines;
int docking;
COLORREF base_color;
} F_menu;

static HWND hwndMenus[DLGINPUT_MAX_level];

« Last Edit: September 18, 2019, 10:26:25 AM by frankie »

finzi

  • Guest
Example

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
How is defined 'hinst'?
Why you cast 'HWND' types to int?
These are incorrect also in 32bits programming. It could eventually work if, in 32bits, those types are <= 32bits wide.
Use the correct types:
Code: [Select]
HWND ReturnMenu(F_menu *m)
{
static unsigned int   first=0;
HINST  hInst=GetModuleHandle(NULL);

if(!first){
base_color=CreateSolidBrush(m->base_color);
if(InitMenu()){
first=1;
Menu_level=0;
}
}
else{
if(Menu_level==DLGINPUT_MAX_level-1){
MessageBox(m->parent,"Too many menu levels!","MENU",MB_OK);
return 0;
}
Menu_level++;
}

ghF_menu[Menu_level]=m;

if(m->Prop==0){
gProp=1;
}
else if(m->Prop<0){
gProp=-1.0/m->Prop;
}
else{
gProp=m->Prop;
}
gWidth=(m->Width-3*spazio)*gProp/(gProp+1);

gParent=m->parent;
strcpy(gitem_description,m->comando);
strcpy(gresults,m->inizio);

Menu_ID[Menu_level]=m->menu_id;
Menu_Type[Menu_level]=m->menu_type;
if(m->wtitle)strcpy(gwtitle[Menu_level],m->wtitle);
if(m->min_lines)gmin_lines=m->min_lines;


        //Here the access violation generates
hwndMenus[Menu_level]=CreateWindow("win_menu",m->wtitle,
WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_TABSTOP|WS_BORDER,
m->x,m->y,200,200,
m->parent,
NULL,
hInst,
NULL);

                 if(Menu_level)
                     ShowWindow(hwndMenus[Menu_level-1], SW_HIDE);

return hwndMenus[Menu_level];
}
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

finzi

  • Guest
Thanks again.
I fixed according to you indication, notthin changed.
I think I must review the all code to find all thes errors. :-[

After that, what shall I change to INT_PTR, INT, ..... all varibles (respectively) or only pointers?

And "Using incompatible types" means that = have differnt tipes on the two sides?

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Warnings are your friends...
Observe all warnings coming out from compilation, better one module at time, and eventually enable LEVEL2 warnings.
They give you a lot of information. I.e. the warning:
Code: [Select]
warning #2145: Using incompatible types 'int __stdcall (*)(HWND, unsigned int, unsigned long long int, long long int)' and 'long long int __stdcall (*)(HWND, unsigned int, unsigned long long int, long long int)'
Is telling you that you tried to assign to a pointer to a function that takes an HWND, an unsigned int, an unsigned long long, a long long, and returns a long long int a pointer to a function that takes the same arguments, but returns an int.
If the value returned is a pointer to memory, i.e. the original type was 'UINT_PTR' or 'DWORD_PTR' or the like (that reduces to a basic long long int on a 64 bits system and to a long int on a 32bits system), the conversion from long long to int, that will happen on a 64bits system, truncate the upper significant 32bits supplying an invalid pointer value. On a 32bits it could work, while not syntactically correct, because int and pointer have same width, 32bits, so no value modification will apply.
I.e. if the long long value was 0x0000123456781234, converted to int becomes 0x56781234 that eventually points to an invalid memory region, or worst to a valid region, corrupting data contained.
The last case is even more poisonus because your program will fail elsewhere from the point were is located the error making absolutely crazy any debug.
« Last Edit: September 18, 2019, 12:30:42 PM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

finzi

  • Guest
Yes I understand the meaning but where is the error.
For example, I get the warning here:
   
Code: [Select]
switch(id) {
case IDM_ABOUT:
[b]DialogBox(hInst,MAKEINTRESOURCE(IDD_ABOUT), hwndMain,AboutDlg);[/b]                                                .....

Where is the error? did I #include wrong files?

Thank for patience.....

finzi

  • Guest
Sorry I unrestood: AboutDlg wrong type  :-[

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
In this case the problem is in the declaration of the dialog box callback procedure.
It is prototyped as:
Code: [Select]
INT_PTR Dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
Maybe you coded it as:
Code: [Select]
BOOL Dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
    ....
}
In this case you will have no warnings compiling for 32bits system, but for 64bits you'll get:
Code: [Select]
warning #2145: Using incompatible types 'int __stdcall (*)(HWND, unsigned int, unsigned long long int, long long int)' and 'long long int __stdcall (*)(HWND, unsigned int, unsigned long long int, long long int)'
This is due to a change in the return value starting from Win7_SDK I think.
Changing accordingly you'll remove the warning, and it will compile correctly for both systems 32 and 64. Anyway this one don't should lead to a memory violation  :(.
As a suggestion right clicking on system functions and choosing 'go to definition' from the popup-menu should open the header file where it is defined so you can check the correct declaration.
Good luck
« Last Edit: September 18, 2019, 03:33:34 PM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

finzi

  • Guest
Thanks very much for the lessons. :)
I will try to fix all warnings. (I need days ...)
Andrea