C# - P/Invoke

List of exported functions in Windows system dll files: https://strontic.github.io/xcyclopedia/index-dll

Data Type conversion from C++ to .NET: https://www.codeproject.com/Articles/9714/Win32-API-C-to-NET

  • Boilerplate Code

using System;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Text;

namespace WinAPI
{
    class Program
    {
        # P/Invoke


        //[HandleProcessCorruptedStateExceptions] // Helps catch the System.AccessViolationException exception
        static void Main(string[] args)
        {
            try
            {
                # Code
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
    }
}
  • GetUserNameA

  • GetComputerNameA

Last updated

Was this helpful?