Last active
June 6, 2023 09:19
-
-
Save rkttu/359f6a42f0c720f182de2064bb7b20ac to your computer and use it in GitHub Desktop.
P/Invoke with PowerShell (and small portion of C# code)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Windows uses msvcrt.dll | |
Add-Type -Path .\test.cs | |
[Sample]::printf_win32("Hello, World %d!`r`n", 123) | |
# *nix uses libc | |
Add-Type -Path ./test.cs | |
[Sample]::printf_linux("Hello, World %d!`n", 123) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.InteropServices; | |
public static class Sample { | |
[DllImport("msvcrt.dll", CharSet = CharSet.Ansi, | |
CallingConvention = CallingConvention.Cdecl, | |
SetLastError = false, ExactSpelling = true, EntryPoint = "printf")] | |
public static extern int printf_win32(string fmt, int arg0); | |
[DllImport("libc", CharSet = CharSet.Ansi, | |
CallingConvention = CallingConvention.Cdecl, | |
SetLastError = false, ExactSpelling = true, EntryPoint = "printf")] | |
public static extern int printf_linux(string fmt, int arg0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment