MSI Afterburner .NET Class Library

Discussion in 'MSI AfterBurner Application Development Forum' started by stangowner, Feb 28, 2011.

  1. stangowner

    stangowner Guest

    Messages:
    607
    Likes Received:
    11
    GPU:
    2xMSI N550GTX-Ti Cy II OC
    Current Version: 1.1.1.0
    Download Library: MSIAfterburner.NET.dll
    Documentation: Compiled HTML Help (.chm) or View Online
    Last Updated: February 18, 2018

    _________________________________________________
    original post:

    Hi guys,

    I'm finishing up a class library to expose the new Control API in MSI Afterburner 2.1 to .NET languages. This will allow you to communicate with Afterburner from any .NET language (C++/CLI, C#, VB.net) without having to deal with the shared memory aspects of the process. You can just add a reference to this library and access the data via standard class properties and methods.

    I'll post it here shortly, I just have to do some further testing. In the meantime, take a look what's available and let me know if I missed anything. I'll post more details (like which properties are read-only vs read/write, what raises the exceptions, example code, etc) when I post the library.

    Thanks!
    Nick

    [​IMG]
     
    Last edited: Feb 18, 2018
    hen@brosh likes this.
  2. Unwinder

    Unwinder Ancient Guru Staff Member

    Messages:
    17,130
    Likes Received:
    6,694
    Good job, Nick.
     
  3. Garu

    Garu Guest

    Messages:
    4
    Likes Received:
    0
    GPU:
    nvidia 8200M G
    Very good job , i try to use this in some application ;)
     
  4. Zaph0d_B

    Zaph0d_B New Member

    Messages:
    9
    Likes Received:
    0
    look great :) where to download ? pls ! i need it :banana:
     

  5. stangowner

    stangowner Guest

    Messages:
    607
    Likes Received:
    11
    GPU:
    2xMSI N550GTX-Ti Cy II OC
    I have not posted it yet.....was just asking for feedback before posting. I'm finishing up the documentation and doing some final testing now.

    I may make 2 changes to it first though:

    1 - I wrote this using the new MemoryMappedFile in .NET 4. I think I'm going to change this to import the functions from the kernel instead so it will work with older versions of .NET. I don't like the idea of having .NET 4 and Visual Studio 2010 a requirement.

    2 - I'm also going to add classes for accessing the hardware monitoring memory that was exposed in Afterburner 1.5/2.1. Not sure if I will add this now or in the next release. If now, it will delay release a few weeks.

    Did the library seem complete from what you can tell so far? Anything in particular you are planning on using it for?
     
  6. Garu

    Garu Guest

    Messages:
    4
    Likes Received:
    0
    GPU:
    nvidia 8200M G
    i wanna use for a simple auto-overclock tool in vb.net , using this library and opengl. with integrated bechmark and stress for gpu and cpu.

    sorry for bad english :p
     
  7. stangowner

    stangowner Guest

    Messages:
    607
    Likes Received:
    11
    GPU:
    2xMSI N550GTX-Ti Cy II OC
    I have finished creating an internal memory management class, so I am no longer using the MemoryMappedFile class in .NET 4. This library was compiled against version 2.0.50727 so it only requires .NET v2 or later.

    I released this as a 0.9.0.0, because I have not yet added the hardware monitoring classes. Currently, it only contains classes for the new Control Memory access. However, I did add binary and XML serialization capabilities. Once I complete the other classes, I'll release it as version 1.

    I just posted the class library and documentation in the first post.

    The documentation includes a C# console application example that demonstrates:

    • printing the header and GPU entry information
    • saving profiles using serialization
    • reading and changing the fan speed - including capturing the exception if the fan is set to auto
    • reading and changing the core clock speed
    • undoing the changes by deserializing the previously saved profile and applying it
    Feel free to start using it and let me know if you find any issues with the library or documentation.

    Thanks,
    Nick
     
    Last edited: Mar 10, 2011
  8. Garu

    Garu Guest

    Messages:
    4
    Likes Received:
    0
    GPU:
    nvidia 8200M G
    Sorry strangowner but i have a problem with the library, i'm using vb.net with visual basic 2010.

    this is the code:
    but the error is: "Could not connect to MSI Afterburner 2.1 or later."

    i have wrong something ?
     
  9. stangowner

    stangowner Guest

    Messages:
    607
    Likes Received:
    11
    GPU:
    2xMSI N550GTX-Ti Cy II OC
    I'll try VB 2010 later tonight and let you know.
     
  10. stangowner

    stangowner Guest

    Messages:
    607
    Likes Received:
    11
    GPU:
    2xMSI N550GTX-Ti Cy II OC
    That error is stating that it can't connect to Afterburner's shared memory. You do have Afterburner running, right? I raise that exception if it isn't.

    I'm not having any issues with it. I created a new console app in Visual Basic 2010 Express. Then I added the reference to the MSIAfterburner.NET.dll library.

    Here is the complete code for the program
    Code:
    Imports MSI.Afterburner
    Module Module1
    
        Sub Main()
            Dim ControlMemory = New ControlMemory
            Dim i = ControlMemory.GpuEntries(0).CoreClockCur
            Console.WriteLine("Current clock speed for GPU 0 is: " + i.ToString)
            Console.ReadKey()
        End Sub
    
    End Module
    And here is the result:
    Code:
    Current clock speed for GPU 0 is: 650000
    Let me know how you make out. If you still have a problem, I need more info. I'm passing the original exception as the inner exception. Can you check that and see if it is: "The system cannot find the file specified" ? Or something else?

    EDIT:
    BTW, you should not use class names as variable names. Although that worked, I would change it to:
    Dim macm = New ControlMemory
    Dim i = macm.GpuEntries(0).CoreClockCur
     
    Last edited: Mar 16, 2011

  11. Garu

    Garu Guest

    Messages:
    4
    Likes Received:
    0
    GPU:
    nvidia 8200M G
    sorry for the inconvenience, but I did not know it worked only with afterburner open, I thought it was 'independent'.
    the library now works.
     
    Last edited: Mar 16, 2011
  12. stangowner

    stangowner Guest

    Messages:
    607
    Likes Received:
    11
    GPU:
    2xMSI N550GTX-Ti Cy II OC
    No, its not independent. It reads and writes to Afterburner's shared memory. Without Afterburner running, the shared memory files do not exist.

    There is no way to split these. To have something independent would require that it be part of the Afterburner's core (an API Unwinder would have to provide). He exposed this functionality using shared memory as an IPC, and this library is a .NET wrapper for it so you don't have to worry about the memory management aspects of the process.
     
  13. Zaph0d_B

    Zaph0d_B New Member

    Messages:
    9
    Likes Received:
    0
    hi,

    is it possible to read GPU temp and GPU usage ???

    /inteks


    BTW. here the code i use start MSI Afterburner , x86/x64 , init ControlMemory .....

    maybe it helps ;)

    Code:
     private static string _afterburnerInstallPath;
            public static string AfterburnerInstallPath
            {
                get
                {
                    if(string.IsNullOrEmpty(_afterburnerInstallPath))
                    {
                        try
                        {
                            RegistryKey aKey;
                            if (IntPtr.Size == 8)
                            {
                                 aKey = Registry.LocalMachine.CreateSubKey("Software").CreateSubKey("Wow6432Node").CreateSubKey("MSI").CreateSubKey("Afterburner");
                            }else
                            {
                                aKey = Registry.LocalMachine.CreateSubKey("Software").CreateSubKey("MSI").CreateSubKey("Afterburner");
                            }
    
    
                            _afterburnerInstallPath = aKey.GetValue("InstallPath").ToString();
                        }catch
                        {
                        }
                    }
                    return _afterburnerInstallPath;
                }
                set { _afterburnerInstallPath = value; }
            }
    
    
    
    public static bool SetOverclock(int coreFsb, int memoryFsb)
            {
                if (Process.GetProcessesByName("MSIAfterburner").Length == 0)
                {
                    Execute(AfterburnerInstallPath, "");
                }
                DateTime start = DateTime.Now;
                ControlMemory macm = null;
    
                do
                {
                    Thread.Sleep(150);
                    try
                    {
                        macm = new ControlMemory();
                    }
                    catch
                    {
                    }
                    if ((DateTime.Now - start).TotalSeconds > 5)
                    {
                        IO.AddLog("cant connect afterburner");
                        return false;
                    }
                } while (macm == null);
    
    
                try
                {
                    macm.Connect();
                    macm.GpuEntries[0].CoreClockCur = (uint) (coreFsb*1000);
                    macm.GpuEntries[0].MemoryClockCur = (uint) (memoryFsb*1000);
                    macm.CommitChanges();
                    macm.Disconnect();
                }
                catch
                {
                    IO.AddLog("cant apply afterburnner setting");
                }
                return true;
            }
    
     
    Last edited: Mar 19, 2011
  14. stangowner

    stangowner Guest

    Messages:
    607
    Likes Received:
    11
    GPU:
    2xMSI N550GTX-Ti Cy II OC
    Not yet. This is the first half of the library which is just for the Control Memory. This lets you programatically interact with the left side of the Afterburner interface (read and set voltages, clocks and fan).

    I'll be adding the second half of the library in the upcoming weeks. This will include the classes for reading the hardware monitoring information - the right half of the Afterburner interface (temps, speeds, FPS, usage, etc).

    I'll mention here when I post the update. I just need to finish another project first before I can get to this.

    Thanks for posting the code. Maybe I'll add some additional capabilities in the future. But for instance, the "SetOverclock" method you posted would need to be overloaded to deal with the shader clock in case it is not linked to the core, have an additional argument for gpu index for SLI/CrossFire modes (and deal with Sync setting for Master/slave scenarios), etc, etc. There are a lot of possibilities. I don't have the time ATM to code them all. So for now - you get access to all these properties for all GPUs, and just change the properties you want before telling it to commit (as you are doing).

    Let me know if you have any other question, comments or issues.

    Thanks,
    Nick
     
  15. stangowner

    stangowner Guest

    Messages:
    607
    Likes Received:
    11
    GPU:
    2xMSI N550GTX-Ti Cy II OC
    The 2nd half of the library is now complete. This update includes the new classes for hardware monitoring. No notable changes were made to the Control Memory classes since 0.9.

    The links in the first post have been updated.

    Here is the help file TOC with the additions in this release highlighted.

    [​IMG]

    Let me know if you have any questions.

    - Nick
     

  16. Unwinder

    Unwinder Ancient Guru Staff Member

    Messages:
    17,130
    Likes Received:
    6,694
    Well done, Nick. Making the thread sticky.
     
  17. stangowner

    stangowner Guest

    Messages:
    607
    Likes Received:
    11
    GPU:
    2xMSI N550GTX-Ti Cy II OC
    DLL was updated to 1.0.1 to resolve an issue where auxVoltageBoostMax was not correct when serializing ControlMemoryGpuEntry objects.
     
  18. rewt

    rewt Guest

    Messages:
    1,279
    Likes Received:
    15
    GPU:
    Yes
    Wow Nick, this is truly impressive work! Even the documentation is pretty :)

    Were you planning on implementing "RTSSSharedMemoryV2"?
     
  19. stangowner

    stangowner Guest

    Messages:
    607
    Likes Received:
    11
    GPU:
    2xMSI N550GTX-Ti Cy II OC
    Thanks. Have you used it, or just reviewed the information?

    I was not planning on adding that, but could. You want to be able to contribute to the OSD from .NET languages?

    I'll be honest though. I have my hands full with other projects at the moment. It will be a couple months before I can even look at implementing this.
     
  20. timiman

    timiman Guest

    Messages:
    42
    Likes Received:
    1
    GPU:
    2xR9-290 Asus DCU-II
    I have made an application (G15/G19 Smart Process) that was using the logging functionality of both Rivatuner/MSI Afterburner to read the values of the sensors, which was causing a lot of problems and finally the "silently" stopping of the logging (access errors etc).

    Now, I've just finished the implementation of this .dll to my application, to read the sensors' values without the usage of the logging.

    Great job and many thanks to the "maker"!!! :)

    PS1. Using it in .Net VB
    PS2. Now I wish for "Speedfan" to have a .dll like this!!!
     

Share This Page