DirectX 11 Framework help required! C++

Soldato
Joined
8 Jan 2012
Posts
2,802
So I'm following this tutorial here (http://www.rastertek.com/dx11s2tut03.html) to setup a DX11 framework in C++ so that eventually I can create a graphics engine.

Now the issue persists upon this code:

// Convert the name of the video card to a character array and store it.
error = wcstombs_s(&stringLength, m_videoCardDescription, 128, adapterDesc.Description, 128);
if(error != 0)
{
return false;
}

I've never used wcstombs_s before but upon reading it I think I'm using it correctly... (Even copy pasted it flags as an error but I typed it out manually the first time since I tend to learn a bit better that way)

The issue is that I get an error of:

No instance of overloaded function "wcstombs_s" matches the argument list. Argument types are: (unsigned long long*, char[128], WCHAR[128], int).

I've tried trimming it down to a 3 variable instance of the function... For reference:

http://www.cplusplus.com/reference/cstdlib/wcstombs/

Following this. And it still comes up with the no instance of overloaded function.

Has anyone got any advice on using wcstombs_s/can see the issue that I can't in the code I followed?
 
Soldato
OP
Joined
8 Jan 2012
Posts
2,802
Might not be any help, but..

Is your second parameter an address to your string variable? Also it's good practice to use sizeof(var) instead of hardcoding 128.

Yeah I know it's better to use sizeof (not my code I just followed the tutorial :p will make changes later)

The second variable is an address of the string relating to the GPU's name/info.
 
Soldato
OP
Joined
8 Jan 2012
Posts
2,802
The error is as the compiler says, the function signature takes 4 parameters , while your link shows 3, so you must be using a different version of the c standard library (likely some nasty windows version). You have given the function 5 parameters, with an additional int. You need to modify the code to sort your system, and lay attention to the compiler, it is usually quite helpful.

I figured what the tutorial says is wrong. I tried a 4 parameter version without the extra int... as well as dropping to a version similar to that of the cplusplus method. Both resulted in no difference whatsoever.

So what happens if you do:

error = wcstombs_s(&stringLength, m_videoCardDescription, adapterDesc.Description, 128);

?

Under the assumption you are using some variant of the library that expects you to use 1 buffer size.

EDIT: What IDE are you using?

EDIT2: The only definitions I can find of it with 3 or 4 parameters are from old C libraries and not recent C++ stuff :S and the last int is sizeof the output buffer and apparently you have to be careful with that as its very easy to overwrite memory or something :S the whole implementation looks a mess and I'd run a mile before using it if I did any programming any more :S get all kinds of errors in the IDE about "not sure which overloaded instance is intended" and the old version doesn't seem to be thread safe.

Using VS2013. My friend also followed this tutorial and I don't think he had this issue/he's a bit more experienced than I am and found another way of getting the same result (unsure of which and he's currently on holiday so no PC for him to tell me ahah). I tried both the 3 variable and 4 variable function.

Dropping one of the ints so it looks like this:

Code:
error = wcstombs_s(&stringLength, m_videoCardDescription, adapterDesc.Description, 128);

Results in a compiler error of neither overloaded function being able to convert all the argument types.

This is the first time I've coded in a while. As well as it being the first time I've done anything beyond simple OpenGL stuff. So I'm a little rusty as is.
 
Soldato
OP
Joined
8 Jan 2012
Posts
2,802
It doesn't look like you are using the right parameter types for the version of the function you are calling.

It tells you right in the error message:

I got that however changing unsigned long long to size_t flags the size_t as inconvertible as well?
Looks like an error in the tutorial?

Just change the type of stringLength from unsigned long long to size_t.

i.e. change this line:

Code:
unsigned long long stringLength;
in the D3DClass::Initialize function, to:

Code:
size_t stringLength;
Source then compiles and runs OK.

Edit:
Also Depends if you do a Win32 or x64 build.
When building as a 64 bit app, unsigned long long IS compatible with size_t and the original code compiles without error.

Tried that see above. :/

Upon further looking into Cambofrogs part about win32 or x64 I converted the project to x64 and everything is now compiling perfectly... What a pain.. I swear I set it as x64 to begin with.. Cheers for the help (and pointing out the obvious. It really helps when you only just come back to C++ after ages of C# in Unity or only doing OpenGL stuff in C++ to DX11 to have people make sure you do everything right!)
 
Last edited:
Soldato
OP
Joined
8 Jan 2012
Posts
2,802
Why not dx12?

Mostly lack of tutorials. Plus DX12 is still early on in its cycle. The SDK is yet to be properly released (as far as I know you have to actually deal with files etc)

I was going to wait for Vulkan in all honesty. But its too far away so DX11 seemed the intermediate go to with plenty of tutorials/sources about to help me out. I will do DX12 at some point. But Vulkan will probably be before that. (Open platform whilst I solo dev games? Great!)
 
Back
Top Bottom