D3DX11CompileFromFile doesn't work

Started by
11 comments, last by proanim 11 years, 6 months ago
I have been trying to make simple colored triangle, and everyting worked fine until i got to the point render a triangle with color shader. Why is it that D3DX11CompileFromFile function can't find the shader file even if it is placed in the project and in same folder as the exe file.

The program compiles without any errors or warning.

Also why is it that half of the program is messed up with LPCSTR and LPCWSTR conflicts when using #define UNICODE?
Advertisement
When you debug in Visual Studio, the working directory is set to the directory that the project is in. So if you're not going to use an absolute path to your shader file, you need to place the shader file in the same directory as the project. Are you sure your problem is that it can't find the file?

As for UNICODE, are you defining that manually? Usually you set this in the project properties instead of defining the macro yourself.
I just checked if i give absolute path it still can't find the file.

and the UNICODE i used #define UNICODE in the main header file of the project. It was defined like that on client-server sample on msdn.
Again, set the Unicode character set in the project options, don’t define it manually.
Right-click your project -> Properties -> Configuration Properties -> General -> Character Set -> Use Unicode Character Set.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

i just did that, it is the same thing as #define UNICODE. In both cases i need to change LPCSTR to LPCWSTR

i just did that, it is the same thing as #define UNICODE. In both cases i need to change LPCSTR to LPCWSTR

They are not the same. Once is scalable and reliable and one is not.

And yes, you need to change LPCSTR to LPCWSTR.
I am not sure why you are confused on this.
One is a char and one is a wchar_t. They are not the same type, and cannot be used interchangeably. By using UNICODE you have specified that you want to use wchar_t, so if you have any char’s being passed to those functions you will need to change them to wchar_t (or LPCWCHAR in your case), so what is the problem?


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

ok i understand UNICODE now, at this point i can change everything in my program, but i still don't see why D3DX11CompileFromFile or in this case D3DX11CompileFromFileW can't find the file even with absolute path. What can cause this to happen?
Can you show the string you use for absolute path? In C/C++ the path string may not look like what you expect it to look like.

Can you confirm the error given by the D3DX11CompileFromFile?

Cheers!
i think i tried every combination like:

L"color.hlsl" (and without L)
L"../shaders/color.hlsl" (and without L)
L"C:\\Documents and Settings\\...." (and without L)
L"C:/Documents and Settings/..." (and without L)

error is always the same if file is not found return file path like this:

[source lang="cpp"]// compile the vertex shader code
result = D3DX11CompileFromFileW(ShaderFileName, NULL, NULL, "ColorVertexShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &vertexShaderBuffer, &errorMessage, NULL);
if(FAILED(result))
{
// if the shader failed to compile it should have writen something to the error message
if(errorMessage)
OutputShaderErrorMessage(errorMessage, hwnd, ShaderFileName);
// if there was nothing in the error message then
// it simply could not find the shader file itself
else
MessageBoxW(hwnd, ShaderFileName, L"Missing Shader File", MB_OK);

return false;
}[/source]
Why not post the actual path of the shader?

And I mean via copy-and-paste.
Browse to the shader file, right-click it, select Properties, and copy/past the path.
Then add \ and select the file itself. Hit F2 and copy/paste.

Show result here.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement