Create a Direct3D12 Device fails with E_NoInterface - c++

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.

Related

DirectX - CreateDeviceAndSwapChain returns E_INVALIDARG

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.

Programmatically installing printer drivers from Windows Update

I'd like to be able to programmatically install a selected printer driver from Windows Update. I've tried doing so with something like the following code, but the only search results returned were the collection of Windows Language Packs that I haven't installed.
IUpdateSearcher *pUpdateSearcher = NULL;
// Snip instantiation code
pUpdateSearcher->put_ServerSelection(ssWindowsUpdate);
pUpdateSearcher->put_CanAutomaticallyUpgradeService(VARIANT_TRUE);
pUpdateSearcher->put_IncludePotentiallySupersededUpdates(VARIANT_TRUE);
pUpdateSearcher->put_Online(VARIANT_TRUE);
hr = pUpdateSearcher->Search(
BSTR(TEXT("Type='Driver' AND IsInstalled=0 AND IsHidden=0")),
&pSearchResult
);
Is there a way I could programmatically search Windows Update for printer drivers in a way similar to how you can search Windows Update when manually installing a printer?

HRESULT "Class Not Registered" Implementing simple COM server DLL

I'm following this sites tutorial:
http://progtutorials.tripod.com/COM.htm
Preliminary evidence: Visual Studio 2010, Windows 7 64 bit.
and I'm coding the examples in section 3. (Implementing a server DLL). I've typed out the code exactly as shown and I'm getting a "Class not registered" exception when executing this code on line 12 of the code outlined in section 4.1 (where the tutorial shows you how to access the DLL and I have followed 3.1 to the letter):
hresult hr = CoGetClassObject(CLSID_Car, CLSCTX_SERVER, NULL, IID_IClassFactory, (void **) &pClassFactory);
I tried running:
regsvr32 xyz.dll
with xyz.dll being the path to my dll in order to register the DLL. This resulted in an error trying to find DLLRegisterServer:
I have already run
REGEDIT
HKEY_CLASSES_ROOT\CarDLL.Car\CLSID = {d969084c-b758-43ea-a218-a48763167abd}
HKEY_CLASSES_ROOT\CLSID\{d969084c-b758-43ea-a218-a48763167abd} = CarDLL.Car
HKEY_CLASSES_ROOT\CLSID\{d969084c-b758-43ea-a218-a48763167abd}\InProcServer32 = C:\Users\wiocl2\Documents\Visual Studio 2010\Projects\CarDLL\debug\CarDLL.dll
that I assumed put all the GUIDS I needed in the registry (The GUIDS were generated by me).
I'm assuming that a function is needed to be added to the class that allows it to be registered but I don't know how to do this and how to go about figuring it out. I'm kind of lost, as I haven't been working with COM for very long. If someone could give me a shove in the right direction that would be helpful.
Edit: Oh yes, I moved
#include // contains definition of DEFINE_GUID
to the iid.h file from iid.cpp, otherwise I was getting unresolved external errors on the build.
The most likely explanation: you are building your COM object as a 32-bit DLL, but the registration has been performed as a 64-bit DLL.
The treatment: open an admin privileged command window and navigate to the location of your DLL (C:\Users\wiocl2\Documents\Visual Studio 2010\Projects\CarDLL\debug). Once there, type:
c:\windows\sysWOW64\regedit <filename of .reg file whose contents are displayed above>
This will run the 32-bit version of REGEDIT, ensuring that the registry entries are created in the correct part of the hive. To verify this, you should see an entry for {d969084c-b758-43ea-a218-a48763167abd} in HKLM\Software\Wow6432Node\Classes\CLSID, not HKLM\Software\Classes\CLSID.
DllRegisterServer is a method you can implement in your COM server DLL, and is required if you want to use regsvr32 to perform the same operation you are currently using the .REG approach for. The same caveat applies: for a 32-bit DLL, you'll need to invoke c:\windows\sysWOW64\regsvr32.exe.
And Yes! COM is still mostly alive and well :) At least there is still standard support for it in VS 2012.
Hope that helps.

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?

Out-of-Proc-COM-Server (x86): dllhost.exe looks in wrong registry path

I write for a COM-Server (x86) a wrapper based on a DLL surrogate (x64) described like here to get access from a 64-bit-client.
I registered the COM-Server (x86) and the Proxy/Stub-DLL (x86) and they registered in the WOW6432-Nodes.
But when I call the instance with
IShellServerx86* pShellServer = NULL;
::CoCreateInstance(__uuidof(CShellServerx86), NULL, CLSCTX_LOCAL_SERVER |
CLSCTX_ACTIVATE_32_BIT_SERVER, __uuidof(IShellServerx86),
(void**)&pShellServer);
the dllhost.exe is started and I get back "Class not registered". When I analyse the dllhost.exe (x86-version!) with procmon I can see that the dllhost.exe tries to look up the paths in the 64bit-registry and not in the WOW6432-Nodes.
I tried to dupliate the registry entries into the 64-bit-paths but then I get back "%1 is not a WIN32 application".
How can I can COM to look up in the 32-bit paths? Is the flag "CLSCTX_ACTIVATE_32_BIT_SERVER" not enough?
Thanks for your help in advance.
Tobias
EDIT:
I found at MSDN this article that told that with Windows 7 registry reflection is disabled? It is said that all CLSIDs that contains a InprocServer32-Key are not reflected. But how then can I achieve reflection when I use System-Surrogation?