Mmm, I just love these error messages, I don't understand them what-so-ever and I can't interpret them.
(Unsure where the post should be in the forum)
I'm getting this error message at build time (Using VC++):
1>Linking...
1>main.obj : error LNK2019: unresolved external symbol _DirectDrawCreate@12 referenced in function "long __cdecl InitWindow(struct HINSTANCE__ *,int)" (?InitWindow@@YAJPAUHINSTANCE__@@H@Z)
1>C:\Users\Shadow\Documents\Visual Studio 2008\Projects\g_app\Debug\g_app.exe : fatal error LNK1120: 1 unresolved externals
Now, I don't really know how this linker works, so I'm hoping you do. Anyone care to explain what is wrong? It refers to a function I recently added, I'm posting the code as well so you can test it.
The problem occurs at InitWindow (where I call to the ddraw func )
I tried adding an include for DDRAW.lib but it probably doesn't exist.
The code works if you remove the lines that have to do with directx in InitWindow
#include <windows.h>
#include <stdio.h>
#include <DDRAW.H>
HINSTANCE g_hInst = NULL;
HWND g_hWnd = NULL;
HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow );
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
void Game_Init();
void Rendering();
void Game_End();
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
{
if( FAILED( InitWindow( hInstance, nCmdShow ) ) )
return 0;
int i = 0;
// Main message loop
MSG msg = {0};
Game_Init();
while( WM_QUIT != msg.message )
{
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}else{
Rendering();
}
}
Game_End();
return ( int )msg.wParam;
}
HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow )
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof( WNDCLASSEX );
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon( hInstance, IDI_APPLICATION );
wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
wcex.hbrBackground = ( HBRUSH )( COLOR_WINDOW + 1 );
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "rpgwnd";
wcex.hIconSm = LoadIcon( wcex.hInstance, IDI_APPLICATION );
if( !RegisterClassEx( &wcex ) )
return E_FAIL;
// Create window
g_hInst = hInstance;
RECT rc = { 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN) };
AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );
g_hWnd = CreateWindow( "rpgwnd", "RPG",
WS_POPUP | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, hInstance,
NULL );
if( !g_hWnd )
return E_FAIL;
//DirectX Online
LPDIRECTDRAW lpdd;
if(DirectDrawCreate(NULL, &lpdd, NULL)!=DD_OK){}
lpdd->SetCooperativeLevel( g_hWnd, DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT);
if((lpdd->SetDisplayMode(640,480, 8)) != DD_OK){}
ShowWindow( g_hWnd, nCmdShow );
return S_OK;
}
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
PAINTSTRUCT ps;
HDC hdc;
switch( message )
{
case WM_PAINT:
{
hdc = BeginPaint( hWnd, &ps );
HPEN black_pen = CreatePen( PS_SOLID, 5, RGB(150,150,150));
HBRUSH black_brush = CreateSolidBrush( RGB(255,255,0));
SelectObject( hdc, black_pen);
SelectObject( hdc, black_brush);
Ellipse(hdc, 5,5, 20,20);
Ellipse(hdc, 43,5,58,20);
MoveToEx( hdc, 12,12, NULL);
LineTo( hdc,50,12);
DeleteObject( black_pen);
DeleteObject( black_brush);
EndPaint( hWnd, &ps );
}
break;
case WM_MOUSEMOVE:
{
RECT drawarea = {0,0,60,20};
int mouse_x = (int)LOWORD(lParam);
int mouse_y = (int)HIWORD(lParam);
if( mouse_x > 0 && mouse_x < 60 && mouse_y> 0 && mouse_y < 20){
hdc = GetDC( hWnd);
char buffer[30];
int length = sprintf(buffer, "You are at X: %d, Y: %d", mouse_x, mouse_y);
TextOut( hdc, 0, 70, buffer, length);
ReleaseDC( hWnd, hdc);
ValidateRect( hWnd, NULL);
}
}
break;
case WM_KEYDOWN:
{
int virtual_key = (int)wParam;
int key_bits = (int)lParam;
switch(virtual_key){
case VK_ESCAPE:
PostQuitMessage( 0 );
break;
default:
break;
}
}
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default:
return DefWindowProc( hWnd, message, wParam, lParam );
}
return 0;
}
void Game_Init(){
}
void Rendering(){
}
void Game_End(){
}