Hello, I'm a new programmer and wanted to create a simple windows application. I might be getting in a little over my head when writing the code below. All seems well when compiling the code without implementing classes. When I implemented the class AppEngine from a separate source file I had these errors that I could not resolve. I came to two conclusions of what I was doing wrong and was hoping that someone could point me in the right direction.

Conclusion 1 - I incorrectly included the source files during compile
Conclusion 2 - I was in over my head and should not attempt windows programming just yet.

The errors I'm receiving are:
Line 12 : new types may not be defined in a return type
Line 4 : requires init-declaration before LRESULT WindowProcedure

I use DEV C++ IDE and these the codes that gets the error.

1 #include <windows.h>
2 #include "DCPPPClasses.h"
3
4 LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT 5 message, WPARAM wParam, LPARAM lParam);
6
7 AppEngine *_pAE;
8
9 _pAE = new AppEngine(HINSTANCE, LPSTR, LPSTR, WORD, 10 WORD, int, int);
11
12 int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevi, 13 LPSTR szcmdline, int icmdshow)
14 {
15 }

I would like to know what those error means and how to fix them. Thanks in advance. Sadaka

If poking it with a stick doesn't work for you. Try poking it with a bigger one.

how bout using a better api? qt or gtk are much easier.

Comments
answer the question. There is nothing wrong with the WinAPI.

line 4: LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT 5 message, WPARAM wParam, LPARAM lParam);
line 9: _pAE = new AppEngine(HINSTANCE, LPSTR, LPSTR, WORD, 10 WORD, int, int);

these are the errors. the compiler/ide you are using seems to emit very poor error messages.

That's what you get when you copy-paste code... De lines got messed up, and now the linenumbers are in your code:
In line 4: Remove '5'
In line 9: Remove '10'
In line 12: Remove '13'

Edited 6 Years Ago by Nick Evan: n/a

I added the numbers to indicated the line. I thought it would help indicate which line generated the errors. I figured that I included the external source files incorrectly and that the complier didn't recognize any of my class calls hence error : new types may not be define in a return type. I want to know what that error means because I tried everything I could think of to resolve it but in vain. Next time I'll just attach my source files so there won't be any confusions. Sorry. Thanks again in advance.

Things aren't always what it seems my young grasshopper...

check the header DCPPPClasses.h for a missing ; at the end of the class, mismatched (), {} etc.
line 9: _pAE = new AppEngine(HINSTANCE, LPSTR, LPSTR, WORD, 10 WORD, int, int); is an obvious error on many counts.

oh yes duh... i'm such a dueche bag that's what I left out after the class. Thanks alot bro. i've attached my source if you want to look them over. Thanks again. I've also made changes to the class and added the colon (;). Think that I can attach stuff?

A good deed will not go unnoticed. -Sun Tsu

Attachments
//This is the source of main
#include <windows.h>
#include "DCPPP4.h"

//Prototype
LRESULT CALLBACK t1f_windproc(HWND, UINT, WPARAM, LPARAM);

//Main
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprevi, LPSTR szcmd, int ishow)
{
 MSG msg;
 static int iTickTrigger = 0;
 int iTickCount;
 
 if(EngineOn(hinst)
 {
  if(!EngineBlock::UnderHood()->Initialize(ishow))
  {
   return 0;
  }
  
  while(1)
  {
   if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
   {
    if(msg.message == WM_QUIT)
    {
     break;
    }
    
    TranslateMessage(&msg);
    DispatchMessage(&msg);
   }else
   {
    iTickCount = GetTickCount();
    if(iTickCount > iTickTrigger)
    {
     EngineIterate();
    }
   }
   return (int)msg.wParam;
  }
  EngineOff();
  return 1;
}

//Window procedure
LRESULT CALLBACK t1f_windproc(HWND winhando, UINT msg, WPARAM wparam, LPARAM lparam)
{
 HDC hdc;
 PAINTSTRUCT ps;
 RECT rect;
 
 switch(msg)
 {
  case WM_PAINT:
       hdc = BeginPaint(winhando, &ps);
       GetClientRect(winhando, &rect);
       DrawText(hdc, TEXT("Success"), -1, &rect, DT_SINGLELINE);
       EndPaint(winhando, &ps);
       return 0;
       
  case WM_DESTROY:
       PostQuitMessage(0);
       return 0;
  }
  return DefWindowProc(winhando, msg, wparam, lparam);
}

bool EngineOn(HINSTANCE hinst)
{
 _pEngine = new EngineBlock(hinst, TEXT("Success"), TEXT("Success"), IDI_APPLICATION, IDI_APPLICATION);
 if(_pEngine == NULL)
 {
  return false;
 }
 return true;
}

void EngineGo()
{
 srand(GetTickCount());
}

void EngineOff()
{
 delete _pEngine;
}

void FuelEngine(HDC hdc)
{
 //Does some changes
}

void EngineIterate()
{
 HDC hdc;
 HWND winhando = _pEngine->UnderHood();
 
 hdc = GetDC(winhando);
 DrawIcon(hdc, rand() % _pEngine->LeakWidth(), rand() % _pEngine->LeakHeight(), \
 (HICON)(WORD)GetClassLong(winhando, GCL_HICON));
 ReleaseDC(winhando, hdc);
}

//This function from the class refreshes the application with new changes
LRESULT CALLBACK EngineBlock::FuelControl(HWND winhando, UINT msg, WPARAM wparam, LPARAM lparam)
{
 switch(msg)
 {
  case WM_CREATE:
       LockFrame(winhando); //winhando is an HWND
       EngineGo(winhando);
       return 0;

  case WM_PAINT:
       HDC hdc;
       PAINTSTRUCT ps;
       hdc = BeginPaint(winhando, &ps);
       
       FuelEngine(hdc); //Changes the application data
       
       EndPaint(winhando, &ps);
       return 0;

  case WM_DESTROY:
       EngineOff();
       PostQuitMessage(0);
       return 0;
       }
       return DefWindowProc(winhando, msg, wparam, lparam);
}

//class definition temporarily here so to not have more than two sources
bool EngineBlock::Ignition(int ishow)
{
         static TCHAR szName[] = TEXT("Window Application");
         WNDCLASSEX winclassex;
         HWND winhando;
         MSG msg;

         winclassex.cbSize = sizeof(winclassex);
         winclassex.style = CS_HREDRAW | CS_VREDRAW;
         winclassex.lpfnWndProc = t1f_windproc;
         winclassex.cbClsExtra = 0;
         winclassex.cbWndExtra = 0;
         winclassex.hInstance = hinst;
         winclassex.hIcon = NULL;
         winclassex.hIconSm = NULL;
         winclassex.hCursor = LoadCursor(NULL, IDC_ARROW);
         winclassex.hbrBackground = (HBRUSH)(BLACK_BRUSH);
         winclassex.lpszMenuName = NULL;
         winclassex.lpszClassName = szName;

         if(!RegisterClassEx(&winclassex))
         {
          return false;
         }
         
         //creates the application window
         winhando = CreateWindow(szName, szName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hinst, NULL);
         if(!cm_winhando)
         {
          return false;
         }

  ShowWindow(winhando, ishow);
  UpdateWindow(winhando);

  return true;
}
//Header source for the class and definitions
#include <windows.h>

#ifndef DCPPP4_H
#define DCPPP4_H

bool EngineOn(HINSTANCE hinst); //Initializes the window application
void EngineOff(); //Kills the application
void EngineGo(HWND hwnd); //The body of the application
void FuelEngine(); // Receives inputs and messages to continue the application

//Below is class and class definition
class EngineBlock
{
 protected:
           static EngineBlock *cmp_Engine;
           HINSTANCE cm_hinst;
           HWND cm_winhando;
           TCHAR cm_szclass[32];
           TCHAR cm_sztitle[32];
           WORD cm_wicon, cm_wiconsm;
           int cm_iwidth, cm_iheight;
 public:
        //Constructors- class automatically calls this function to execute once initiated
        EngineBlock(HINSTANCE hinst, LPSTR szclass, LPSTR sztitle, WORD wicon, WORD wiconsm, int iwidth = 640, int iheight = 480)
        {
          //Sets the members with values
          cmp_Engine = this;
          cm_hinst = hinst;
          cm_winhando = NULL;
          if(lstrlen(szclass)>0)
          {
           lstrcpy(cm_szclass, szclass);
          }
          if(lstrlen(sztitle)>0)
          {
           lstrcpy(cm_sztitle, sztitle);
          }
          cm_wicon = wicon;
          cm_wiconsm = wiconsm;
          cm_iwidth = iwidth;
          cm_iheight = iheight;;//(HINSTANCE hinst, LPSTR szclass, LPSTR sztitle, WORD wicon, WORD wiconsm, int iwidth = 640, int iheight = 480);
        }
        //Destructor- still need to know which is convenient virtual or no.
        //I use no till I can get more 411 on virtual destructors
        ~EngineBlock();

        //Derived classes will possess UnderHood - This function returns an address when called
        static EngineBlock* UnderHood(){ return cmp_Engine;};
        bool Ignition(int ishow);
        LRESULT FuelControl(HWND winhando, UINT msg, WPARAM wparam, LPARAM lparam);

        //Leaks and Settings - Defined inside the class
        HINSTANCE LeakInstance(){return cm_hinst;};
        HWND LeakHando(){return cm_winhando;};
        void LockFrame(HWND winhando){cm_winhando = winhando;};
        LPSTR LeakTitle(){return cm_sztitle;};
        WORD LeakIcon(){return cm_wicon;};
        WORD LeakIconSm(){return cm_wiconsm;};
        int LeakWidth(){return cm_iwidth;};
        int LeakHeight(){return cm_iheight;};
};

EngineBlock* _pEngine;
#endif
This question has already been answered. Start a new discussion instead.