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?
 
Associate
Joined
10 Nov 2013
Posts
1,808
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.
 
Last edited:
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.
 
Caporegime
Joined
18 Oct 2002
Posts
32,623
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.
 
Last edited:
Man of Honour
Joined
13 Oct 2006
Posts
92,043
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.
 
Last edited:
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.
 
Caporegime
Joined
18 Oct 2002
Posts
32,623
It doesn't look like you are using the right parameter types for the version of the function you are calling.
 
Associate
Joined
2 Jun 2007
Posts
1,180
Location
Bradford
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.
 
Last edited:
Man of Honour
Joined
13 Oct 2006
Posts
92,043
Weird I'd have thought you'd have got an error along the lines of "cannot convert argument unsigned blah to blah" or whatever - but with the mess of overloaded stuff I guess its not surprising.
 
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:
Associate
Joined
2 Jun 2007
Posts
1,180
Location
Bradford
With the single change I specified in my last post, the code compiles and runs fine for me in both 32 and 64 bit builds.
size_t is 64 bits in x64 build and 32 bits in a Win32 build.
unsigned long long is 64 bits on both Win32 and x64 with the Microsoft implamentation, so the code wont compile correcly on a 32 bit build when the type for stringLength is unsigned long long.
The first parameter to wcstombs_s is a pointer to a size_t, therefor the correct type for stringLength is size_t.
It's a mistake in the tutorial code.
 
Last edited:
Associate
Joined
2 Jun 2007
Posts
1,180
Location
Bradford
Learning Direct3D from OpenGL.
Direct3D is object oriented C++ COM model, while OpenGL is a C based state machine model.

Probably the the best way to transition from OpenGL to Direct3D (IMO), is to use the Microsoft SDK documentation, samples and tutorials.
Even though Direct3D is C++ OO, the samples and tutorials take a much more linear C type aproach which I think is best when your learning and coming from an OpenGL background.

Also with DirectX being COM based, you will need to get into the Create...., release... thing instead of constuctor, delete when dealing with DirectX interfaces.

The site you are using for tutorials just wraps the Microsoft Examples (very badly IMO) in C++ classes.

Feel free to create your own classes when you've got everthing sussed, but I think MS tuts are best when going from OpenGL to Direct3D.

Also the problems you experienced here aren't specific to Direct3D.
Somedody used the wrong type when declaring a variable and wcstombs_s is part of the C runtime library and not a part of Direct3D.
 
Associate
Joined
2 Jun 2007
Posts
1,180
Location
Bradford
Why not dx12?
No reason not, but it's not easy for anyone ATM. :)

Still very early days for DX 12 development.

Requirements:
OS: Windows 10

Dev environment: Visual Studio 2015
The free community edition is available here

The only real samples I've seen so far are the MS examples on Github here

MSDN documentation is here
Documention still seems quite preliminary and in some cases incorrect, refering to beta releases of DX 12 SDK.

General Discussion and help regarding DX 12 development is available on gamedev.net forums here
 
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!)
 
Man of Honour
Joined
13 Oct 2006
Posts
92,043
Why not dx12?

There are a lot of concepts that IMO are easier to get your head around in an earlier DX say 11 and then understand from that perspective why they are the way they are in DX12 than trying to understand them new to DX12. (With that background IMO you then tend to make more efficient use of the features understanding a bit of the "history" of them).

EDIT: I really should get back into it for a bit while I've messed about a bit with DX11/12 samples - haven't created anything from the ground up since DX7.
 
Last edited:
Associate
Joined
2 Jun 2007
Posts
1,180
Location
Bradford
There are a lot of concepts that IMO are easier to get your head around in an earlier DX say 11 and then understand from that perspective why they are the way they are in DX12 than trying to understand them new to DX12. (With that background IMO you then tend to make more efficient use of the features understanding a bit of the "history" of them).

EDIT: I really should get back into it for a bit while I've messed about a bit with DX11/12 samples - haven't created anything from the ground up since DX7.

Agree completly with being into Direct3D 11 before going to Direct3D 12, and as the Direct3D 12 documentation currently stands, that seems to be the recommended route ATM.

MSDN Direct3D 11 docs are very good IMO, both at the reference level for types, interfaces etc, but more importantly at the general workflow level.

Direct3D 12 docs are sort of OK at the reference level, but still with mistakes refering to beta versions of the API. General workflow documentation is very lacking in Direct3D 12 docs, and indeed, this is the way in which Direct3D 12 most differs from Direct3D 11.

With the openness of Direct3D 12, I don't think they'd be able to document a "general" workfow in the same way as the Dx 11 docs. I think they would have to document several "example" workflows.

There again, you've got the engines like unreal engine 4 which will be used in a very "general" way, where DX 12 will be an option??

I've seen some very experienced people on gamedev.net slowly getting things together, on a sort of trial and error basis, but I think most people would agree that DX 12 SDK documentation is in its very early stages still.

Personally, I'm going to wait until the docs are more mature before going for DX 12, but more and more, I'm thinking I'll go the engine route (say UE4) rather than bare DX 12.
 
Back
Top Bottom