D3D NOT WORKING!!

Posts 1–15 of 29 · Page 1 of 2
D3D NOT WORKING!!
OK so i am compiling my code and i consistently get these errors and no matter what i do they are there. Here is my code:

Code:
#include <windows.h>
#include <WindowsX.h>
#include <d3d9.h>
#include <d3dx9.h>
#pragma comment (lib, "d3d9.lib")
#define width 800
#define height 600

int r, g, b;
#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

struct CUSTOMVERTEX       // Vertices struct
{
	FLOAT x, y, z, rhw;
	DWORD color;
};

HDC hdc;
RECT rect;


LPDIRECT3D9 d3d = NULL;
LPDIRECT3DDEVICE9 d3ddev = NULL;
LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL; 



bool tri = false;

void init_d3d(HWND hwnd);
void render_frame();
void clean_up();
void init_graphics();
void PrintText();

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

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
     static TCHAR szAppName[] = TEXT ("HelloWin") ;
     HWND         hwnd ;
     MSG          msg ;
     WNDCLASS     wndclass ;

     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
     wndclass.lpfnWndProc   = WndProc ;
     wndclass.cbClsExtra    = 0 ;
     wndclass.cbWndExtra    = 0 ;
     wndclass.hInstance     = hInstance ;
     wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
     wndclass.hbrBackground = (HBRUSH) COLOR_WINDOW ;
     wndclass.lpszMenuName  = NULL ;
     wndclass.lpszClassName = szAppName ;

     if (!RegisterClass (&wndclass))
     {
          MessageBox (NULL, TEXT ("This program requires Windows NT!"), 
                      szAppName, MB_ICONERROR) ;
          return 0 ;
     }
     hwnd = CreateWindow (szAppName,                  // window class name
                          TEXT ("The Hello Program"), // window caption
                          WS_OVERLAPPEDWINDOW,        // window style
                          0,              // initial x position
                          0,              // initial y position
                          width,              // initial x size
                          height,              // initial y size
                          NULL,                       // parent window handle
                          NULL,                       // window menu handle
                          hInstance,                  // program instance handle
                          NULL) ;                     // creation parameters
     
     ShowWindow (hwnd, iCmdShow) ;
     init_d3d(hwnd);
	 

	 UpdateWindow (hwnd) ;
     
     while (GetMessage (&msg, NULL, 0, 0))
     {
          TranslateMessage (&msg) ;
          DispatchMessage (&msg) ;
         
		  render_frame();
	      
	 }
     return msg.wParam ;

	 clean_up();

}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    
	
     switch (message)
     {
   
	 case WM_KEYDOWN:
		 switch(wParam)
		 {
		 case VK_SHIFT:
			 if(r<255-25){
			 r+=25;
			 }
			 else
			 break;
		 case VK_HOME:
			 if(g<255-25){
			 g+=25;
			 }
			 else
			 break;
		 case VK_NUMPAD1:
			 if(b<255 - 25 ){
			 b+= 25;
			 }
			 else
			 
			 break;

		 default:
			 break;
		 }
		 return 0;
	 
     case WM_DESTROY:
          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
}

void init_d3d(HWND hwnd)
{
	d3d = Direct3DCreate9(D3D_SDK_VERSION);

	D3DPRESENT_PARAMETERS d3dpp;

	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.Windowed = true;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.hDeviceWindow = hwnd;
	d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
	d3dpp.BackBufferWidth = width;
	d3dpp.BackBufferHeight = height;

	d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);

	
}


void render_frame()
{
	d3ddev->Clear(0, 0, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,196,50), 0.0f, NULL);

	d3ddev->BeginScene();
	init_graphics();
	hdc = GetDC(0);
	GetClientRect(NULL, &rect);
	DrawTextA(hdc, "HELLO", -1, &rect, NULL);
	d3ddev->SetFVF(CUSTOMFVF);
	d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
	d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

	d3ddev->EndScene();
	d3ddev->Present(NULL, NULL, NULL, NULL);


	
}


void init_graphics()
{
	
	CUSTOMVERTEX triangle[] =
	{
	{400.0f, 100.0f, .5f, 1.0f, D3DCOLOR_XRGB(r,g,b), } ,
	{650.0f, 200.0f, .5f, 1.0f, D3DCOLOR_XRGB(r,g,b),},
	{100.0f, 200.0f, .5f, 1.0f, D3DCOLOR_XRGB(r,g,b),},
	};

	d3ddev->CreateVertexBuffer(3 * sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, 0);
    
	VOID* buffer;
	
	v_buffer->Lock(0,0,&buffer, 0);
	memcpy(buffer, triangle, sizeof(triangle));
	v_buffer->Unlock();

}
void clean_up()
{
	v_buffer->Release();
	d3d->Release();
	d3ddev->Release();
}
AND THEN HERE ARE MY ANNOYING ERRORS:

Code:
1>main.obj : error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function "void __cdecl init_d3d(struct HWND__ *)" (?init_d3d@@YAXPAUHWND__@@@Z)



1>c:\users\egmfco\documents\visual studio 2010\Projects\D3d\Debug\D3d.exe : fatal error LNK1120: 1 unresolved externals

How can I fix these?
Hmmmmm

SOLUTION #1 Delete winlogon.exe
SOLUTION #2 Stop hacking
SOLUTION #3 Pm someone who cares/knows how to fix it
linker error.

Quote Originally Posted by mushdoomx View Post
Hmmmmm

SOLUTION #1 Delete winlogon.exe
SOLUTION #2 Stop hacking
SOLUTION #3 Pm someone who cares/knows how to fix it
I never knew deleting winlogon.exe solved linker errors! Genious!!
you are importing d3dx9's header but not the library?
[highlight=cpp]#pragma comment(lib, "d3dx9.lib")[/highlight]
Horatio, It didn't work, i just tried it. Keep the solutions coming. Thanks btw.
How about using the D3DXFont struct, instead of DrawTextA()? The linker error can be caused for so many reasons. I can remember a project that it showed me a lot of linker errors for some unknown reasons.
Well what do you suggest that i do. Should i reinstall the headers or libs somehow?
Nope. I think you have to look thought your code for a while until you find something..
Well, i did that before i posted this thread here. I can't find anything. How did you get this error fixed when you had it?
Quote Originally Posted by 258456 View Post
Well, i did that before i posted this thread here. I can't find anything. How did you get this error fixed when you had it?
I didn't imported the classes and funcs. I fucking created them by myself
But no1 can't replace the D3D Library so idk what to say...
Quote Originally Posted by mushdoomx View Post
Hmmmmm

SOLUTION #1 Delete winlogon.exe
SOLUTION #2 Stop hacking
SOLUTION #3 Pm someone who cares/knows how to fix it


Answer to Solution # 1 : First of all, Who are you and do you even know what coding is? Second of all, Don't post stupid things because it's obvious you don't know what you are talking about, and people reading this with the same problem might think that your solution is true and they will actually delete it.

Answer to Solution # 2: Just because I am using directx doesn't mean i am hacking. This is why you make yourself look stupid because anybody who knows their way around c++ and the directx sdk knows that it isn't just for hacking.


Answer to Solution #3: You need to make a google search on what a forum is because it appears that you don't understand how a forum works.


If you don't want to help don't post. You are wasting your time by posting useless words and you are wasting everybody else's time reading your posts.

Quote Originally Posted by user590177 View Post


I didn't imported the classes and funcs. I fucking created them by myself
But no1 can't replace the D3D Library so idk what to say...
Well, thanks for trying to help anyways i appreciate it. Anybody with a solution please post here. I am really getting frustrated with this.

@[MPGH]Hell_Demon, I know you know a solution (and btw, i am still waiting for your second d3d tut)

@Void you most likely know this cuz u just know everything... lol

@why06 there's no doubt that you know this...

Quote Originally Posted by user590177 View Post


I didn't imported the classes and funcs. I fucking created them by myself
But no1 can't replace the D3D Library so idk what to say...
Well, thanks for trying to help anyways i appreciate it. Anybody with a solution please post here. I am really getting frustrated with this.

@[MPGH]HELL_DEMON, I know you know a solution (and btw, i am still waiting for your second d3d tut)

@Void you most likely know this cuz u just know everything... lol

@why06 there's no doubt that you know this...

@Fovea cuz you always help me, especially in asm
And anybody else i didn't mention
Forgetting to link the libraries is the only thing that comes to mind.
Well, i linked with them. Everything is fine but it gives me these errors. It's really pissing me off. Does anybody know how i can reinstall d3d if there is no solution to this?
Google and find the D3D SDK June 2010
Quote Originally Posted by user590177 View Post
Google and find the D3D SDK June 2010
But won't that install D3D10? so i can't use D3D9 and the code will be different?
Posts 1–15 of 29 · Page 1 of 2

Post a Reply

Tags for this Thread

None

Talk with us