Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

johnc82

Don't Know Why

This topic is 5382 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi... My Code:
#include <windows.h>
#include <d3d8.h>
#include <iostream>
using namespace std;


LRESULT CALLBACK MainMsg(HWND, UINT, LPARAM, WPARAM);
bool RegisterWinClass(HINSTANCE, WNDPROC, LPSTR);
bool CreateWin(HWND&, HINSTANCE, LPSTR, LPSTR);
WPARAM MainLoop();
bool Inti(HWND&);
bool DestroyWin();
void ClearUp();
void Render();


HWND g_hWnd = NULL;
HDC g_hDc = NULL;


LPDIRECT3D8 g_pD3d = NULL;
LPDIRECT3DDEVICE8 g_pD3ddevice = NULL;



int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
				   LPSTR lpstrCmdLine, int iCmdShow)
{
	if(!RegisterWinClass(hInstance, MainMsg, "DXTest"))
	{
		return -1;
	}
	
	CreateWin(g_hWnd, hInstance, "DXTest", "Direct X Test");
    
	Inti(g_hWnd);

	ShowWindow(g_hWnd, SW_SHOWDEFAULT);
	UpdateWindow(g_hWnd);

	return (int)MainLoop();
}


LRESULT CALLBACK MainMsg(HWND hWnd, UINT uiMsg, LPARAM lParam, 
						 WPARAM wParam)
{
	switch(uiMsg)
	{
		case WM_PAINT:
			{
				Render();
				ValidateRect(g_hWnd, NULL);
				break;
            }
		case WM_CREATE:
			{
				break;
			}
		case WM_CLOSE:
			{
				PostQuitMessage(0);
				break;
			}
		case WM_DESTROY:
			{
				break;
			}
		default:
			{
				break;
			}
	}

	return DefWindowProc(hWnd, uiMsg, lParam, wParam);
}


bool RegisterWinClass(HINSTANCE hInstance, WNDPROC wndProc, LPSTR className)
{
	WNDCLASSEX wcx;

	wcx.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	wcx.cbSize = sizeof(WNDCLASSEX);
	wcx.hInstance = hInstance;
	wcx.lpfnWndProc = wndProc;
	wcx.lpszClassName = className;

	wcx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
	wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wcx.hIconSm = LoadIcon(NULL, IDI_WINLOGO);

	wcx.cbClsExtra = NULL;
	wcx.cbWndExtra = NULL;
	wcx.lpszMenuName = NULL;

	if(!RegisterClassEx(&wcx))
	{
		return false;
	}

	return true;
}


bool CreateWin(HWND &hWnd, HINSTANCE hInstance, LPSTR className, 
			   LPSTR winCaption)
{
	hWnd = CreateWindowEx(NULL,
						  className,
						  winCaption,
						  WS_OVERLAPPEDWINDOW,
						  0,
						  0,
						  CW_USEDEFAULT,
						  CW_USEDEFAULT,
						  NULL,
						  NULL,
						  hInstance,
						  NULL);

	if(!hWnd)
	{
		return false;
	}

	return true;
}


WPARAM MainLoop()
{
	MSG msg;
	bool done = false;

	while(!done)
	{
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if(msg.message == WM_QUIT)
			{
				done = true;
				break;
			}

			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{

		}

	}
	
	ClearUp();

	return msg.wParam;
}
Error:
c:\Dev\WinDXTest\main.cpp(25): error C2664: 'RegisterWinClass' : cannot convert parameter 2 from 'LRESULT (HWND,UINT,LPARAM,WPARAM)' to 'WNDPROC'
 
So far as I program it never happen before....... [edited by - johnc82 on November 15, 2003 12:46:42 PM]

Share this post


Link to post
Share on other sites
Advertisement
DANG!!!

Another sudden error.............

Code:


#include <d3d8.h>
#include <iostream>
using namespace std;

bool RegisterWinClass(HINSTANCE, WNDPROC, LPSTR);
bool CreateWin(HWND&, HINSTANCE, LPSTR, LPSTR);
LRESULT CALLBACK MainMsg(HWND, UINT, WPARAM, LPARAM);
WPARAM MainLoop();
bool Inti(HWND&);
bool DestroyWin();
void ClearUp();
void Render();

HWND g_hWnd = NULL;
HDC g_hDc = NULL;

LPDIRECT3D8 g_pD3d = NULL;
LPDIRECT3DDEVICE8 g_pD3ddevice = NULL;


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpstrCmdLine, int iCmdShow)
{
if(!RegisterWinClass(hInstance, MainMsg, "DXTest"))
{
return -1;
}

//The Error come from CreateWin() funtion...
if(!CreateWin(g_hWnd, hInstance, "DXTest", "DirectXTest"))
{
return -2;
}

if(!Inti(g_hWnd))
{
return -3;
}

ShowWindow(g_hWnd, SW_SHOWDEFAULT);
UpdateWindow(g_hWnd);

return (int)MainLoop();
}

bool RegisterWinClass(HINSTANCE hInstance, WNDPROC wndProc,
LPSTR className)
{
WNDCLASSEX wcx;

wcx.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wcx.cbSize = sizeof(WNDCLASSEX);
wcx.hInstance = hInstance;
wcx.lpfnWndProc = wndProc;
wcx.lpszClassName = className;

wcx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcx.hIconSm = LoadIcon(NULL, IDI_WINLOGO);

wcx.cbClsExtra = NULL;
wcx.cbWndExtra = NULL;
wcx.lpszMenuName = NULL;

if(!RegisterClassEx(&wcx))
{
return false;
}

return true;
}

bool CreateWin(HWND &hWnd, HINSTANCE hInstance, LPSTR className,
LPSTR winCaption)
{
hWnd = CreateWindowEx(NULL,
className,
winCaption,
WS_OVERLAPPEDWINDOW,
0,
0,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);

if(!hWnd)
{
return false;
}

return true;
}


Another unknow problem

Error:

The program ''[1492] WinDXTest.exe: Native'' has exited with code -2 (0xfffffffe).

Share this post


Link to post
Share on other sites
hey...i''ve had the same problem before with it set up correctly, why did I have to cast to get it to work? I didn''t look at his code, I just know I''ve had the same problem.

Share this post


Link to post
Share on other sites
Ya... I manage to fix the problem ... is either the compiler or the entire Visual Studio gone nuts.......

[edited by - johnc82 on November 18, 2003 10:49:23 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!