NO

Author Topic: Warning without preventing a successful compile  (Read 3081 times)

David L Morris

  • Guest
Warning without preventing a successful compile
« on: June 04, 2011, 07:13:14 AM »
I have converted a C++ example which compiles and runs ok but presents this warning. 

Building exercise.obj.
C:\Users\David\Documents\Pelles C Projects\CompoundInterest\exercise.c(21): warning #2168: Operands of '=' have incompatible types 'int __stdcall function(HWND, unsigned int, unsigned int, long int)' and 'long int __stdcall function(HWND, unsigned int, unsigned int, long int)'.
Building CompoundInterest.exe.
Done.

The portion of code applicable appears to be:-

#define WIN32_LEAN_AND_MEAN
/* #define NOCRYPT */
/* #define NOSERVICE */
/* #define NOMCX */
/* #define NOIME */
#include <windows.h>
#include <commctrl.h>
#include "Resource.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
//---------------------------------------------------------------------------
HWND hWnd;
LRESULT CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
//---------------------------------------------------------------------------
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
               LPSTR lpCmdLine, int nCmdShow)
{
//      DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN_DLG),
//             hWnd, reinterpret_cast<DLGPROC>(DlgProc));
   return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN_DLG), 0, DlgProc);

//   return FALSE;
}
//---------------------------------------------------------------------------
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
   // These variables will carry the values in the text boxes
   /*LPTSTR strPrincipal = new char[20],
        strInterest = new char[20], strPeriods = new char[20],
         strInterestEarned = new char[20], strAmountEarned = new char[20];
   */
   char strPrincipal[20],strInterest[20], strPeriods[20],
         strInterestEarned[20], strAmountEarned[20];
   // These are handled for the various controls
   HWND hWndPrincipal, hWndInterest, hWndPeriods, hWndCompound,
       hWndInterestEarned, hWndAmountEarned, hWndCalculate;

   double Principal, AnnualRate, InterestEarned;
   double FutureValue, RatePerPeriod;
   int    NumberOfPeriods, CompoundType;
   double i;
   int n;

   hWndPrincipal      = GetDlgItem(hWndDlg, IDC_PRINCIPAL);
   hWndInterest       = GetDlgItem(hWndDlg, IDC_ANNUAL_RATE);
   hWndPeriods        = GetDlgItem(hWndDlg, IDC_NBR_OF_PERIODS);
   hWndCompound       = GetDlgItem(hWndDlg, IDC_COMPOUND);
   hWndInterestEarned = GetDlgItem(hWndDlg, IDC_INTEREST_EARNED);
   hWndAmountEarned   = GetDlgItem(hWndDlg, IDC_AMOUNT_EARNED);
   hWndCalculate      = GetDlgItem(hWndDlg, IDC_CALCULATE_BTN);

Any hints would be appreciated. 

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Warning without preventing a successful compile
« Reply #1 on: June 04, 2011, 08:23:51 AM »
Just cast that DlgProc function:
Code: [Select]
return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN_DLG), 0, (DLGPROC)DlgProc);
May the source be with you

David L Morris

  • Guest
Re: Warning without preventing a successful compile
« Reply #2 on: June 04, 2011, 10:00:00 AM »
Thanks timovl that works. I wonder how someone new to C and winapi would get to know that solution? Should I have seen a hint from the C++ code "reinterpret_cast<DLGPROC>(DlgProc));"?