What's wrong with this simple DirectX prg?

Miscellaneous Forums/General Discussion/What's wrong with this simple DirectX prg?

Hi all,

I just want to print the results of subtraction of two vectors.
I installed VC++ 2005 express and DirectX SDK April 2006

Project types: Visuall C++, Win32, Win32 Console Application, Empty project

	
#include <d3dx9math.h> 
#include <stdio.h> 
main(){ 
   D3DXVECTOR3 A3 (5.0f,2.6f,10.f); 
   D3DXVECTOR3 B3 (2.0f,3.4f,3.0f); 
   D3DXVECTOR3 C3=A3-B3; 
   printf("C3=A3-B3=(5.0f,2.6f,10.2)-(2.0f,3.4f,3.0f)=(%f,%f,%f)\n",C3.x,C3.y,c3.z); 
   return 0; 
}    


When I run the prg, I get...
------ Build started: Project: start, Configuration: Debug Win32 ------
Compiling...
start.cpp
c:\program files\microsoft directx sdk (april 2006)\include\d3d9.h(40) : fatal error C1083: Cannot open include file: 'objbase.h': No such file or directory
Build log was saved at "file://c:\testdirectx\begin\start\start\Debug\BuildLog.htm"
start - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Configuration settings of VC++ 2005 express:
Tools>options
"Projects and Solutions" > VC++ Directories

(1) Platform: Win32; Show directories for: Include files
C:\Program Files\Microsoft DirectX SDK (April 2006)\Samples\C++\Common
C:\Program Files\Microsoft DirectX SDK (April 2006)\Include
$(VCInstallDir)include
$(VCInstallDir)PlatformSDK\include
$(FrameworkSDKDir)include

(2) Platform: Win32; Show directories for: Library files
C:\Program Files\Microsoft DirectX SDK (April 2006)\Lib\x86
$(VCInstallDir)lib
$(VCInstallDir)PlatformSDK\lib
$(FrameworkSDKDir)lib
$(VSInstallDir)
$(VSInstallDir)lib

Any ideas?

Thanks in advance.
:)


I installed VC++ 2005 express and DirectX SDK April 2006



You also need to install a specific platform SDK (check in your start menu for an entry for Microsoft Platform SDK for Windows blah blah... to make sure you haven't already installed one, i used the Windows Server 2003 R2 sdk.)

Oh, and its **int** main() and ***C3.z***... to get it to build without errors.

Hi skiracer,

I just installed microsoft platform SDK, but I still
get the same error message. What's wrong with it?

i have $(VCInstallDir)PlatformSDK\include but also a full path to the sdk's include folder I installed (which has it's own path). Which one did you install and did you check your start menu for it?

Hi skidracer,

I finally get it worked! Thanks a lot!

As mentioned above, "objbase.h" still could not be located.
Thus, I search for it and find it in
"C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include"
Then, I added this line to VC++ Directories - include files.
Also, I amend it as you said.

#include <d3dx9math.h> 
#include <stdio.h> 
main(){ 
   char c;  // dummy

   D3DXVECTOR3 A3 (5.0f,2.6f,10.f); 
   D3DXVECTOR3 B3 (2.0f,3.4f,3.0f); 
   D3DXVECTOR3 C3=A3-B3; 
   printf("C3=A3-B3=(5.0f,2.6f,10.2)-(2.0f,3.4f,3.0f)=(%f,%f,%f)\n",C3.x,C3.y,c3.z); 

   scanf("%c",&c);  // waiting for pressing any key.
   return 0; 
}    


Thanks a lot!

Hi all,

Here is another simple prg that returns error...

#include "stdafx.h"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	cout << "Hello";
	system("pause");
	return 0;
}


When I run the prg, I get...
------ Build started: Project: testing, Configuration: Debug Win32 ------
Compiling...
testing.cpp
c:\testdirectx\testing\testing\testing.cpp(5) : error C2871: 'std' : a namespace with this name does not exist
c:\testdirectx\testing\testing\testing.cpp(9) : error C2065: 'cout' : undeclared identifier
c:\testdirectx\testing\testing\testing.cpp(10) : error C3861: 'system': identifier not found
Build log was saved at "file://c:\testdirectx\testing\testing\Debug\BuildLog.htm"
testing - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Any ideas?

(My configuration is same as above)

Thanks in advance

"A golden rule of c++ is that everything must be declared before it can be used." - Visual C++ .NET In Action

I have Dev-cpp here, so i don't have "stdafx.h" but i do have "stdlib.h" which looks like an equivalent of it.

Basically, you need to include the file "iostream" to get that working.

Here is your code converted to compile in Dev-cpp.

// "testing.cpp" (in Dev-cpp)

#include <iostream>
#include "stdlib.h" // #include "stdafx.h"

using namespace std;

int main(int argc, char *argv[]) // int _tmain(int argc, _TCHAR* argv[])
{
	cout << "Hello" << endl;
	system("pause");
	return 0;
}


Thank you, muk.
Yes, you are absolutely right!
(I just follow an examples of some textbook. The book said that it ran correctly.)

#include <iostream>
#include "stdafx.h"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	cout << "Hello";
	system("pause");
	return 0;
}