Can I get IntPtr from IDirect3D11Device - nvidia

I am using Win2D. I want to apply NVIDIA Reflex SDK to my game. To achieve this, NVIDIA Reflex SDK requests Direct3DDevice object. I think CanvasDevice (which implements IDirect3D11Device) matches Direct3DDevice.
So, how can I get a native Direct3DDevice object from IDirect3D11Device. Or, am I misunderstand this?

IntPtr id2d1device1 = Marshal.GetComInterfaceForObject(MyCanvasDevice, typeof(IDirect3DDevice));

Related

MvxRecyclerView NotSupportedException

I want to implement list of different types using MvxRecyclerView and ItemTemplateSelector but I get not supported exception when I only try to show activity with MvxRecyclerView.
System.NotSupportedException has been thrown.
Could not activate JNI Handle 0x7ffc627020 (key_handle 0xc743032) of Java type 'mvvmcross/droid/support/v7/recyclerview/MvxRecyclerView' as managed type 'MvvmCross.Droid.Support.V7.RecyclerView.MvxRecyclerView'.
The same when I add binding to ItemsSource, MvxTemplateSelector or MvxItemTemplate. Nothing helps. What am I missing?
I decided to post my answer as I had the same issue in MvvmCross 8.0.2 despite using the MvvmCross.DroidX.RecyclerView.MvxRecyclerView.
The solution in my case was to add MvvmCross.Plugin.FieldBinding package to the Droid project.

CGImageRef not found when binding a static library to Xamarin.iOS

I am trying to bind some *.framework library which (among others) uses CoreGraphics.
So, the code generated by Sharpie is as follows:
// +(CGImageRef)rotateCGImage:(CGImageRef)image byRadians:(double)radians;
[Static]
[Export ("rotateCGImage:byRadians:")]
unsafe CGImageRef* RotateCGImage (CGImageRef* image, double radians);
However, when trying to build it, I receive error message like "CGImageRef could not be found".
Also, I can't find corresponding class in the list of members of CoreGraphics in Assembly Explorer.
(Same way as using CoreGraphics; doesn't help.)
It looks like this class (or struct) is just not supported by Mono: I just can't find it in regular iOS project libraries neither.
And actually, there is a number of similar "ref-like" classes which are missed: CMSampleBufferRef from Core Media, CVImageBufferRef from Core Video etc.
So, how can I handle this situation?
Please try the solution in this thread:
CGImageRef doesn't exist in Xamarin. In Obj-C, CGImageRef is just a pointer to CGImage, so I would think you could just change all of those CGImageRef to CGImage.
I think it should be something like this:
[Static]
[Export("rotateCGImage:byRadians:")]
unsafe CGImage RotateCGImage(CGImage image, double radians);
The same to other "...Ref" in your project.
From what I've found out (and one of the approaches Xamarin team uses inside of their framework), the solution is as follows:
static extern CGImagePixelFormatInfo CGImageGetPixelFormatInfo (/* __nullable CGImageRef */ IntPtr handle);
static extern IntPtr /* CFStringRef */ CGImageGetUTType (/* __nullable CGImageRef* */ IntPtr image);
So, because of C# managed architecture, there are no explicit pointers to implement, that's why they just didn't create any *Ref-like classes across Mono.
The only thing to point here is that they pass IntPtr for both cases: CGImageRef and CGImageRef*, which has sense of course. However, the trick is in passing the CGImage pointer correctly inside of calling method, because in first case it must be this:
image == null ? IntPtr.Zero : image.Handle
so, passing a pointer of the CGImage. But in second case it must be a pointer to Handle, I assume.

How does cv::Ptr<CvHaarClassifierCascade> be released?

Assuming:
CvHaarClassifierCascade* pCascade;
cv::Ptr < CvHaarClassifierCascade > ptrCascade;
Assuming the xml file has been loaded in both pCascade and ptrCascade. Now we try to release them.
In OpenCV, there is a function cvReleaseHaarClassifierCascade to release pCascade, as directly deleting pCascade will cause a crash.
So how will ptrCascade be released?
It seems cv::Ptr< T > would use delete T* directly.
Or would cvReleaseHaarClassifierCascade be called? If so, how does cv::Ptr know which cvRelease* function should be called?
Documentation of cv::Ptr<T> shows that some types from the OpenCV C API already have a DefaultDeleter specialization that calls the appropriate release function.
Also, try not to use the old C API. Use the newer CascadeClassifier for new projects instead.

Error Handling in opencv gpu

How to handle opencv gpu exceptions? Is there any specific set of error code api for opencvgpu exception handling?
I tried searching a lot but I only got 1 error code i.e. CV_GpuNotSupported.
Please help me out.
While I'm assuming that you know that CV_GpuNotSupported is NOT how OpenCV handles GPU exceptions, and in fact, it handles error when you try to call gpu methods without compiling OpenCV with -DHAVE_CUDA or -DHAVE_OPENCL, the way OpenCV (I also assume the newest OpenCV released version, 2.4.5) handles error codes, is defined in these files:
For methods that use NVIDIA CUDA:
https://github.com/Itseez/opencv/blob/2.4.5/modules/gpu/src/error.cpp
https://github.com/Itseez/opencv/blob/2.4.5/modules/gpu/src/precomp.hpp
For methods that use OpenCL:
https://github.com/Itseez/opencv/blob/2.4.5/modules/ocl/src/error.cpp
https://github.com/Itseez/opencv/blob/2.4.5/modules/ocl/src/precomp.hpp
As for the API, you can use cv::gpu::error or cv::ocl::error. Or to get the error string, getErrorString for cv::gpu and getOpenCLErrorString. And by the way for CUDA's error you have to specify whether it's an NPP, NCV, cufft, or cublas error.

How to link to NTQueryKey in Kernel Mode

For the life of me I can't figure out how to resolve the declared NTQueryKey value in my device driver. I looked for a device driver forum, but didn't find one.
Can someone point me to the right place? OSR isn't very responsive with dumb questions like how to link to NTQueryKey.
Here is my prototype:
NTSYSAPI NTSTATUS NTAPI NtQueryKey(HANDLE, KEY_INFORMATION_CLASS, PVOID, ULONG, ULONG *);
and it compiles fine, but the linker doesn't like it.
Thanks
NtXXXX functions should not be called from kernel mode. Use the ZwXXXX functions instead. In your case, you want ZwQueryKey. It has the same signature as NtQueryKey, but it performs actions on the x86 required for talking with kernel mode, and it's provided by ntoskrnl.exe rather than by ntdll.dll.
In kernel mode you link to the Zw.... equivalent functions. See Here. NT.... functions are called from user mode (for example the Win32 subsystem would call the NT... functions).

Resources