DirectX - CreateDeviceAndSwapChain returns E_INVALIDARG - c++

I'm trying to initialize Direct3D11 in C++. On machines that have Visual Studio installed(all of those are running on Windows 10), it runs fine.
On other computers (without Visual studio installed, Windows 10 and 7) it returns E_INVALIDARG.
The flag P_FeatureLevelsSupported says 0 on those computers. On mine it says D3D_FEATURE_LEVEL_11_1.
So I guess it has something to do with the DirectX installation or maybe because the SDK is missing( but wouldn't that be strange? :D )
By running dxdiag, I know that those machines support DirectX11_0.
Is there something i need to install?
The software has to run on the PCs of our clients.
The Code that causes the error:
const D3D_FEATURE_LEVEL lvl[] = { D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3, D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_1,
};
D3D_FEATURE_LEVEL P_FeatureLevelsSupported;
//see microsoft documentation, we use 11_1 or 11_0 if 11_1 is not supported by the client machine
//https://learn.microsoft.com/en-us/windows/desktop/direct3d11/overviews-direct3d-11-devices-initialize
result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, D3D11_CREATE_DEVICE_DEBUG, lvl, _countof(lvl), D3D11_SDK_VERSION, &swapChainDesc, &swapChain, &device, &P_FeatureLevelsSupported, &deviceContext);
if(result == E_INVALIDARG) //check with FEATURE_LEVEL_11_0
D3D11CreateDeviceAndSwapChain(NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
D3D11_CREATE_DEVICE_DEBUG,
&lvl[1],
_countof(lvl) - 1,
D3D11_SDK_VERSION,
&swapChainDesc,
&swapChain,
&device,
&P_FeatureLevelsSupported,
&deviceContext);
Thanks in advance :)

You are asking to create the debug device by passing in D3D11_CREATE_DEVICE_DEBUG. For that to succeed you must have D3D11*SDKLayers.dll installed which you probably have on your dev machines. See here for details which includes:
Debug Layer The debug layer provides extensive additional parameter
and consistency validation (such as validating shader linkage and
resource binding, validating parameter consistency, and reporting
error descriptions).
To create a device that supports the debug layer, you must install the
DirectX SDK (to get D3D11SDKLayers.dll), and then specify the
D3D11_CREATE_DEVICE_DEBUG flag when calling the D3D11CreateDevice
function or the D3D11CreateDeviceAndSwapChain function. If you run
your application with the debug layer enabled, the application will be
substantially slower. But, to ensure that your application is clean of
errors and warnings before you ship it, use the debug layer. For more
info, see Using the debug layer to debug apps.
Note
For Windows 8, to create a device that supports the debug layer,
install the Windows Software Development Kit (SDK) for Windows 8 to
get D3D11_1SDKLayers.dll.
If you don't need a debug device when on a customer machine just remove that flag.

Related

Unable to use the "runas" verb on programs requiring UAC

I have the following C code that should run the default Windows program changepk.exe with an UAC prompt
ShellExecute(NULL, "runas", "C:\\Windows\\System32\\changepk.exe", 0, 0, SW_SHOWNORMAL);
(Side note that the output of the ShellExecute is 2).
However, when I try to execute the 'changepk.exe' with these lines nothing happens at all, but for 'notepad.exe' instead of 'changepk.exe' it works and gives me an UAC prompt. What could be the issue here and what are the potential ways around it?
Error 2 is ERROR_FILE_NOT_FOUND. Make sure that changepk.exe actually exists on your machine at that path.
More importantly, if your app is a 32bit EXE running on a 64bit Windows, then you are likely encountering the File System Redirector at work, which will redirect "C:\\Windows\\System32\\..." to "C:\\Windows\\SysWOW64\\..." for 32bit processes.
If that is the case, try using WOW64's sysnative alias to reach the 64bit System32 folder from a 32bit app, eg:
ShellExecute(NULL, "runas", "C:\\Windows\\Sysnative\\changepk.exe", 0, 0, SW_SHOWNORMAL);
Or, you can disable the redirector temporarily by using Wow64DisableWow64FsRedirection(), eg:
PVOID oldValue;
Wow64DisableWow64FsRedirection(&oldValue);
ShellExecute(NULL, "runas", "C:\\Windows\\System32\\changepk.exe", 0, 0, SW_SHOWNORMAL);
Wow64RevertWow64FsRedirection(oldValue);
The reason why NotePad works is because a 64bit Windows provides both 32bit and 64bit versions of NotePad, so you end up running the correct one regardless of where "C:\\Windows\\System32\\notepad.exe" actually maps to.

Strange behaviour with RegQueryValueEx whitch return value of another register

I want to the path of Excel.exe from the registry. So i used the following:
I am using Windows64bits
RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, KEY_READ, &hKey)
with
szKey = "\Classes\CLSID\{ExcelCLSID}\LocalServer",
this register contains "C:\PROGRA~1\MIF5BA~1\Office15\EXCEL.EXE /automation"
Used this to get the Excel.exe Path
RegQueryValueEx(hKey, NULL, NULL, NULL, (BYTE*)szPath, &cSize)
So when building my solution for Platform x64, i get as path
C:\\PROGRA~1\\MIF5BA~1\\Office15\\EXCEL.EXE /automation
which is fine, but when building my solution for Win32 platform i get the
following path
"C:\\Program Files\\Microsoft Office\\Office15\\EXCEL.EXE" /automation
which is strange because this value is stored in the following registry
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Classes\CLSID\{ExcelCLSID}\
am i missing something here?
The Windows registry maintains, more or less transparently, different information for 32-bit and 64-bit applications running in the same environment. The Wow6432Node you see indicates that the value for that key is specific to 32-bit applications running on a 64-bit version of Windows.
You can disable the default registry redirection (see RegDisableReflectionKey), but in the majority of cases this isn't what you want to do.
See the information on registry redirection here.

Could not initialize Direct3D VS 2015 (Win 10)

I'm following the DirectX 11 Series 2 tutorial on rastertek.com. Presently I'm on Tutorial 3 (Initializing DirectX) and for some reason the CreateDeviceAndSwapChain function keeps failing when I run the program. I have followed the steps to link the Windows 10 SDK libraries and includes to the project from here (rastertek.com/dx12tut01.html) and my GPU is an Nvidia 780 Ti. I've also tried his pre-compiled .exe and that works fine. What's the problem? Let me know if screenshots are needed!
//enable debug mode
UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
#if defined( DEBUG ) || defined( _DEBUG )
flags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
//create the swap chain, d3d device, and d3d device context
result = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, &featureLevel, 1, D3D11_SDK_VERSION, &swapChainDesc, &m_swapChain, &m_device, NULL, &m_deviceContext);
if (FAILED(result)) {
return false;
}
Well, in my case, i have a laptop with intel hd 4400 and geforce 840m (using win10 + visual studio 2015), and i had set featureLevel to 11.1 manually, turned out that intel supports that feature level, but geforce suports maximum 11.0. Anyway, its still not clear what is your problem, what error message is, or anything else, so you can try lower feature level, pass 0 as flags.

Create a Direct3D12 Device fails with E_NoInterface

I'm trying to create a D3D12 device as specified in
https://msdn.microsoft.com/en-us/library/dn899120%28v=vs.85%29.aspx
I have a NVidia 670 gtx, Windows 10 preview build 9926, and last 10041 windows sdk.
I also have latest NVidia beta driver, system information for GeForce reports a DirectX12 runtime.
Calling
ID3D12Device* device;
HRESULT hr = D3D12CreateDevice(NULL, D3D_DRIVER_TYPE::D3D_DRIVER_TYPE_HARDWARE,
D3D12_CREATE_DEVICE_FLAG::D3D12_CREATE_DEVICE_NONE,
D3D_FEATURE_LEVEL::D3D_FEATURE_LEVEL_11_0, D3D12_SDK_VERSION, __uuidof(ID3D12Device), (void**)&device);
Returns me a HRESULT with NOINTERFACE error code
Strangely calling:
ID3D12Object* device;
HRESULT hr = D3D12CreateDevice(NULL, D3D_DRIVER_TYPE::D3D_DRIVER_TYPE_HARDWARE,
D3D12_CREATE_DEVICE_FLAG::D3D12_CREATE_DEVICE_NONE,
D3D_FEATURE_LEVEL::D3D_FEATURE_LEVEL_11_0, D3D12_SDK_VERSION, __uuidof(ID3D12Object), (void**)&device);
returns me a valid object, but I'm not able to use QueryInterface to get a valid device object afterwards.
Please note I already tried using LoadLibrary/GetProcAddress instead of using d3d12 headers, which returns same error code.
You should always use the same OS and SDK Build, because APIs can change betweens builds. Because you use SDK for Build 10041, you should also update Windows 10 to the Build 10041. Open the Settings App, and search for a new Windows 10 Build and install it.

ADO objects instance creation failed on the target computer

I created an MFC application using VC++ 6.0 on my development computer installing Windows XP SP3. In this application, I used ADO objects to access SQL database server :
CoInitialize (NULL);
try
{
_ConnectionPtr pConn;
HRESULT hr = pConn.CreateInstance (__uuidof (Connection));
if (FAILED (hr))
{
AfxMessageBox ("Can't create intance of Connection");
}
//...
}
//...
Of course, the app works fine on my computer. However, I copied the whole Release folder of the app and then run it on another computer with Windows XP SP3 installed, the app failed at creating the Connection object with hr = -2147467262.
I searched on the internet much but don't see any resolution.
Does anyone know this issue and could you give me some guides on that?