PageRenderTime 53ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Visual Studio 2008/CSPInvokeDll/NativeMethod.cs

#
C# | 116 lines | 69 code | 19 blank | 28 comment | 0 complexity | 53c2eda633490edc997c5f570071d12b MD5 | raw file
  1. /****************************** Module Header ******************************\
  2. * Module Name: NativeMethod.cs
  3. * Project: CSPInvokeDll
  4. * Copyright (c) Microsoft Corporation.
  5. *
  6. * The PInvoke signatures of the methods exported from the unmanaged DLLs.
  7. *
  8. * This source is subject to the Microsoft Public License.
  9. * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
  10. * All other rights reserved.
  11. *
  12. * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
  13. * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
  15. \***************************************************************************/
  16. #region Using directives
  17. using System;
  18. using System.Runtime.InteropServices;
  19. using System.Text;
  20. using System.Security;
  21. #endregion
  22. namespace CSPInvokeDll
  23. {
  24. // Function delegate of the 'PFN_COMPARE' callback function.
  25. // The delegate type has the UnmanagedFunctionPointerAttribute. Using
  26. // this attribute, you can specify the calling convention of the native
  27. // function pointer type. In the native API's header file, the callback
  28. // PFN_COMPARE is defined as __stdcall (CALLBACK), so here we specify
  29. // CallingConvention.StdCall.
  30. [UnmanagedFunctionPointer(CallingConvention.StdCall)]
  31. delegate int CompareCallback(int a, int b);
  32. [SuppressUnmanagedCodeSecurity]
  33. class NativeMethod
  34. {
  35. [DllImport("CppDynamicLinkLibrary.dll", CharSet = CharSet.Auto,
  36. CallingConvention = CallingConvention.Cdecl)]
  37. public static extern int GetStringLength1(string str);
  38. [DllImport("CppDynamicLinkLibrary.dll", CharSet = CharSet.Auto,
  39. CallingConvention = CallingConvention.StdCall)]
  40. public static extern int GetStringLength2(string str);
  41. [DllImport("CppDynamicLinkLibrary.dll", CharSet = CharSet.Auto)]
  42. public static extern int Max(int a, int b, CompareCallback cmpFunc);
  43. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  44. public static extern MessageBoxResult MessageBox(IntPtr hWnd,
  45. string text, String caption, MessageBoxOptions options);
  46. [DllImport("msvcrt.dll", CharSet = CharSet.Ansi,
  47. CallingConvention = CallingConvention.Cdecl)]
  48. public static extern int printf(string format, string arg1, string arg2);
  49. }
  50. /// <summary>
  51. /// Flags that define appearance and behaviour of a standard message
  52. /// box displayed by a call to the MessageBox function.
  53. /// </summary>
  54. [Flags]
  55. enum MessageBoxOptions : uint
  56. {
  57. Ok = 0x000000,
  58. OkCancel = 0x000001,
  59. AbortRetryIgnore = 0x000002,
  60. YesNoCancel = 0x000003,
  61. YesNo = 0x000004,
  62. RetryCancel = 0x000005,
  63. CancelTryContinue = 0x000006,
  64. IconHand = 0x000010,
  65. IconQuestion = 0x000020,
  66. IconExclamation = 0x000030,
  67. IconAsterisk = 0x000040,
  68. UserIcon = 0x000080,
  69. IconWarning = IconExclamation,
  70. IconError = IconHand,
  71. IconInformation = IconAsterisk,
  72. IconStop = IconHand,
  73. DefButton1 = 0x000000,
  74. DefButton2 = 0x000100,
  75. DefButton3 = 0x000200,
  76. DefButton4 = 0x000300,
  77. ApplicationModal = 0x000000,
  78. SystemModal = 0x001000,
  79. TaskModal = 0x002000,
  80. Help = 0x004000, // Help Button
  81. NoFocus = 0x008000,
  82. SetForeground = 0x010000,
  83. DefaultDesktopOnly = 0x020000,
  84. Topmost = 0x040000,
  85. Right = 0x080000,
  86. RTLReading = 0x100000,
  87. }
  88. /// <summary>
  89. /// Represents possible values returned by the MessageBox function.
  90. /// </summary>
  91. enum MessageBoxResult : uint
  92. {
  93. Ok = 1, Cancel, Abort, Retry, Ignore,
  94. Yes, No, Close, Help, TryAgain, Continue,
  95. Timeout = 32000
  96. }
  97. }