Sign in to follow this  

Visual Studio 8 Headaches

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

Hello! I'm currently going through Jim Adams' book, "Programming Role Playing Games in DirectX 2 Ed." Specifically, I am trying to recreate his project on displaying a textured 2D square. Today i installed Visual Studio 8 on my home computer, and got to programming. On building, a number of errors were thrown my way, many by the windows header files. I attempted a build on my laptop (which has a copy of Visual Studio .Net 2003) and everything went fine, it built and ran without trouble. Jim Adams' source code does exactly the same. I was wondering if anyone can help me out in solving this problem, as Im hearing Visual Studio 8 is the way to go. Jim Adams' code is as follows: ************************************************** WinMain.cpp Chapter 2 2-D Drawing Demo (Draw2D) Programming Role-Playing Games with DirectX, 2nd Edition by Jim Adams (Jan 2004) Required libraries: D3D9.LIB and D3DX9.LIB **************************************************/ // Include files #include <windows.h> #include <stdio.h> #include "d3d9.h" #include "d3dx9.h" // Window handles, class and caption text HWND g_hWnd; HINSTANCE g_hInst; static char g_szClass[] = "Draw2DClass"; static char g_szCaption[] = "Draw2D Demo by Jim Adams"; // The Direct3D and Device object IDirect3D9 *g_pD3D = NULL; IDirect3DDevice9 *g_pD3DDevice = NULL; // The 2-D vertex format and descriptor typedef struct { FLOAT x, y, z; // 2-D coordinates FLOAT rhw; // rhw FLOAT u, v; // Texture coordinates } sVertex; #define VERTEXFVF (D3DFVF_XYZRHW | D3DFVF_TEX1) // Vertex buffer IDirect3DVertexBuffer9 *g_pVB = NULL; // Texture IDirect3DTexture9 *g_pTexture = NULL; // Function prototypes int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow); long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); BOOL DoInit(); BOOL DoShutdown(); BOOL DoFrame(); BOOL SetupMeshes(); int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow) { WNDCLASSEX wcex; MSG Msg; g_hInst = hInst; // Create the window class here and register it wcex.cbSize = sizeof(wcex); wcex.style = CS_CLASSDC; wcex.lpfnWndProc = WindowProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInst; wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = NULL; wcex.lpszMenuName = NULL; wcex.lpszClassName = g_szClass; wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if(!RegisterClassEx(&wcex)) return FALSE; // Create the Main Window g_hWnd = CreateWindow(g_szClass, g_szCaption, WS_CAPTION | WS_SYSMENU, 0, 0, 400, 400, NULL, NULL, hInst, NULL ); if(!g_hWnd) return FALSE; ShowWindow(g_hWnd, SW_NORMAL); UpdateWindow(g_hWnd); // Run init function and return on error if(DoInit() == FALSE) return FALSE; // Start message pump, waiting for signal to quit ZeroMemory(&Msg, sizeof(MSG)); while(Msg.message != WM_QUIT) { if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } if(DoFrame() == FALSE) break; } // Run shutdown function DoShutdown(); UnregisterClass(g_szClass, hInst); return Msg.wParam; } long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, uMsg, wParam, lParam); } BOOL DoInit() { D3DPRESENT_PARAMETERS d3dpp; D3DDISPLAYMODE d3ddm; BYTE *Ptr; sVertex Verts[4] = { { 50.0f, 50.0f, 1.0f, 1.0f, 0.0f, 0.0f }, { 350.0f, 50.0f, 1.0f, 1.0f, 1.0f, 0.0f }, { 50.0f, 350.0f, 1.0f, 1.0f, 0.0f, 1.0f }, { 350.0f, 350.0f, 1.0f, 1.0f, 1.0f, 1.0f } }; // Do a windowed mode initialization of Direct3D if((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL) return FALSE; if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm))) return FALSE; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = d3ddm.Format; d3dpp.EnableAutoDepthStencil = FALSE; if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice))) return FALSE; // Create the vertex buffer and set data g_pD3DDevice->CreateVertexBuffer(sizeof(sVertex)*4, 0, VERTEXFVF, D3DPOOL_DEFAULT, &g_pVB, NULL); g_pVB->Lock(0,0, (void**)&Ptr, 0); memcpy(Ptr, Verts, sizeof(Verts)); g_pVB->Unlock(); // Load the texture map D3DXCreateTextureFromFile(g_pD3DDevice, "Texture.bmp", &g_pTexture); return TRUE; } BOOL DoShutdown() { // Release vertex buffer if(g_pVB != NULL) g_pVB->Release(); // Release texture if(g_pTexture != NULL) g_pTexture->Release(); // Release device and 3D objects if(g_pD3DDevice != NULL) g_pD3DDevice->Release(); if(g_pD3D != NULL) g_pD3D->Release(); return TRUE; } BOOL DoFrame() { // Clear device backbuffer g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_RGBA(0,64,128,255), 1.0f, 0); // Begin scene if(SUCCEEDED(g_pD3DDevice->BeginScene())) { // Set the vertex stream, shader, and texture g_pD3DDevice->SetStreamSource(0, g_pVB, 0, sizeof(sVertex)); g_pD3DDevice->SetFVF(VERTEXFVF); g_pD3DDevice->SetTexture(0, g_pTexture); // Draw the vertex buffer g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); // Release texture g_pD3DDevice->SetTexture(0, NULL); // End the scene g_pD3DDevice->EndScene(); } // Display the scene g_pD3DDevice->Present(NULL, NULL, NULL, NULL); return TRUE; } The errors it throws up are as follows: c:\microsoft platform sdk\include\winnt.h(222) : error C2146: syntax error : missing ';' before identifier 'PVOID64' c:\microsoft platform sdk\include\winnt.h(222) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\microsoft platform sdk\include\winnt.h(5940) : error C2146: syntax error : missing ';' before identifier 'Buffer' c:\microsoft platform sdk\include\winnt.h(5940) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\microsoft platform sdk\include\winnt.h(5940) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int d:\bookcode\chap02\draw2d\winmain.cpp(72) : error C2440: '=' : cannot convert from 'char [12]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast d:\bookcode\chap02\draw2d\winmain.cpp(82) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'char [12]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast d:\bookcode\chap02\draw2d\winmain.cpp(106) : error C2664: 'UnregisterClassW' : cannot convert parameter 1 from 'char [12]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast d:\bookcode\chap02\draw2d\winmain.cpp(108) : warning C4244: 'return' : conversion from 'WPARAM' to 'int', possible loss of data d:\bookcode\chap02\draw2d\winmain.cpp(121) : warning C4244: 'return' : conversion from 'LRESULT' to 'long', possible loss of data d:\bookcode\chap02\draw2d\winmain.cpp(160) : error C2664: 'D3DXCreateTextureFromFileW' : cannot convert parameter 2 from 'const char [12]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Build log was saved at "file://c:\Documents and Settings\James Dobrowski\My Documents\Visual Studio 2005\Projects\2D Polygon Practice\2D Polygon Practice\Debug\BuildLog.htm" 2D Polygon Practice - 9 error(s), 2 warning(s) I apologize if this seems a trivial matter, but I'm rather new to programming and any help would be appreciated. Thanks for everything!

Share this post


Link to post
Share on other sites
Oh, I did manage to fix:

d:\bookcode\chap02\draw2d\winmain.cpp(121) : warning C4244: 'return' : conversion from 'LRESULT' to 'long', possible loss of data

In my own programmes i use int WINAPI WinMain() and LRESULT CALLBACK WindowProc().

Share this post


Link to post
Share on other sites
Quote:
c:\microsoft platform sdk\include\winnt.h(222) : error C2146: syntax error : missing ';' before identifier 'PVOID64'
c:\microsoft platform sdk\include\winnt.h(222) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\microsoft platform sdk\include\winnt.h(5940) : error C2146: syntax error : missing ';' before identifier 'Buffer'
c:\microsoft platform sdk\include\winnt.h(5940) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\microsoft platform sdk\include\winnt.h(5940) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

I'm not too sure about these errors. Which version of the Platform SDK did you install?

Quote:
d:\bookcode\chap02\draw2d\winmain.cpp(72) : error C2440: '=' : cannot convert from 'char [12]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
d:\bookcode\chap02\draw2d\winmain.cpp(82) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'char [12]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
d:\bookcode\chap02\draw2d\winmain.cpp(106) : error C2664: 'UnregisterClassW' : cannot convert parameter 1 from 'char [12]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
d:\bookcode\chap02\draw2d\winmain.cpp(160) : error C2664: 'D3DXCreateTextureFromFileW' : cannot convert parameter 2 from 'const char [12]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

You need to change the project's character encoding. You can do this by going to "Project->Properties->Configuration Properties->General->Character Set" and set that to "Use Multi-Byte Character Set".


jfl.

Share this post


Link to post
Share on other sites
Ah thankyou very much! That did solve every problem but the 5 SDK build errors.

The SDK I installed is "Microsoft Platform SDK for Windows Server 2003 SP1." It's the SDK the Microsoft website indicated i should install on the page from which I downloaded Visual studio 8.

Share this post


Link to post
Share on other sites
Quote:
Original post by Helderash
Ah thankyou very much! That did solve every problem but the 5 SDK build errors.

The SDK I installed is "Microsoft Platform SDK for Windows Server 2003 SP1." It's the SDK the Microsoft website indicated i should install on the page from which I downloaded Visual studio 8.

Make sure that the Platform SDK includes are first in the directories list. Go to "Tools->Options->Projects and Solutions->VC++ Directories" and select "Show directories for: Include Files", then use the up arrow button to move the PSDK include directory above the DirectX include directory.

Share this post


Link to post
Share on other sites
Woo, thankyou once again.. all build errors solved!

Only one warning remains:

c:\documents and settings\james dobrowski\my documents\visual studio 2005\projects\2d polygon practice\2d polygon practice\test.cpp(108) : warning C4244: 'return' : conversion from 'WPARAM' to 'int', possible loss of data

Is this much of a problem?

Share this post


Link to post
Share on other sites
You can get rid of the warning by changing return Msg.wParam; to return static_cast< int >( Msg.wParam );. This is essentially telling the compiler: "Yeah I know int could be smaller than WPARAM, shoot me". Read: it isn't much of a problem in this case.

Share this post


Link to post
Share on other sites

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