Skip to content

Is it possible to use P/Invoke in native blocks? #109

Closed Answered by pfusik
ghost asked this question in Q&A
Discussion options

You must be logged in to vote
#if CS
native {
    using System;
    using System.Runtime.InteropServices;

    class PInvokeHelper
    {
        // Import user32.dll (containing the function we need) and define
        // the method corresponding to the native function.
        [DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
        public static extern int MessageBox(IntPtr hWnd, string lpText, string lpCaption, uint uType);
    }
}
#endif

public class Program
{
    public static void Main()
    {
#if CS
        native {
            PInvokeHelper.MessageBox(IntPtr.Zero, "Command-line message box", "Attention!", 0);
        }
#endif
    }
}
C:\0\ci>fut -D CS -o pinvoke.cs pinvoke.fu

C:\0\ci…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant