4

Question:
Hello I am trying to get GPU temps for a nividia gtx 980 using Delphi, I have seen the C++ question and his solution was not to use nvcpl.dll, I dont think this is the correct solution as nivida have a full document stating how to deal with there API(See Below).

Details:
I am using Delphi XE7 and run windows 8.1 64bit, I also compiled code as 64bit delphi application(to able to use loadlibrary), which brings me to think maybe Delphi types have changed when compiling x64 applications. I have also tried using stdcall without success and diffrent types and point types.UINT Integer Dword Cardinal Int32 PDWORD DWORD_PTR without success, hopefully someone could explain why.

Issue:
The call to "NvCplGetThermalSettings" is always returning false.

Refference:
Nvidia nvcpl.dll API manual <--- Page 64
C++ Stackoverflow Question Similar

Thanks for looking....

{
NvCplGetThermalSettings()
Function
Prototype
BOOL CDECL NvCplGetThermalSettings
 (IN UINT nWindowsMonitorNumber,
 OUT DWORD* pdwCoreTemp,
 OUT DWORD* pdwAmbientTemp,
 OUT DWORD* pdwUpperLimit);
Parameters In UINT nWindowsMonitorNumber -- The display number shown on
 the Windows Display Properties->Settings page.
 A value of 0 indicates the current primary Windows display device.
DWORD* must be a valid pointer --
 pdwCoreTemp -- GPU temperature in degrees Celsius.
 pdwAmbientTemp -- Ambient temperature in degrees Celsius.
 pdwUpperLimit -- Upper limit of the GPU temperature specification.
Return Values True on success.
False on failure.
}

function NvidiaGpuTemp: Integer;
type
  NvCplGetThermalSettings = function(
    nWindowsMonitorNumber: UINT; 
    pdwCoreTemp, 
    pdwAmbientTemp, pdwUpperlimit: PDWORD): BOOL; cdecl;
var
  hNvcpl: Hwnd;
  GetThermalSettings: NvCplGetThermalSettings;
  dwCoreTemp, dwAmbientTemp, dwUpperlimit: DWORD;
begin
  Result := 0;


  hNvcpl := LoadLibrary('nvcpl.dll');
  if hNvcpl <> 0 then
    try
      GetThermalSettings := GetProcAddress(hNvcpl,'NvCplGetThermalSettings');
      if Assigned(GetThermalSettings) then
        If GetThermalSettings(0, Addr(dwCoreTemp), Addr(dwAmbientTemp), 
          Addr(dwUpperlimit)) then
        begin
         ShowMessage('Called Successfully');
         Result:= Integer(dwCoreTemp);
        end;
    finally
      FreeLibrary(hNvcpl);
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
   ShowMessage(InttoStr(NvidiaGpuTemp));
end;
Community
  • 1
  • 1
  • OT: `LoadLibrary` returns `HMODULE` type value, not `HWND`. – TLama Mar 25 '15 at 10:11
  • Ptr(dwXXX) should be Addr(dwXXX) or @dwXXX. – LU RD Mar 25 '15 at 10:21
  • Yes, I was also wondering what `Ptr` is...... – David Heffernan Mar 25 '15 at 10:21
  • 1
    Or declare the parameters like `out pdwCoreTemp: DWORD`... – TLama Mar 25 '15 at 10:24
  • It's also pointless initialising dwCoreTemp, dwAmbientTemp and dwUpperlimit since the function you are calling is tasked with doing that. – David Heffernan Mar 25 '15 at 10:28
  • I originally had "Addr" but I was trying anything I could to get it to work and didn't change it back, it still doesn't work. also removed initialising as suggest by david. Also tried parameter declare out pdwCoreTemp: DWORD as suggested ... no luck – TheDrunkenAlcoholic Mar 25 '15 at 10:32
  • Did you read the answer in the dupe? It seems like you are just trying stuff at random. Why would not initialising the variables change the behaviour of the function. I told you that it was pointless, not that it was the cause of your problem. You do need to slow down and read carefully the answer at the dupe. Did you compile that code and run it yet? – David Heffernan Mar 25 '15 at 10:34
  • He answered him self with using nvapi64.dll, I am wanting to use nvcpl.dll as it doesn't require all those structures and also I am curious why this wouldn't work as stated in the API manual. – TheDrunkenAlcoholic Mar 25 '15 at 10:39
  • That doesn't change the fact that this question is a dupe. It's an identical question. I'm surprised that you haven't run that code yet to see that it works. If you really want to do it with nvcpl, I suggest that you read the documentation more closely, and look at the samples that are given there, and find some other sample code. It will be in C++. Perhaps you need to perform some initialization of the library. – David Heffernan Mar 25 '15 at 10:41
  • Or perhaps it returns false because your hardware/driver do not support the functionality – David Heffernan Mar 25 '15 at 10:47
  • 1
    @DavidHeffernan The question is maybe dupe, but first, it is for another language, and second answer in that question does not fully address question asked. "If those answers do not fully address your question, please ask a new question." - so person asks new question and only to be closed as dupe. – Dalija Prasnikar Mar 25 '15 at 10:50
  • @DavidHeffernan another question for you, lets say that I do have answer for this question. Should I go and post answer written in Delphi in that another question? – Dalija Prasnikar Mar 25 '15 at 10:52
  • I didn't count it as a dupe as the solution was to use another dll, and it was for C++. Also I did read the documentation as you can see I have quoted the function in the first post directly from the manual. I am pretty sure it supports thats function, but yes I will download a C++ example and compile it that uses this function and make sure it works(thanks for the tip). Also to note I am not a professional coder, I am a hobbyist and really only play with the pascal language for self learning and experimenting. – TheDrunkenAlcoholic Mar 25 '15 at 10:52
  • I can reproduce the same. The `NvGetLastError` function returns me `NV_NOTIMPLEMENTED` which sounds like this function is not implemented in the library. My device is not capable of this feature, but I think I would get `NV_NOTSUPPORTED` rather than `NV_NOTIMPLEMENTED`. (using the most recent drivers) – TLama Mar 25 '15 at 10:55
  • @TheDrunkenAlcoholic It's a duplicate *question*. The answer isn't really relevant. – David Heffernan Mar 25 '15 at 10:59
  • @DalijaPrasnikar The language is not very important here. The point is what functions are called, and how to call them. Any decent winapi dev will be able to understand that in any language. If this was a question that was all about a language specific issue then it would be different. But it's all about interop with a third party library, and that's a language neutral subject. – David Heffernan Mar 25 '15 at 11:00
  • @TLama the function in question only returns true or false, I am assuming you are calling functions from the nvapi64.dll which I have not attempted as I was wanting to know why the "NvCplGetThermalSettings" function from the nvcpl.dll doesn't work with the parameters I have given(as stated in the manual). nvapi64 is the solution given in the C++ topic but it still doesn't answer the original question which was dealing with the nvcpl.dll functions. – TheDrunkenAlcoholic Mar 25 '15 at 11:08
  • Okay, I am leaning towards maybe the function is depreciated even tho you can get its proc address from the dll, I guess I will just have to accept that it is depreciated without the facts. I will try nvapi64.dll thanks to all or responding and hopefully someone who reads this can confirm it has been depreciated. – TheDrunkenAlcoholic Mar 25 '15 at 11:27
  • Nope. But sorry, I've misread the docs for the `NvGetLastError` function, it's used for functions that return `NVRESULT` type which is not this case. – TLama Mar 25 '15 at 11:56
  • Voting to reopen. The question links to the presumed duplicate, opting for another solution. – LU RD Mar 25 '15 at 12:34
  • @LURD That's not what it means to be a duplicate question. – David Heffernan Mar 25 '15 at 13:02
  • @DavidHeffernan, the accepted answer in the link does not address the question, hence my doubt. – LU RD Mar 25 '15 at 14:06
  • @LURD I don't see how that is relevant. The two questions appear to be identical to me. – David Heffernan Mar 25 '15 at 14:25
  • @TheDrunkenAlcoholic : Tested your Code, works well on ,WinXP 32, AMD 64, Nvidia GeForce 7600 GT, Driver 307.83, nvcpl.dll : Vers.: 6.14.13.0783 – moskito-x Mar 25 '15 at 20:41
  • @DavidHeffernan, from help, duplicate message: `This question has been asked before and already has an answer. If those answers do not fully address your question, please edit this question to explain how it is different or ask a new question.` The linked answer does not address the question and reasons for asking are well explained. – LU RD Mar 25 '15 at 22:16
  • @LURD I disagree that the answer at the dupe doesn't answer the question – David Heffernan Mar 25 '15 at 22:20
  • @DavidHeffernan, yes that part may be subjective. I see that answer as a good workaround, but there is no explanation why the api is returning false, which is really the question here. – LU RD Mar 25 '15 at 22:26
  • @LURD So let's add the answer there. Unlinking these questions makes things worse. – David Heffernan Mar 25 '15 at 22:33
  • @David, I'm fine either way. There is possibility that the error is due to a 64 bit platform. A trace with dependencywalker should pinpoint where the error is. – LU RD Mar 25 '15 at 22:53
  • @LURD That's not it. The module loads. The function executes. – David Heffernan Mar 25 '15 at 22:55

0 Answers0