Skip to main content
GameDev.net gamedev.net
🔒 Locked

Using NVAPI in managed code (C#)

Started by Hyunkel Oct 30, 2010 at 5:40 PM 1 replies 10.5k views
Original Post
Hyunkel
Hyunkel
I want to use NVAPI to check if SLI is available, and if so, enable an SLI mode in my application.
However I was unable to find a managed version of the NVAPI, and there doesn't seem to be any other way to enable SLI.

I know it's possible to call unmanaged code from C#, but I've never worked with marshalling / pinvokes.

Could someone explain what the proper course of action would be to expose some of the nvapi functions to a managed application written in C#?
I'm assuming I'll have to compile nvapi to a dll first, load it with [DllImport()] and expose the functions I need using the extern keyword.

Is this the correct way of doing is, or do I not fully grasp the concept of calling unmanaged code?
Can someone suggest a good marshalling / pinvoke tutorial to get me started? :)

Cheers,
Hyu
Moeller
Moeller
You could compile the nvapi.lib into a dll and then import it using DllImport. If you want to avoid an additional dll, you can take a look at the implementation used in the Open Hardware Monitor: http://code.google.com/p/open-hardware-monitor/source/browse/trunk/Hardware/Nvidia/NVAPI.cs
This gets the corresponding function pointers directly from the nvapi.dll. It has also the advantage of running in x86 and x64 mode (the correct dll is chosen at runtime, something that is a bit tricky when using DllImport).

The required keys to get the function pointers directly can be found e.g. in this Pascal translation of the NVAPI http://mantis.freepascal.org/bug_view_page.php?bug_id=15771&history=1


Hyunkel
Hyunkel
Hey Moeller,

Thanks for your reply.
I've poked around those files, and I'm pretty sure I understand what I have to do.
Unfortunately it seems that the public version of the NvApi does not support to enable gpu topologies such as SLI.
It's only available in the version provided to NDA customers.

Since I'm a student I am unable to fill out their form to become a registered Nvidia developer, so there's no way for me to access this version of the NvApi.
This is quite unfortunate.

Thanks for you help though,
Hyu

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.