Sign in to follow this  

VisualCExpress and Directx

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

How do i get the directx sdk working with visual c++(express). The express edition does not even come with the windows.h file.Do I just copy the files from the directx sdk in their corresponding directories in visual c++? Also, how do you link libraries in VCE?

Share this post


Link to post
Share on other sites
Thanks for such a quick reply!I noticed that the PSDK is processor specific. Does this mean that all of the programs will not be portable to other processors?I am assuming the answer is no but I want to make sure.

Share this post


Link to post
Share on other sites
Quote:
Original post by ridefast42
Thanks for such a quick reply!I noticed that the PSDK is processor specific. Does this mean that all of the programs will not be portable to other processors?I am assuming the answer is no but I want to make sure.

You've almost got it. It's architecture specific, so it will work on different models of x86 processors, but you'll need a different SDK for 64-bit CPUs.

Share this post


Link to post
Share on other sites
In order to be able to compile in win32 you should follow these steps:
http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/

Note: In the step 2 you will install "Windows Server 2003 SP1 Platform SDK Web", but you have to be carrefull since in the step 3 the expanation will reference to "C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\"

Share this post


Link to post
Share on other sites
Quote:
Original post by ridefast42
Now that I have the PSDK and directx sdk downloaded, do I just copy and paste the header files of the two sdk's into the vce include directory?
You don't have to you can just tell VCE where to look for them (directory where they are).

Quote:
Step 3: Update the Visual C++ directories in the Projects and Solutions section in the Options dialog box.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Ok, I think I will just copy and paste them in because I don't really want to change the project options everytime.

Share this post


Link to post
Share on other sites
You don't necessarily have to change them every time. Once you add the directory to the list you are all set.
After the respective directories for the PSDK and DirectX are added, you only have to supply the filename of the library that you want to link to.
For example, in the project optionsunder Linker->Input I add 'd3d9.lib' to the Additional Dependencies list.
It may sound a little confusing at first (especially coming from a different environment) but you'll get the hang of it.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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")...

Share this post


Link to post
Share on other sites

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