[DllImport("mylib.dll")] public static extern int MyFunction(int arg1, int arg2); int result = MyFunction(2, 3);
[DllImport("user32.dll")] public static extern bool SetWindowText(IntPtr hWnd, String lpString); IntPtr hWnd = // get the handle to a window SetWindowText(hWnd, "Hello world");
Type type = Type.GetTypeFromProgID("MyCOMObject"); dynamic comObject = Activator.CreateInstance(type); comObject.MyMethod("Hello world");In this example, we are creating an instance of a COM object named "MyCOMObject" and calling a method named "MyMethod" on it. The method takes a string argument. The package libraries used in these examples are not specified as they depend on the specific native code or COM object being called.