I try to merge all the image resources to a folder called resource. So, set image path as "resource/" but my directX framework only works if I compile at VS 2010. If I run from the debug folder it cannot run.(I already copy all the image resources to debug folder)


string folder = "resource/";

void setTexture(LPDIRECT3DTEXTURE9& texture, string imgName, int imgWidth, int imgHeight, D3DCOLOR TransparentColorKey)
    string path;

    path = folder + imgName;

    //  Create texture.
    hr = D3DXCreateTextureFromFileEx(d3dDevice, path.c_str(), imgWidth, imgHeight, 
        D3DX_DEFAULT, D3DX_DEFAULT, TransparentColorKey, NULL, NULL, &texture);

A simple way would be to configure your output directory for your project and then set your working directory to that folder.

1) Set your output directory. This folder holds your .exes, .liks and .pdbs. In this example I will output to a folder called Bin outside of my project directory.

2) As you are outputting to a folder for multiple configs, you will want to modify your target name so they can be distinguished between debug and release. In this example I have appended _debug to my Target Name for my Debug config and _release for my Release config so that when I build both configs there will be two sets of files for each config.

Output Config

So now you will have a folder storing your exe outside of your project root.

3) Create your Resource folder in the same directory as your Bin and Project. The folder structure will look something along the lines of:

 -- DirectX FrameWork  
    |-- Bin  
    |-- Project  
    |-- Resources

4) Set your working directory to your Bin folder.

Configure Working Directory

Now as you can see, when you run from Visual Studio or the .exe they will both be using the same working directory, so the same relative file path can be used when referencing files. Doing this also helps to separate your code from your resources.


There are multiple things that can cause this but maybe try this, if that doesn't work please provide us with more information about the project and deployment setup

When running via Visual Studio the CWD (current working directory) is that of the project (by default) so the path to your files is "./resource/" while if you're running from the debug folder your CWD is that of the executable, so the path to the resources is "./../resource/".

You have to set up that your resources are copied to the output directory. You can do this in the solution explorer by selecting the resource and selecting "Copy To Output Directory"

enter image description here

  • \$\begingroup\$ Why it goes to property pages after I click properties? i.stack.imgur.com/ok6Fe.png \$\endgroup\$
    – user
    Jul 13 '13 at 8:09
  • \$\begingroup\$ That is weird, as what kind of file type have you added the png? (Resource, Content, ...?) \$\endgroup\$
    – Roy T.
    Jul 13 '13 at 8:14
  • \$\begingroup\$ yup. I add png image file into resource folder \$\endgroup\$
    – user
    Jul 13 '13 at 8:28
  • \$\begingroup\$ Ok. Now I can show file properties but I dun have advanced section. i.stack.imgur.com/GXOFl.png \$\endgroup\$
    – user
    Jul 13 '13 at 8:33
  • \$\begingroup\$ I'm very curious why this answer was voted down at least twice, are there any errors? I think it is a plausible answer given the tiny bit of information in the question. \$\endgroup\$
    – Roy T.
    Jul 14 '13 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.