Home » Community » Forums » For Beginners » Win32 API is Haaard help
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Win32 API is Haaard help
Post New Topic  Post Reply 
Ive been trying to set up a class for creating and registering a basic win32 application so i can work on my game , but im getting lots of errors... can u give me some advice on this?

// cApplication.h 
// Creates and Manages Win32 Window Application
// Armando Alva@2005

#ifndef CAPPLICATION_H__
#define CAPPLICATION_H__

#include <windows.h>
#include <iostream>

class cApplication
{
public:
	
	// Constructor Destructor
	cApplication();
	~cApplication();
	
	// WindowClassEx
	WNDCLASSEX wcex;
	// WindowHandle
	HWND hWnd;
	
	// Methods
	void CreateWnd();
	void RegisterWnd();

private:

}

#endif



// cApplication.cpp
// Definition for cApplication.h
// Armando Alva@2005

#include "cApplication.h"

// -----------------------------------------------------
// Constructor Destructor
// -----------------------------------------------------
cApplication()
{
	RegisterWnd();
	CreateWnd();
}

~cApplication()
{
	// Do Nothing (for now)
}

// -----------------------------------------------------
// RegisterWnd()
// -----------------------------------------------------
void cApplication::RegisterWnd()
{
	// Registering Window Class
	wcex.cbSize			= sizeof(WNDCLASSEX);
	wcex.style			= 0; 
	wcex.lpfnWndProc	= MsgProc; // Points to the name of the MsgProcedure funct.
	wcex.cbWndExtra		= 0L;
	wcex.cbClsExtra		= 0L;
	wcex.hInstance		= GetModuleHandle(NULL); // Or hInstance
	wcex.hIcon			= NULL;
	wcex.hCursor		= NULL;
	wcex.hbrBackground	= NULL;
	wcex.hIconSm		= NULL;
	wcex.lpszMenuName	= NULL;
	wcex.lpszClassName	= "Game Class";

	if(!RegisterClassEx(&wcex))
	{
		MessageBox(NULL, "Window Registration Failed!", "Error!", MB_OK);
	}

}

// -----------------------------------------------------
// CreateWnd()
// -----------------------------------------------------
void cApplication::CreateWnd()
{
	hWnd = CreateWindowEx(NULL, "Game Class", "Double Dragon Clone",
						  WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
						  NULL, NULL, wcex.hInstance, NULL);
}



// -----------------------------------------------------
// WinMain.cpp
// Application Main Starting Point
// Armando Alva@2005
// -----------------------------------------------------

#include <windows.h>
#include "cApplication.h"

INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, INT)
{
	cApplication TestApp;	
}



 User Rating: 980   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Can you post the errors please
so we can help more

 User Rating: 1104   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Not unless you tell us what the problem is

 User Rating: 1769   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I found it extremely hard as well, so i moved to wxWidgets. wxWidgets is marvellous quite frankly and i recommend it to anyone looking for a quick GUI.

Here is the linky.

Seriously, USE IT, it rocks.

Hope it helps you, im sure it will...

ace



 User Rating: 1737   |  Rate This User  Send Private MessageView ProfileView JournalView GD Showcase Entries Report this Post to a Moderator | Link

Ok only beacuse uve asked it

1>Compiling...
1>cApplication.cpp
1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(12) : error C3861: 'RegisterWnd': identifier not found
1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(13) : error C3861: 'CreateWnd': identifier not found
1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(16) : error C2588: '::~cApplication' : illegal global destructor
1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(17) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(17) : error C2556: 'int cApplication(void)' : overloaded function differs only by return type from 'cApplication cApplication(void)'
1>        c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(10) : see declaration of 'cApplication'
1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(17) : error C2371: 'cApplication' : redefinition; different basic types
1>        c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(10) : see declaration of 'cApplication'
1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(29) : error C2065: 'MsgProc' : undeclared identifier
1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(38) : error C2440: '=' : cannot convert from 'const char [11]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(42) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [28]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(54) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [11]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>WinMain.cpp
1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\winmain.cpp(10) : error C2143: syntax error : missing ';' before '__stdcall'
1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\winmain.cpp(10) : error C2377: 'INT' : redefinition; typedef cannot be overloaded with any other symbol
1>        c:\archivos de programa\microsoft visual studio 8\vc\include\windef.h(171) : see declaration of 'INT'
1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\winmain.cpp(10) : error C2061: syntax error : identifier 'INT'
1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\winmain.cpp(11) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\winmain.cpp(11) : error C2731: 'WinMain' : function cannot be overloaded
1>        c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\winmain.cpp(10) : see declaration of 'WinMain'
1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\winmain.cpp(13) : warning C4508: 'WinMain' : function should return a value; 'void' return type assumed
1>Generating Code...
1>Build log was saved at "file://c:\Documents and Settings\Armando Alva\Mis documentos\Visual Studio 2005\Projects\Double Dragon Clone\Double Dragon Clone\Debug\BuildLog.htm"
1>Double Dragon Clone - 15 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



 User Rating: 980   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Where and how is the MsgProc function defined?

Edit: You also need to prefix your constructor and destructor with "cApplication::", like this:
// -----------------------------------------------------
// Constructor Destructor
// -----------------------------------------------------
cApplication::cApplication()
{
	RegisterWnd();
	CreateWnd();
}

cApplication::~cApplication()
{
	// Do Nothing (for now)
}



 User Rating: 1688   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Quote:
Original post by CTar
Where and how is the MsgProc function defined?

Edit: You also need to prefix your constructor and destructor with "cApplication::", like this:
*** Source Snippet Removed ***



errr.. MsgProc is not defined yet , I just wanted to see if my code worked til now

 User Rating: 980   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Wow!
Only took a quick look but it seems that you don't have a
MsgProc
function. also winmain should return a value like:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
                    LPSTR lpCmdLine, int lpCmdShow)
{
.
.
.

    return msg.wParam;
}


 User Rating: 1104   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Thanks Ill work hard on this one
Ill post up my progress


 User Rating: 980   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by EvilNando
errr.. MsgProc is not defined yet , I just wanted to see if my code worked til now


Well it have to, look at this line:
wcex.lpfnWndProc = MsgProc;
How should it know what it should assign lpfnWndProc to? You'll have to create a MsgProc function, just a simple one to test if it works.

 User Rating: 1688   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Ok, I have got your code to work. You'll have to:
- Define MsgProc, maybe like this for a start:
LRESULT CALLBACK MsgProc(HWND pWindow,UINT pMsg,WPARAM pWParam ,LPARAM pLParam)
{
	return DefWindowProc(pWindow,pMsg,pWParam,pLParam);
}




- Add a ; after your declaration so that it looks like this:
class cApplication
{
public:
	
	// Constructor Destructor
	cApplication();
	~cApplication();
	
	// WindowClassEx
	WNDCLASSEX wcex;
	// WindowHandle
	HWND hWnd;
	
	// Methods
	void CreateWnd();
	void RegisterWnd();

private:
////////////////////////////////
////////////////////////////////
////////////////////////////////
// Notice the added ;
////////////////////////////////
////////////////////////////////
};




- Add "cApplication::" before your constructor and destructor, so it'll look like this:
cApplication::cApplication()
{
	RegisterWnd();
	CreateWnd();
}

cApplication::~cApplication()
{
	// Do Nothing (for now)
}



[Edited by - CTar on September 11, 2005 12:01:23 PM]

 User Rating: 1688   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Thanks a lot thanks thanks thanks

now my program just got down to 4 errors wich I presume are generated because of my stinking compiler.. do u know how I fix this?

>Compiling...
1>cApplication.cpp
1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(43) : error C2440: '=' : cannot convert from 'const char [11]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(47) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [28]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\armando alva\mis documentos\visual studio 2005\projects\double dragon clone\double dragon clone\capplication.cpp(59) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [11]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>WinMain.cpp
1>Generating Code...
1>Build log was saved at "file://c:\Documents and Settings\Armando Alva\Mis documentos\Visual Studio 2005\Projects\Double Dragon Clone\Double Dragon Clone\Debug\BuildLog.htm"
1>Double Dragon Clone - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========




and thanks again

 User Rating: 980   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Apparently, it's expecting unicode.

 User Rating: 1063   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

What do I have to do then?

 User Rating: 980   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I believe something like this should work (It's been a long time since I've done anything like this however).
wcex.lpszClassName	= L"Game Class";


If at first you don't succeed, redefine success.

 User Rating: 1552   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Yes u were right the L fixed the problem but is there a way to omit the L after every string I have to use?

 User Rating: 980   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may not post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: