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(){
}

Recommended Answers

All 13 Replies

That is a linker error. You will not be able to find linker error's in the code. They have to do which which libraries you have your visual studio project linking to. I don't use visual studio so I can't tell you exactly, but you need to look in "project properties -> linking" or "libraries" or something like that and set which ever directX libraries you need to link to (I also don't use directX so I don't know which ones they are).

Can anyone give more specifics?

Dave

Well, I googled some, and tried it out, but it still failed.
I tried:
Project-"projectname" properties->Linker->General->Additional Library Directories->"directory file.lib" (I know where the file is located)
Then I also added:
Project-"projectname" properties->C/C++->General->Additional Library Directories->"directory where the lib is located"
And I was really excited for a while, 'cause I thought "This will definatly work!!!!", but, no! -.-
I also copied the library and put it in my resources, but when I try to include the resource I get an error, so I gave that up as well. I've tested everything I can think (or search) of! :(

Here are some small images of the properties window, if you don't have VC++ yourself, you might think of something here?

(Location of lib file: C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib\ddraw.lib)

you need to add additional libraries as shown in the thumbnail. Of course you would have found that too had you bothered to compile one of the sample programs that comes with DirectX SDK.

Mhm, well that didn't work either, am I doing something wrong? Enlighten me, 'cause I really don't know where to find the sample programs at the moment...

EDIT: well I found the sample, but I still don't get what I'm doing wrong

The sample programs should be in the same directory where you installed the SDK. On my computer they are here:
c:\Program Files\Microsoft DirectX SDK (August 2008)\Samples

Edited my post, but what the hey, I still can't get it to work, but I did find the sample program ( happy to say I did it before you posted :) )
Anywho... Should I, not only in the linker, include directory in c++ or something? It gives off the same error as before.
I really don't understand this linker... ( why can't there just be a button that says "Import libraries here"!? -.-)
As I said earlier, the library file is located somewhere else other than in the project folder

Just a reminder - I will give you a cookie if you teach me your ways :D (just remember why you're helping a stubborn lazy ass like me)

Since you found the samples, open one of them and browse the project linker settings, comparing them with your original program.

Also go to Tools --> Options and make sure the directories are something like the attached thumbnails

Ok, I've compared my program and the "AntiAlias", the one you're referring to, and the "input" seem to derive from the SDK library, right? and my file ddraw.lib, is also there, and yet it will not work!
If you want, here's the project, maybe you can fix it? :)

Seeing as everyone has the ddraw.lib, there should be a way to get it to work, I first thought it was added automatically like most other libraries... :(

(So far it's just one file, so you need to compile it yourself, and you have to change: Project->"projectname" properties -> General ->Character Set-> to either Multi-code or no set at all)

Are you reading a tutorial ? I don't see DirectDrawCreate being called in any of the sample programs.

I searched all the samples and found it used in two projects: Configuration System and VideoMemory. And in those projects DirectDrawCreateEx is being called as a function pointer. Like this:

IDirectDraw7* DDobject;
    HINSTANCE ddrawLib = LoadLibraryW( L"ddraw.dll" );
    if( ddrawLib )
    {
        HRESULT (WINAPI* _DirectDrawCreateEx)( GUID* lpGUID, void** lplpDD, REFIID iid, IUnknown* pUnkOuter ) = (HRESULT (WINAPI*)( GUID* lpGUID, void** lplpDD, REFIID iid, IUnknown* pUnkOuter ))GetProcAddress( ddrawLib, "DirectDrawCreateEx" ); 
        if( _DirectDrawCreateEx )
        {
            HRESULT (WINAPI* _DirectDrawEnumerateEx)( LPDDENUMCALLBACKEXA, LPVOID, DWORD ) = (HRESULT (WINAPI*)( LPDDENUMCALLBACKEXA, LPVOID, DWORD )) GetProcAddress( ddrawLib, "DirectDrawEnumerateExA" );

Yes, I'm reading a tutorial, but not the one's from the SDK, its a book called Windows Game Programming for Dummies, it's quite old, but it says no matter what version of directx u have, the functions will remain. But the whole reason for this is because it doesn't approve of the function DirectDrawCreate? and instead want DirectDrawCreateEx? :S, Because intellisense in VC++ knows the DirectDrawCreate function, but that could be because I included the header...?

Argh, I don't know what to do! :'(

Here is a tutorial that actually compiles, links and works. It's possible that book you are reading is just too old.

commented: Already tried it, but at least you were willing to help out, maybe in time I'll see what stupid mistake I did. Thanks! +1

Already tried that tutorial, but I need a more... eh.. stupid one, but seeing as I know more than I did before ( I actually tried this tutorial before borrowing the book ), I might understand it this time. Thanks for your help Dragon.

I noticed on that site he has more advanced tutorials -- for a price of $25.00 USD.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.