VisualCExpress and Directx

Started by
17 comments, last by ridefast42 17 years, 9 months ago
Ok, I can compile windows applications now.Thank you for all of your help on that. I still can't seem to compile directx programs now. How would you go about compiling the drawing a triangle tutorial under the c++ tree on the right of http://www.riemers.net/Tutorials/DirectX/C++/tut5.php . Assume I don't know anything about compiling it which is not far from the truth lol.
Advertisement
Here are the errors I get upon building:

------ Build started: Project: Directx Test, Configuration: Debug Win32 ------
Compiling...
Directx Test.cpp
c:\documents and settings\neil dwyer\desktop\directx test\directx test.cpp(44) : error C2440: '=' : cannot convert from 'const char [16]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil dwyer\desktop\directx test\directx test.cpp(49) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [16]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil dwyer\desktop\directx test\directx test.cpp(60) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [39]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil dwyer\desktop\directx test\directx test.cpp(73) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [44]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil dwyer\desktop\directx test\directx test.cpp(118) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [34]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil dwyer\desktop\directx test\directx test.cpp(124) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [21]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil dwyer\desktop\directx test\directx test.cpp(137) : error C2664: 'NewWindow' : cannot convert parameter 1 from 'const char [21]' to 'LPCTSTR'
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\Neil Dwyer\Desktop\Directx Test\Debug\BuildLog.htm"
Directx Test - 7 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I am linking to d3d9.lib plus all of the other libs necessary(user32,kernal32,ect...).

Here is the code
#include<windows.h>#include<d3d9.h>#include<d3dx9.h> struct OURCUSTOMVERTEX {     float x,y,z,weight;     DWORD color; };  int int_AppRunning = 1;  LRESULT CALLBACK OurWindowProcedure(HWND han_Wind,UINT uint_Message,WPARAM parameter1,LPARAM parameter2) {     switch(uint_Message)     {         case WM_KEYDOWN:         {             int_AppRunning = 0;             break;         }         break;     }      return DefWindowProc(han_Wind,uint_Message,parameter1,parameter2); }  HWND NewWindow(LPCTSTR str_Title,int int_XPos, int int_YPos, int int_Width, int int_Height) {     WNDCLASSEX wnd_Structure;      wnd_Structure.cbSize = sizeof(WNDCLASSEX);     wnd_Structure.style = CS_HREDRAW | CS_VREDRAW;     wnd_Structure.lpfnWndProc = OurWindowProcedure;     wnd_Structure.cbClsExtra = 0;     wnd_Structure.cbWndExtra = 0;     wnd_Structure.hInstance = GetModuleHandle(NULL);     wnd_Structure.hIcon = NULL;     wnd_Structure.hCursor = NULL;     wnd_Structure.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);     wnd_Structure.lpszMenuName = NULL;     wnd_Structure.lpszClassName = "WindowClassName";     wnd_Structure.hIconSm = LoadIcon(NULL,IDI_APPLICATION);      RegisterClassEx(&wnd_Structure);      return CreateWindowEx(WS_EX_CONTROLPARENT, "WindowClassName", str_Title, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE, int_XPos, int_YPos, int_Width, int_Height, NULL, NULL, GetModuleHandle(NULL), NULL); }  LPDIRECT3DDEVICE9 InitializeDevice(HWND han_WindowToBindTo) {     LPDIRECT3D9 p_dx_Object;     LPDIRECT3DDEVICE9 p_dx_Device;      p_dx_Object = Direct3DCreate9(D3D_SDK_VERSION);     if (p_dx_Object == NULL)     {         MessageBox(han_WindowToBindTo,"DirectX Runtime library not installed!","InitializeDevice()",MB_OK);     }      D3DPRESENT_PARAMETERS dx_PresParams;     ZeroMemory( &dx_PresParams, sizeof(dx_PresParams) );     dx_PresParams.Windowed = TRUE;     dx_PresParams.SwapEffect = D3DSWAPEFFECT_DISCARD;     dx_PresParams.BackBufferFormat = D3DFMT_UNKNOWN;   if (FAILED(p_dx_Object->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, han_WindowToBindTo, D3DCREATE_HARDWARE_VERTEXPROCESSING, &dx_PresParams, &p_dx_Device)))  {         if (FAILED(p_dx_Object->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, han_WindowToBindTo, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &dx_PresParams, &p_dx_Device)))         {             MessageBox(han_WindowToBindTo,"Failed to create even the reference device!","InitializeDevice()",MB_OK);         }  }      return p_dx_Device; }  void DrawScene(LPDIRECT3DDEVICE9 p_dx_Device, LPDIRECT3DVERTEXBUFFER9 p_dx_VertexBuffer) {     p_dx_Device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);     p_dx_Device->BeginScene();      p_dx_Device->SetStreamSource(0, p_dx_VertexBuffer, 0, sizeof(OURCUSTOMVERTEX));     p_dx_Device->SetFVF(D3DFVF_XYZRHW|D3DFVF_DIFFUSE);     p_dx_Device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);      p_dx_Device->EndScene();     p_dx_Device->Present(NULL, NULL, NULL, NULL); }  LPDIRECT3DVERTEXBUFFER9 FillVertices(HWND han_Window, LPDIRECT3DDEVICE9 p_dx_Device) {     OURCUSTOMVERTEX cv_Vertices[3];     LPDIRECT3DVERTEXBUFFER9 p_dx_VertexBuffer;      cv_Vertices[0].x = 150;     cv_Vertices[0].y = 100;     cv_Vertices[0].z = 0;     cv_Vertices[0].weight = 1;     cv_Vertices[0].color = 0xffff0000;      cv_Vertices[1].x = 350;     cv_Vertices[1].y = 100;     cv_Vertices[1].z = 0;     cv_Vertices[1].weight = 1;     cv_Vertices[1].color = 0xff00ff00;      cv_Vertices[2].x = 250;     cv_Vertices[2].y = 300;     cv_Vertices[2].z = 0;     cv_Vertices[2].weight = 1;     cv_Vertices[2].color = 0xff00ffff;      if (FAILED(p_dx_Device->CreateVertexBuffer(3*sizeof(OURCUSTOMVERTEX), 0, D3DFVF_XYZRHW|D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &p_dx_VertexBuffer, NULL ) ) )     {         MessageBox(han_Window,"Error while creating VertexBuffer","FillVertices()",MB_OK);     }      VOID* p_Vertices;     if (FAILED(p_dx_VertexBuffer->Lock(0, 3*sizeof(OURCUSTOMVERTEX), (void**)&p_Vertices, 0)))     {         MessageBox(han_Window,"Error trying to lock","FillVertices()",MB_OK);     }else{         memcpy(p_Vertices, cv_Vertices, 3*sizeof(OURCUSTOMVERTEX));         p_dx_VertexBuffer->Unlock();     }      return p_dx_VertexBuffer; }  int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPreviousInstance,LPSTR lpcmdline,int nCmdShow) {     MSG msg_Message;      HWND han_Window = NewWindow("DirectX C++ Tutorial",100,100,500,500);     LPDIRECT3DDEVICE9 p_Device = InitializeDevice(han_Window);     LPDIRECT3DVERTEXBUFFER9 p_dx_VB = FillVertices(han_Window, p_Device);      while(int_AppRunning)     {         if(PeekMessage(&msg_Message,han_Window,0,0,PM_REMOVE))         {             DispatchMessage(&msg_Message);         }         DrawScene(p_Device, p_dx_VB);     }      p_Device->Release();     DestroyWindow(han_Window);      return 0; }
i bought a book (for beginners) for 80 dollars im having the same problems, they dont mention anything about linking just download sdk.
All of the LPCWSTR-related errors have nothing to do with DirectX.
It can be fixed by a project obtion (forgot which) but I usually fix it by casting all of the erroneous strings to an LPCWSTR.
____________________________________Spazuh- Because I've had too much coffee
I'm sorry, what does erroneous mean?
Causes errors.
I may have spelled erroneous wrong.
____________________________________Spazuh- Because I've had too much coffee
Ok, I should have known that.
You could turn off Unicode in Project->[Priject Name] Properties...->

or you could put L infront of all your strings or _T("string") or TEXT("string")...
F-R-E-D F-R-E-D-B-U-R...G-E-R! - Yes!
You guys are awesome. Thanks for all of your help. Now that I can compile, I can focus on learning the API's. Once again thanks a lot!

This topic is closed to new replies.

Advertisement