Skip to content

Instantly share code, notes, and snippets.

@EgorBo
Created March 25, 2021 08:51
Show Gist options
  • Select an option

  • Save EgorBo/b81454826ff1580441abad90d66bcac3 to your computer and use it in GitHub Desktop.

Select an option

Save EgorBo/b81454826ff1580441abad90d66bcac3 to your computer and use it in GitHub Desktop.
call-beep.cs
using System;
using System.Runtime.InteropServices;
class Prog
{
static unsafe void Main()
{
var func = (delegate* unmanaged<int, int, int>)GetProcAddress(GetModuleHandle("kernel32.dll"), "Beep");
int result = func(500, 500);
}
[DllImport("kernel32.dll"), SuppressGCTransition]
static extern IntPtr GetProcAddress(IntPtr hModule, string entryPoint);
[DllImport("kernel32.dll"), SuppressGCTransition]
static extern IntPtr GetModuleHandle(string moduleName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment