C++ DirectX skipped when looking for precompiled header

  • Context: C/C++ 
  • Thread starter Thread starter Superposed_Cat
  • Start date Start date
  • Tags Tags
    C++
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
13 replies · 4K views
Superposed_Cat
Messages
388
Reaction score
5
Hi all, I main c# and XNA, but XNA is really outdated and requires the player (I'm using XNA for game making) to install it, i wanted to use something windows native so i decided to choose Direct X because i knew some c++. I copied and pasted code to open a blank window to look through but I get the error:

"Warning 1 warning C4627: '#include <windows.h>': skipped when looking for precompiled header use c:\users\e\documents\visual studio 2012\projects\first directx\first directx\first directx.cpp 2 1 first directx"

now tried a different code sample from a different site and had the same issue. I was under the impression that direct x being native wouldn't need special include paths. I have $(IncludePath);$(DXSDK_DIR)Include under additional include directories and $(LibraryPath);$(DXSDK_DIR)Lib\x86 under the using directories, what am i doing wrong? I have googled the issue and every variation of my problem takes me to the same stackoverflow page. thanks in advance.
 
on Phys.org
oh, tanks. i just googled the error message and not the actual error value.
 
aright second question if no body minds is does anyone know the location of d3dx9.h?
 
Superposed_Cat said:
aright second question if no body minds is does anyone know the location of d3dx9.h?
Have you downloaded the DirectX SDK? Here's a link to the June, 2010 release: http://www.microsoft.com/en-us/download/details.aspx?id=6812

I'm not sure if that's the latest release or the release that you need for your version of VS. If it's not, do a web search for DirectX SDK. They have a developer center that should have a link to whatever version you need.
 
I did all that. i got the error "unexpected end of file, did you forget to add "include "stdfx.h""?" so i added it then i get :
Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup C:\Users\E\Documents\Visual Studio 2012\Projects\hopes run\hopes run\MSVCRTD.lib(crtexe.obj) first
 
literally reinstalled directx sdk and c++.literally reinstalled directx sdk and c++.
 
Give this a shot...
In the Visual Studio IDE, open Solution Explorer.
Select the project.
Right click the project, and select Properties, which should be the last thing on the right-click menu.
On Property Pages for the project, under Configuration Properties, click C/C++.
Under C/C++, select Precompiled Headers.
In the pane on the right, the first thing listed is Precompiled Header, which has a pull-down menu.
Select Not Using Precompiled Header. The other choices are Create and Use.

I'm currently using VS 10. If you're using a different version, you might see something different.

Let me know if that helps out any.
 
nope, sorry i thank you for the advie anyway, twas good.

"Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup C:\Users\E\Documents\Visual Studio 2012\Projects\first directx\first directx\MSVCRTD.lib(crtexe.obj) first directx
"

thats the new error
 
Code:
// include the basic windows header files and the Direct3D header file
#include <stdafx.h>
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>

// define the screen resolution
#define SCREEN_WIDTH  800
#define SCREEN_HEIGHT 600

// include the Direct3D Library file
#pragma comment (lib, "d3d9.lib")

LPDIRECT3D9 d3d; // the pointer to our Direct3D interface
LPDIRECT3DDEVICE9 d3ddev; // the pointer to the device class

// function prototypes
void initD3D(HWND hWnd); // sets up and initializes Direct3D
void render_frame(void); // renders a single frame
void cleanD3D(void); // closes Direct3D and releases memory

// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);


// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    HWND hWnd;
    WNDCLASSEX wc;

    ZeroMemory(&wc, sizeof(WNDCLASSEX));

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    // wc.hbrBackground = (HBRUSH)COLOR_WINDOW;    // not needed any more
    wc.lpszClassName = L"WindowClass";

    RegisterClassEx(&wc);

    hWnd = CreateWindowEx(NULL,
                          L"WindowClass",
                          L"Our Direct3D Program",
                          WS_EX_TOPMOST | WS_POPUP,    // fullscreen values
                          0, 0,    // the starting x and y positions should be 0
                          SCREEN_WIDTH, SCREEN_HEIGHT,    // set the window to 640 x 480
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

    ShowWindow(hWnd, nCmdShow);

    // set up and initialize Direct3D
    initD3D(hWnd);

    // enter the main loop:

    MSG msg;

    while(TRUE)
    {
        while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        if(msg.message == WM_QUIT)
            break;

        render_frame();
    }

    // clean up DirectX and COM
    cleanD3D();

    return msg.wParam;
}


// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
        case WM_DESTROY:
            {
                PostQuitMessage(0);
                return 0;
            } break;
    }

    return DefWindowProc (hWnd, message, wParam, lParam);
}


// this function initializes and prepares Direct3D for use
void initD3D(HWND hWnd)
{
    d3d = Direct3DCreate9(D3D_SDK_VERSION); // create the Direct3D interface

    D3DPRESENT_PARAMETERS d3dpp; // create a struct to hold various device information

    ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use
    d3dpp.Windowed = FALSE;    // program fullscreen, not windowed
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames
    d3dpp.hDeviceWindow = hWnd;    // set the window to be used by Direct3D
    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;    // set the back buffer format to 32-bit
    d3dpp.BackBufferWidth = SCREEN_WIDTH;    // set the width of the buffer
    d3dpp.BackBufferHeight = SCREEN_HEIGHT;    // set the height of the buffer


    // create a device class using this information and the info from the d3dpp stuct
    d3d->CreateDevice(D3DADAPTER_DEFAULT,
                      D3DDEVTYPE_HAL,
                      hWnd,
                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                      &d3dpp,
                      &d3ddev);
}


// this is the function used to render a single frame
void render_frame(void)
{
    // clear the window to a deep blue
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);

    d3ddev->BeginScene();    // begins the 3D scene

    // do 3D rendering on the back buffer here

    d3ddev->EndScene();    // ends the 3D scene

    d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen
}


// this is the function that cleans up Direct3D and COM
void cleanD3D(void)
{
    d3ddev->Release(); // close and release the 3D device
    d3d->Release(); // close and release Direct3D
}

my code.

if anyone could please look thorugh it/try compile it to see if they have issues. I really want to learn this engine.
 
Last edited:
Your Visual Studio project is configured for a console application. So the linker expects a main() entry point. While your C++ code is for a GUI application, whose entry point is WinMain(). Change the project properties to match your code; or recreate the project, making sure you specify the correct application type (GUI/Windows).
 
  • Like
Likes   Reactions: 1 person
Thanks. I did everything you guys said, which solved it, but I am getting the error:
MSB6006: "link.exe" exited with code 1120. this is in a win32 project. precompiled headers switched off.
 
MSB6006 is a message from the build system. You should also get a message from the linker, prefixed with LNK, that explains what the error is. Assuming that the exit code would be equal to the error number, and googling for LNK1120, I get this: http://msdn.microsoft.com/en-us/library/z98k84c3.aspx So you still have some unresolved externals, and other messages from the linker should tell you what they are.
 
  • Like
Likes   Reactions: 1 person
Thanks again, your obdurate helpfulness is unparalleled all of you.