本文整理汇总了C#中NativeMethods类的典型用法代码示例。如果您正苦于以下问题:C# NativeMethods类的具体用法?C# NativeMethods怎么用?C# NativeMethods使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NativeMethods类属于命名空间,在下文中一共展示了NativeMethods类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Send
/// <summary>
/// Send file to recycle bin
/// </summary>
/// <param name="path">Location of directory or file to recycle</param>
/// <param name="flags">FileOperationFlags to add in addition to FOF_ALLOWUNDO</param>
public static bool Send(string path, NativeMethods.FileOperationFlags flags)
{
try
{
if (NativeMethods.IsWOW64Process())
{
NativeMethods.SHFILEOPSTRUCT_x64 fs = new NativeMethods.SHFILEOPSTRUCT_x64();
fs.wFunc = NativeMethods.FileOperationType.FO_DELETE;
// important to double-terminate the string.
fs.pFrom = path + '\0' + '\0';
fs.fFlags = NativeMethods.FileOperationFlags.FOF_ALLOWUNDO | flags;
NativeMethods.SHFileOperation_x64(ref fs);
}
else
{
NativeMethods.SHFILEOPSTRUCT_x86 fs = new NativeMethods.SHFILEOPSTRUCT_x86();
fs.wFunc = NativeMethods.FileOperationType.FO_DELETE;
// important to double-terminate the string.
fs.pFrom = path + '\0' + '\0';
fs.fFlags = NativeMethods.FileOperationFlags.FOF_ALLOWUNDO | flags;
NativeMethods.SHFileOperation_x86(ref fs);
}
return true;
}
catch
{
return false;
}
}
示例2: HookCallback
public static int HookCallback(int code, int wParam, ref NativeMethods.keyboardHookStruct lParam)
{
//Debug.WriteLine(code + " " + wParam + " " + lParam.vkCode + " " + lParam.scanCode + " " + lParam.flags);
if (code >= 0 && wParam == 256) // KeyDown
{
if ((!KeysDown.ContainsKey(lParam.vkCode) ||
KeysDown[lParam.vkCode] == false) &&
ShouldCancelKeyDown(lParam.vkCode))
{
return 0;
}
KeysDown[lParam.vkCode] = true;
}
if (code >= 0 && wParam == 257) // KeyUp
{
KeysDown[lParam.vkCode] = false;
if (ShouldCancelKeyUp(lParam.vkCode))
return 0;
}
return NativeMethods.CallNextHookEx(NextHookPointer, code, wParam, ref lParam);
}
示例3: BackupStreamInfo
/// <summary>
/// Initializes a new instance of the <see cref="BackupStreamInfo"/> class.
/// </summary>
/// <param name="streamID">The stream ID.</param>
/// <param name="name">The name.</param>
internal BackupStreamInfo(NativeMethods.WIN32_STREAM_ID streamID, string name)
{
m_size = (long)streamID.StreamSize;
m_name = name;
m_attributes = (StreamAttributes)streamID.StreamAttributes;
m_streamType = (BackupStreamType)streamID.StreamType;
}
示例4: PluggableProtocolResponse
internal PluggableProtocolResponse(
PluggableProtocolHandler handler,
NativeMethods.IInternetProtocolSink sink )
{
this.handler=handler;
this.m_Sink=sink;
}
示例5: ThrowWhenFailed
private static void ThrowWhenFailed(NativeMethods.ExecutionStates previousState)
{
if (previousState == 0)
{
throw new Exception("Failed to suppress/restore system power management.");
}
}
示例6: Compile
public void Compile()
{
if (_Command.Connection == null || _Command.Connection.State == ConnectionState.Closed || _Command.Connection.State == ConnectionState.Broken)
{
throw new InvalidOperationException("Connection is currently executing an operation.");
}
if (_NativeMethods == null) _NativeMethods = _Command.Connection.NativeMethods;
if (!_FirstStep)
{
Reset();
}
else
{
if (_CommandText.Length == 0) throw new InvalidOperationException("The command text cannot be empty.");
IntPtr pTail;
IntPtr pVM;
_NativeMethods.prepare(_CommandText, out pVM, out pTail);
if (_NativeMethods.ErrorCode() != SQLiteCode.Ok)
{
throw new SQLiteException(string.Format("Error while prepare statement {0}.\r\n {1}", _CommandText, _NativeMethods.ErrorMessage()));
}
_StatementHandle = pVM;
}
BindParameters();
}
示例7: GetAttributes
/// <summary>
/// Get HID attributes.
/// </summary>
/// <param name="hidHandle"> HID handle retrieved with CreateFile </param>
/// <param name="deviceAttributes"> HID attributes structure </param>
/// <returns> true on success </returns>
internal Boolean GetAttributes(SafeFileHandle hidHandle, ref NativeMethods.HIDD_ATTRIBUTES deviceAttributes)
{
Boolean success;
try
{
// ***
// API function:
// HidD_GetAttributes
// Purpose:
// Retrieves a HIDD_ATTRIBUTES structure containing the Vendor ID,
// Product ID, and Product Version Number for a device.
// Accepts:
// A handle returned by CreateFile.
// A pointer to receive a HIDD_ATTRIBUTES structure.
// Returns:
// True on success, False on failure.
// ***
success = NativeMethods.HidD_GetAttributes(hidHandle, ref deviceAttributes);
}
catch (Exception ex)
{
DisplayException(ModuleName, ex);
throw;
}
return success;
}
示例8: ControlCallback
internal static unsafe uint ControlCallback(NativeMethods.WMIDPREQUESTCODE RequestCode, IntPtr Context, uint* InOutBufferSize, IntPtr Buffer)
{
uint Status;
switch (RequestCode)
{
case NativeMethods.WMIDPREQUESTCODE.WMI_ENABLE_EVENTS:
hTraceLog = NativeMethods.GetTraceLoggerHandle(Buffer);
Status = NativeMethods.ERROR_SUCCESS;
break;
case NativeMethods.WMIDPREQUESTCODE.WMI_DISABLE_EVENTS:
hTraceLog = 0;
Status = NativeMethods.ERROR_SUCCESS;
break;
default:
Status = NativeMethods.ERROR_INVALID_PARAMETER;
break;
}
*InOutBufferSize = 0;
return Status;
}
示例9: GetBuilderGuidString
private bool GetBuilderGuidString(NativeMethods.IProvidePropertyBuilder target, int dispid, ref string strGuidBldr, int[] bldrType)
{
bool builderAvailable = false;
string[] pbstrGuidBldr = new string[1];
if (NativeMethods.Failed(target.MapPropertyToBuilder(dispid, bldrType, pbstrGuidBldr, ref builderAvailable)))
{
builderAvailable = false;
}
if (builderAvailable && ((bldrType[0] & 2) == 0))
{
builderAvailable = false;
}
if (!builderAvailable)
{
return false;
}
if (pbstrGuidBldr[0] == null)
{
strGuidBldr = Guid.Empty.ToString();
}
else
{
strGuidBldr = pbstrGuidBldr[0];
}
return true;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:26,代码来源:Com2IProvidePropertyBuilderHandler.cs
示例10: CreateSearchAlgo
public static AsciiStringSearchAlgorithm CreateSearchAlgo(string pattern, NativeMethods.SearchOptions searchOptions)
{
if (pattern.Length <= 64)
return new AsciiStringSearchBndm64(pattern, searchOptions);
else
return new AsciiStringSearchBoyerMoore(pattern, searchOptions);
}
示例11: DrawText
public static void DrawText(this VisualStyleRenderer rnd, IDeviceContext dc, ref Rectangle bounds, string text, System.Windows.Forms.TextFormatFlags flags, NativeMethods.DrawThemeTextOptions options)
{
NativeMethods.RECT rc = new NativeMethods.RECT(bounds);
using (SafeGDIHandle hdc = new SafeGDIHandle(dc))
NativeMethods.DrawThemeTextEx(rnd.Handle, hdc, rnd.Part, rnd.State, text, text.Length, (int)flags, ref rc, ref options);
bounds = rc;
}
示例12: CategoryEntry
internal CategoryEntry(NativeMethods.PERF_OBJECT_TYPE perfObject)
{
this.NameIndex = perfObject.ObjectNameTitleIndex;
this.HelpIndex = perfObject.ObjectHelpTitleIndex;
this.CounterIndexes = new int[perfObject.NumCounters];
this.HelpIndexes = new int[perfObject.NumCounters];
}
示例13: IconHandleInfo
internal IconHandleInfo(NativeMethods.ICONINFO info)
{
this.IsIcon = info.fIcon;
this.Hotspot = new Point(info.xHotspot, info.yHotspot);
this.MaskBitmap = new BitmapHandle(info.hbmMask);
this.ColorBitmap = new BitmapHandle(info.hbmColor);
}
示例14: WinPosition
internal WinPosition(NativeMethods.WINDOWINFO wti)
{
this.Left = wti.rcClient.left;
this.Top = wti.rcClient.top;
this.Right = wti.rcClient.right;
this.Bottom = wti.rcClient.bottom;
}
示例15: Message
/// <summary>Text updating message.</summary>
/// <remarks>The string will be marshaled: the Message must be correctly disposed after use.</remarks>
public Message(NativeMethods.TaskDialogMessages msg, DialogElements element, string s) {
MessageType = msg;
wParam = (int)element;
_unsafeHandle = Marshal.StringToHGlobalUni(s);
lParam = (int)_unsafeHandle;
}