Thread: Trouble with Windows/DirectX programming

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    141

    Trouble with Windows/DirectX programming

    UPDATE:
    I put the
    Code:
    LPDIRECT3D9 g_pDirect3D = NULL;
    LPDIRECT3DDEVICE9 g_pDirect3D_Device = NULL;
    At the top, now all I get is:
    error C2065: 'WndProc' : undeclared identifier

    Update: I just fixed the wndproc thing, just a typo there..

    I compiled, and debuged and got this:

    Code:
    1>main.obj : error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function _WinMain@16
    1>fatal error LNK1120: 1 unresolved externals
    Code:
    
    #include <windows.h>
    #include <d3d9.h>
    
    /// Update 1
    LPDIRECT3D9 g_pDirect3D = NULL;
    LPDIRECT3DDEVICE9 g_pDirect3D_Device = NULL;
    
    // Update 2, changed WinProc to WndProc, silly typo xD
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lParam);
    
    int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShow)
    {
    	MSG msg;
    
    	WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_VREDRAW|CS_HREDRAW|CS_OWNDC,WndProc, 
    		0,0,hInstance, NULL, NULL, (HBRUSH)(COLOR_WINDOW+1),NULL, "DX9_TUTORIAL1_CLASS", NULL };
    
    	RegisterClassEx(&wc);
    
    	HWND hMainWnd = CreateWindow(
    		"DX9_TUTORIAL1_CLASS", 
    		"DirectX9 test", 
    		WS_OVERLAPPEDWINDOW, 
    		100,100,
    		300,300,
    		NULL,
    		NULL,
    		hInstance, 
    		NULL);
    
    
    	g_pDirect3D = Direct3DCreate9(D3D_SDK_VERSION);
    
    	D3DPRESENT_PARAMETERS PresentParams;
    
    	memset(&PresentParams, 0, sizeof(D3DPRESENT_PARAMETERS));
    
    	PresentParams.Windowed = TRUE;
    	PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
    
    
    	g_pDirect3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hMainWnd, 
    		D3DCREATE_SOFTWARE_VERTEXPROCESSING, &PresentParams, &g_pDirect3D_Device);
    
    	ShowWindow(hMainWnd, nShow);
    	UpdateWindow(hMainWnd);
    
    
    	while (GetMessage(&msg, NULL, 0, 0))
    	{
    
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    
    	}
    
    
    	return 0;
    
    
    }
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    
    	switch(msg)
    	{
    	
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		return 0;
    
    	case WM_PAINT:
    		g_pDirect3D_Device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255),1.0f, 0);
    		g_pDirect3D_Device->Present(NULL, NULL, NULL, NULL);
    		ValidateRect(hwnd, NULL);
    		return 0;
    
    	}
    
    	g_pDirect3D_Device->Release();
    	g_pDirect3D->Release();
    	return DefWindowProc(hwnd, msg, wParam, lParam);
    
    }
    Most of the errors are just saying an unidentifier

    Code:
    (10) : error C2065: 'WndProc' : undeclared identifier
    (27) : error C2065: 'g_pDirect3D' : undeclared identifier
    (37) : error C2065: 'g_pDirect3D' : undeclared identifier
    (37) : error C2227: left of '->CreateDevice' must point to class/struct/union/generic type
    1>        type is ''unknown-type''
    (37) : error C2065: 'g_pDirect3D_Device' : undeclared identifier
    (68) : error C2065: 'g_pDirect3D_Device' : undeclared identifier
    (68) : error C2227: left of '->Clear' must point to class/struct/union/generic type
    1>        type is ''unknown-type''
    (69) : error C2065: 'g_pDirect3D_Device' : undeclared identifier
    (69) : error C2227: left of '->Present' must point to class/struct/union/generic type
    1>        type is ''unknown-type''
    (75) : error C2065: 'g_pDirect3D_Device' : undeclared identifier
    (75) : error C2227: left of '->Release' must point to class/struct/union/generic type
    1>        type is ''unknown-type''
    (76) : error C2065: 'g_pDirect3D' : undeclared identifier
    (76) : error C2227: left of '->Release' must point to class/struct/union/generic type
    Last edited by bobbelPoP; 07-05-2008 at 12:15 AM.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Did you link with d3d9.lib (I think it's called that)?
    I'm taking it that you're using Visual Studio. In that case, you can add libraries to link against under project options, linker and input (add d3d9.lib).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    141
    Quote Originally Posted by Elysia View Post
    Did you link with d3d9.lib (I think it's called that)?
    I'm taking it that you're using Visual Studio. In that case, you can add libraries to link against under project options, linker and input (add d3d9.lib).
    Alright, thanks. Ill try it

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    141
    Okay, I did it, and I got this:
    Code:
    Unhandled exception at 0x00e2178a in dxtest.exe: 0xC0000005: Access violation reading location 0x00000000.
    dxtest is my project/solution compiled exe file.

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Step through the debugger until it crashes.

  6. #6
    Registered User
    Join Date
    May 2008
    Posts
    141
    Quote Originally Posted by medievalelks View Post
    Step through the debugger until it crashes.
    What?

    Also heres some errors:
    Code:
    >	dxtest.exe!WndProc(HWND__ * hwnd=0x00190fd0, unsigned int msg=36, unsigned int wParam=0, long lParam=2880360)  Line 80 + 0x5 bytes	C++
     	user32.dll!76d1f8d2() 	
     	[Frames below may be incorrect and/or missing, no symbols loaded for user32.dll]	
     	user32.dll!76d1f794() 	
     	user32.dll!76d1f73d() 	
     	user32.dll!76d20817() 	
     	user32.dll!76d0fcbe() 	
     	dxtest.exe!WinMain(HINSTANCE__ * hInstance=0x00330000, HINSTANCE__ * hPrevInst=0x00000000, char * lpCmdLine=0x00542d51, int nShow=1)  Line 28 + 0x31 bytes	C++
     	dxtest.exe!__tmainCRTStartup()  Line 574 + 0x35 bytes	C
     	dxtest.exe!WinMainCRTStartup()  Line 399	C
     	kernel32.dll!767a4911() 	
     	ntdll.dll!77d5e4b6() 	
     	ntdll.dll!77d5e489() 	
    
    
    	dxtest.exe	C:\Users\*******\Documents\Visual Studio 2008\Projects\dxtest\Debug\dxtest.exe	N/A	N/A	Symbols loaded.	C:\Users\*******\Documents\Visual Studio 2008\Projects\dxtest\Debug\dxtest.pdb	1		7/6/2008 12:19 PM	00330000-0034B000	[3680] dxtest.exe: Native	
    	ntdll.dll	C:\Windows\System32\ntdll.dll	N/A	N/A	Symbols not loaded.		2	6.0.6001.18000 (longhorn_rtm.080118-1840)	1/19/2008 3:32 AM	77D20000-77E47000	[3680] dxtest.exe: Native	
    	kernel32.dll	C:\Windows\System32\kernel32.dll	N/A	N/A	Symbols not loaded.		3	6.0.6001.18000 (longhorn_rtm.080118-1840)	1/19/2008 3:31 AM	76760000-7683B000	[3680] dxtest.exe: Native	
    	d3d9.dll	C:\Windows\System32\d3d9.dll	N/A	N/A	Symbols not loaded.		4	6.0.6001.18000 (longhorn_rtm.080118-1840)	1/19/2008 3:27 AM	732F0000-734AA000	[3680] dxtest.exe: Native	
    	msvcrt.dll	C:\Windows\System32\msvcrt.dll	N/A	N/A	Symbols not loaded.		5	7.0.6001.18000 (longhorn_rtm.080118-1840)	1/19/2008 3:30 AM	76E20000-76ECA000	[3680] dxtest.exe: Native	
    	user32.dll	C:\Windows\System32\user32.dll	N/A	N/A	Symbols not loaded.		6	6.0.6001.18000 (longhorn_rtm.080118-1840)	1/19/2008 3:32 AM	76D00000-76D9D000	[3680] dxtest.exe: Native	
    	gdi32.dll	C:\Windows\System32\gdi32.dll	N/A	N/A	Symbols not loaded.		7	6.0.6001.18023 (vistasp1_gdr.080221-1537)	2/22/2008 12:57 AM	769A0000-769EB000	[3680] dxtest.exe: Native	
    	advapi32.dll	C:\Windows\System32\advapi32.dll	N/A	N/A	Symbols not loaded.		8	6.0.6001.18000 (longhorn_rtm.080118-1840)	1/19/2008 3:27 AM	76630000-766F6000	[3680] dxtest.exe: Native	
    	rpcrt4.dll	C:\Windows\System32\rpcrt4.dll	N/A	N/A	Symbols not loaded.		9	6.0.6001.18000 (longhorn_rtm.080118-1840)	1/19/2008 3:31 AM	768D0000-76993000	[3680] dxtest.exe: Native	
    	version.dll	C:\Windows\System32\version.dll	N/A	N/A	Symbols not loaded.		10	6.0.6001.18000 (longhorn_rtm.080118-1840)	1/19/2008 3:32 AM	75890000-75898000	[3680] dxtest.exe: Native	
    	d3d8thk.dll	C:\Windows\System32\d3d8thk.dll	N/A	N/A	Symbols not loaded.		11	6.0.6000.16386 (vista_rtm.061101-2205)	11/2/2006 5:39 AM	73290000-73296000	[3680] dxtest.exe: Native	
    	dwmapi.dll	C:\Windows\System32\dwmapi.dll	N/A	N/A	Symbols not loaded.		12	6.0.6001.18000 (longhorn_rtm.080118-1840)	1/19/2008 3:29 AM	73E60000-73E6C000	[3680] dxtest.exe: Native	
    	msvcr90d.dll	C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.21022.8_none_96748342450f6aa2\msvcr90d.dll	N/A	N/A	Symbols loaded.	C:\Windows\symbols\dll\msvcr90d.i386.pdb	13	9.00.21022.8	11/7/2007 12:23 AM	68960000-68A83000	[3680] dxtest.exe: Native	
    	imm32.dll	C:\Windows\System32\imm32.dll	N/A	N/A	Symbols not loaded.		14	6.0.6001.18000 (longhorn_rtm.080118-1840)	1/19/2008 3:30 AM	77B70000-77B8E000	[3680] dxtest.exe: Native	
    	msctf.dll	C:\Windows\System32\msctf.dll	N/A	N/A	Symbols not loaded.		15	6.0.6000.16386 (vista_rtm.061101-2205)	1/19/2008 3:30 AM	76A80000-76B48000	[3680] dxtest.exe: Native	
    	lpk.dll	C:\Windows\System32\lpk.dll	N/A	N/A	Symbols not loaded.		16	6.0.6001.18000 (longhorn_rtm.080118-1840)	1/19/2008 3:29 AM	765A0000-765A9000	[3680] dxtest.exe: Native	
    	usp10.dll	C:\Windows\System32\usp10.dll	N/A	N/A	Symbols not loaded.		17	1.0626.6001.18000 (longhorn_rtm.080118-1840)	1/19/2008 3:32 AM	76DA0000-76E1D000	[3680] dxtest.exe: Native	
    	uxtheme.dll	C:\Windows\System32\uxtheme.dll	N/A	N/A	Symbols not loaded.		18	6.0.6000.16386 (vista_rtm.061101-2205)	1/19/2008 3:32 AM	75060000-7509F000	[3680] dxtest.exe: Native	
    	xfire_toucan_32716.dll	C:\Program Files\Xfire\xfire_toucan_32716.dll	N/A	N/A	Symbols not loaded.		19	0.00.0.0	6/26/2008 4:08 PM	10000000-10221000	[3680] dxtest.exe: Native	
    	shlwapi.dll	C:\Windows\System32\shlwapi.dll	N/A	N/A	Symbols not loaded.		20	6.0.6000.16386 (vista_rtm.061101-2205)	1/19/2008 3:31 AM	76ED0000-76F28000	[3680] dxtest.exe: Native	
    	wsock32.dll	C:\Windows\System32\wsock32.dll	N/A	N/A	Symbols not loaded.		21	6.0.6000.16386 (vista_rtm.061101-2205)	1/19/2008 3:33 AM	713B0000-713B7000	[3680] dxtest.exe: Native	
    	ws2_32.dll	C:\Windows\System32\ws2_32.dll	N/A	N/A	Symbols not loaded.		22	6.0.6000.16386 (vista_rtm.061101-2205)	1/19/2008 3:32 AM	76B50000-76B7D000	[3680] dxtest.exe: Native	
    	nsi.dll	C:\Windows\System32\nsi.dll	N/A	N/A	Symbols not loaded.		23	6.0.6001.18000 (longhorn_rtm.080118-1840)	1/19/2008 3:32 AM	76700000-76706000	[3680] dxtest.exe: Native	
    	winmm.dll	C:\Windows\System32\winmm.dll	N/A	N/A	Symbols not loaded.		24	6.0.6000.16386 (vista_rtm.061101-2205)	1/19/2008 3:33 AM	74140000-74172000	[3680] dxtest.exe: Native	
    	ole32.dll	C:\Windows\System32\ole32.dll	N/A	N/A	Symbols not loaded.		25	6.0.6000.16386 (vista_rtm.061101-2205)	1/19/2008 3:31 AM	76B80000-76CC4000	[3680] dxtest.exe: Native	
    	oleaut32.dll	C:\Windows\System32\oleaut32.dll	N/A	N/A	Symbols not loaded.		26	6.00.6001.18000	1/19/2008 3:31 AM	769F0000-76A7D000	[3680] dxtest.exe: Native	
    	oleacc.dll	C:\Windows\System32\oleacc.dll	N/A	N/A	Symbols not loaded.		27	4.2.5406.0 (longhorn_rtm.080118-1840)	1/19/2008 3:31 AM	74100000-74139000	[3680] dxtest.exe: Native	
    	msimg32.dll	C:\Windows\System32\msimg32.dll	N/A	N/A	Symbols not loaded.		28	6.0.6000.16386 (vista_rtm.061101-2205)	11/2/2006 5:42 AM	75860000-75865000	[3680] dxtest.exe: Native	
    	comctl32.dll	C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.6001.18000_none_5cdbaa5a083979cc\comctl32.dll	N/A	N/A	Symbols not loaded.		29	6.10 (longhorn_rtm.080118-1840)	1/19/2008 3:31 AM	754E0000-7567E000	[3680] dxtest.exe: Native	
    	msvcr71.dll	C:\Program Files\ImageMagick-6.4.1-Q8\msvcr71.dll	N/A	N/A	Symbols not loaded.		30	7.10.3052.4	2/21/2003 8:42 AM	7C340000-7C396000	[3680] dxtest.exe: Native

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by bobbelPoP View Post
    What?
    Compile in debug mode, set a break point at the start of the program (or near where you suspect it may be crashing), and then step through it line by line until it crashes.

    This is Debugging 101, at least before the advent of message boards and the Spoon Feed Method.

  8. #8
    Registered User
    Join Date
    May 2008
    Posts
    141
    Quote Originally Posted by medievalelks View Post
    Compile in debug mode, set a break point at the start of the program (or near where you suspect it may be crashing), and then step through it line by line until it crashes.

    This is Debugging 101, at least before the advent of message boards and the Spoon Feed Method.
    This is where the red break point ball went to:
    Code:
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShow)
    {

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No, not the breakpoint (the red ball), but the line where it crashes.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User
    Join Date
    May 2008
    Posts
    141
    Quote Originally Posted by Elysia View Post
    No, not the breakpoint (the red ball), but the line where it crashes.
    Well theres an arrow that keeps directing me to this piece of code:
    Code:
    g_pDirect3D_Device->Release();

  11. #11
    Registered User
    Join Date
    May 2008
    Posts
    141
    Hey guys, nevermind I got it to work, I took it out of the callback WndProc function, and into WinMain

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Umm no.
    That code release the d3d device, so it must be there.
    If that line causes problems, it means you did something wrong before.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Registered User
    Join Date
    May 2008
    Posts
    141
    Quote Originally Posted by Elysia View Post
    Umm no.
    That code release the d3d device, so it must be there.
    If that line causes problems, it means you did something wrong before.
    Oh.. Lol, well it works like it should, so whats the problem?

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The problem is that you do not release what you acquire.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Registered User
    Join Date
    Jan 2006
    Location
    Sweden
    Posts
    92
    Actually, the release on the device should only be called at the end of WinMain (or once when the application closes). You don't want to release your device at every message you receive so what you did is correct.

    I also noticed your d3d object in the WndProc, did you move it too? If not, you should. Always release such objects in the reverse order that they were created.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with assignment in C
    By mohanlon in forum C Programming
    Replies: 17
    Last Post: 06-23-2009, 10:44 AM
  2. Replies: 6
    Last Post: 01-03-2007, 03:02 PM
  3. Is it so trouble?
    By Yumin in forum Tech Board
    Replies: 4
    Last Post: 01-30-2006, 04:10 PM
  4. trouble scanning in... and link listing
    By panfilero in forum C Programming
    Replies: 14
    Last Post: 11-21-2005, 12:58 PM
  5. C++ program trouble
    By senrab in forum C++ Programming
    Replies: 7
    Last Post: 04-29-2003, 11:55 PM