Sign in to follow this  

Noob question: setting up DDraw with Dev-C++

This topic is 4715 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

I have this source
#define WIN32_LEAN_AND_MEAN
#define INITGUID 

#include <windows.h>
#include <windowsx.h>
#include <ddraw.h>

LPDIRECTDRAW lpdd = 0;

const TCHAR class_name[] = TEXT("Direct Draw");

inline bool keyUp(int key)			{ return !(GetAsyncKeyState(key) & 0x8000);	}
inline bool keyDown(int key)		{ return  (GetAsyncKeyState(key) & 0x8000);	}

LRESULT CALLBACK wndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR cmdLine, int cmdShow)
{ 	
 	WNDCLASSEX wndclsEx;
 	
 	wndclsEx.hInstance		= hInstance;
 	wndclsEx.lpfnWndProc	= wndProc;
 	wndclsEx.style			= CS_HREDRAW | CS_VREDRAW;
 	
 	wndclsEx.hCursor		= LoadCursor(0, IDC_ARROW);
 	wndclsEx.hIcon			= LoadIcon(0, IDI_APPLICATION);
 	wndclsEx.hIconSm		= LoadIcon(0, IDI_WINLOGO);
 	wndclsEx.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
 	
 	wndclsEx.lpszMenuName	= 0; 
 	wndclsEx.lpszClassName	= class_name;
 	
 	wndclsEx.cbSize			= sizeof(WNDCLASSEX);
 	wndclsEx.cbWndExtra		= 0;
 	wndclsEx.cbClsExtra		= 0;
 	
 	if (!RegisterClassEx(&wndclsEx))
 	{
		MessageBox(0, TEXT("Could not register window class."), class_name, MB_OK | MB_ICONERROR);
		
		return 1;
	}
	
	HWND hWnd = CreateWindowEx(0, class_name, TEXT("Not much"), WS_CAPTION | WS_SYSMENU, 
		 	  					  CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, 
								  0, 0, hInstance, 0);
	
    ShowWindow(hWnd, cmdShow);
    UpdateWindow(hWnd);
    
    DirectDrawCreate(0, &lpdd, 0);
    
    MSG msg;
    
    while (1)
    {
 	    if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
 	    {
		    if (msg.message == WM_QUIT)
	     	    break;
	     	    
 	        TranslateMessage(&msg);
 	        DispatchMessage(&msg);
		}
		else
		{
		 	if (keyDown(VK_ESCAPE))
		 	    SendMessage(hWnd, WM_CLOSE, 0, 0);
		}
	}
	
	UnregisterClass(class_name, hInstance);
	
	return msg.wParam;
}

LRESULT CALLBACK wndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {	  	
    case WM_CLOSE: 
		 
		if (MessageBox(hWnd, TEXT("Are you sure you want to close"), class_name, MB_YESNO |
		   					 		   	   				 			 MB_ICONWARNING) == IDYES)
		    SendMessage(hWnd, WM_DESTROY, 0, 0);
			
		return 0;
		   
    case WM_DESTROY:
		 
        PostQuitMessage(0);
        
        return 0;
	}
	
	return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
and I also included the .lib in my project (Project Options -> Parameters -> Included library or object (ddraw.lib), but it still gives me an undefined Reference for DirectDrawCreate. Any help would be appreciated =)

Share this post


Link to post
Share on other sites
btw, what libraries do I need to include to use CoInitialize?

Also, what library do I include for CreateDirectDrawEx?

I'm getting undefined references all the time...

Share this post


Link to post
Share on other sites
To make my questions more clear, here are the programs and the errors
(using DevC++)

Undefined Reference to CreateDirectDrawEx

#define WIN32_LEAN_AND_MEAN
#define INITGUID

#include <windows.h>
#include <windowsx.h>
#include <ddraw.h>

#define null_ptr 0

LPDIRECTDRAW lpdd7 = null_ptr;

const TCHAR class_name[] = TEXT("Direct Draw");

inline bool keyUp(int key) { return !(GetAsyncKeyState(key) & 0x8000); }
inline bool keyDown(int key) { return (GetAsyncKeyState(key) & 0x8000); }

LRESULT CALLBACK wndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR cmdLine, int cmdShow)
{
WNDCLASSEX wndclsEx;

wndclsEx.hInstance = hInstance;
wndclsEx.lpfnWndProc = wndProc;
wndclsEx.style = CS_HREDRAW | CS_VREDRAW;

wndclsEx.hCursor = LoadCursor(0, IDC_ARROW);
wndclsEx.hIcon = LoadIcon(0, IDI_APPLICATION);
wndclsEx.hIconSm = LoadIcon(0, IDI_WINLOGO);
wndclsEx.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);

wndclsEx.lpszMenuName = 0;
wndclsEx.lpszClassName = class_name;

wndclsEx.cbSize = sizeof(WNDCLASSEX);
wndclsEx.cbWndExtra = 0;
wndclsEx.cbClsExtra = 0;

if (!RegisterClassEx(&wndclsEx))
{
MessageBox(0, TEXT("Could not register window class."), class_name, MB_OK | MB_ICONERROR);

return 1;
}

HWND hWnd = CreateWindowEx(0, class_name, TEXT("DDraw Intro"), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 640, 480,
0, 0, hInstance, 0);

ShowWindow(hWnd, cmdShow);
UpdateWindow(hWnd);

if (FAILED(DirectDrawCreateEx(null_ptr, (LPVOID *)&lpdd7, IID_IDirectDraw7, null_ptr)))
{
MessageBox(0, TEXT("Could not create DDraw7 object."), class_name, MB_OK | MB_ICONERROR);

UnregisterClass(class_name, hInstance);

return 1;
}

MSG msg;

while (1)
{
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;

TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
if (keyDown(VK_ESCAPE))
SendMessage(hWnd, WM_CLOSE, 0, 0);
}
}

if (lpdd7)
{
lpdd7->Release();
lpdd7 = null_ptr;
}

UnregisterClass(class_name, hInstance);

return msg.wParam;
}

LRESULT CALLBACK wndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CLOSE:

if (MessageBox(hWnd, TEXT("Are you sure you want to close"), class_name, MB_YESNO |
MB_ICONWARNING) == IDYES)
SendMessage(hWnd, WM_DESTROY, 0, 0);

return 0;

case WM_DESTROY:

PostQuitMessage(0);

return 0;
}

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


Undefined References to CoInitialize and CoCreateInstance

#define WIN32_LEAN_AND_MEAN
#define INITGUID

#include <windows.h>
#include <windowsx.h>
#include <ddraw.h>
#include <objbase.h>

#define null_ptr 0

LPDIRECTDRAW lpdd7 = null_ptr;

const TCHAR class_name[] = TEXT("Direct Draw");

inline bool keyUp(int key) { return !(GetAsyncKeyState(key) & 0x8000); }
inline bool keyDown(int key) { return (GetAsyncKeyState(key) & 0x8000); }

LRESULT CALLBACK wndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR cmdLine, int cmdShow)
{
WNDCLASSEX wndclsEx;

wndclsEx.hInstance = hInstance;
wndclsEx.lpfnWndProc = wndProc;
wndclsEx.style = CS_HREDRAW | CS_VREDRAW;

wndclsEx.hCursor = LoadCursor(0, IDC_ARROW);
wndclsEx.hIcon = LoadIcon(0, IDI_APPLICATION);
wndclsEx.hIconSm = LoadIcon(0, IDI_WINLOGO);
wndclsEx.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);

wndclsEx.lpszMenuName = 0;
wndclsEx.lpszClassName = class_name;

wndclsEx.cbSize = sizeof(WNDCLASSEX);
wndclsEx.cbWndExtra = 0;
wndclsEx.cbClsExtra = 0;

if (!RegisterClassEx(&wndclsEx))
{
MessageBox(0, TEXT("Could not register window class."), class_name, MB_OK | MB_ICONERROR);

return 1;
}

HWND hWnd = CreateWindowEx(0, class_name, TEXT("DDraw Intro"), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 640, 480,
0, 0, hInstance, 0);

ShowWindow(hWnd, cmdShow);
UpdateWindow(hWnd);

if (FAILED(CoInitialize(null_ptr)))
{
MessageBox(0, TEXT("Could not create COM object."), class_name, MB_OK | MB_ICONERROR);

UnregisterClass(class_name, hInstance);

return 1;
}

if (FAILED(CoCreateInstance(CLSID_DirectDraw, null_ptr, CLSCTX_ALL,
IID_IDirectDraw7, (LPVOID *)lpdd7)))
{
MessageBox(0, TEXT("Could not create COM instance."), class_name, MB_OK | MB_ICONERROR);

UnregisterClass(class_name, hInstance);

return 1;
}

if (FAILED(lpdd7->Initialize(null_ptr)))
{
MessageBox(0, TEXT("Could not initialize DDraw7 object."), class_name, MB_OK | MB_ICONERROR);

UnregisterClass(class_name, hInstance);

return 1;
}

/* or
if (FAILED(DirectDraw7_Initialize(lpdd7, null_ptr)))
{
MessageBox(0, TEXT("Could not initialize DDraw7 object."), class_name, MB_OK | MB_ICONERROR);

UnregisterClass(class_name, hInstance);

return 1;
}
*/


MSG msg;

while (1)
{
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;

TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
if (keyDown(VK_ESCAPE))
SendMessage(hWnd, WM_CLOSE, 0, 0);
}
}

if (lpdd7)
{
lpdd7->Release();
lpdd7 = null_ptr;
}

UnregisterClass(class_name, hInstance);

return msg.wParam;
}

LRESULT CALLBACK wndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CLOSE:

if (MessageBox(hWnd, TEXT("Are you sure you want to close"), class_name, MB_YESNO |
MB_ICONWARNING) == IDYES)
SendMessage(hWnd, WM_DESTROY, 0, 0);

return 0;

case WM_DESTROY:

PostQuitMessage(0);

return 0;
}

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

Share this post


Link to post
Share on other sites
Ok, I downloaded the DevC++ DX8 package (http://www.c-view.org/soft/devcpp/packages/) and the third example works now (the one with DirectDrawCreateEx) just fine when I include the libddraw.a.

However, the second (with COM) doesn't, so I'm guessing I need to include antoher library... any clues?

Share this post


Link to post
Share on other sites

This topic is 4715 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this