Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Wmi / managed / System / Management / wmiutil.cs / 1305376 / wmiutil.cs
using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using WbemClient_v1;
namespace System.Management
{
[ComImport, Guid("87A5AD68-A38A-43ef-ACA9-EFE910E5D24C"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IWmiEventSource
{
[PreserveSig]
void Indicate(IntPtr pIWbemClassObject);
[PreserveSig]
void SetStatus(
int lFlags,
int hResult,
[MarshalAs(UnmanagedType.BStr)] string strParam ,
IntPtr pObjParam
);
}
#if USEIWOS
// The following is a manually defined wrapper for IWbemObjectSink
// since the size_is attribute cannot be dealt with by TlbImp.
[Guid("7c857801-7381-11cf-884d-00aa004b2e24"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IWbemObjectSink
{
[PreserveSig]
void Indicate(
long lObjectCount,
[MarshalAs(UnmanagedType.Interface, SizeParamIndex=0)] IWbemClassObject [] apObjArray
);
[PreserveSig]
void SetStatus(
long lFlags,
int hResult,
[MarshalAs(UnmanagedType.BStr)] string strParam,
[MarshalAs(UnmanagedType.Interface)] IWbemClassObject pObjParam
);
};
#endif
//Class for calling GetErrorInfo from managed code
class WbemErrorInfo
{
public static IWbemClassObjectFreeThreaded GetErrorInfo()
{
IErrorInfo errorInfo = GetErrorInfo(0);
if(null != errorInfo)
{
IntPtr pUnk = Marshal.GetIUnknownForObject(errorInfo);
IntPtr pIWbemClassObject;
Marshal.QueryInterface(pUnk, ref IWbemClassObjectFreeThreaded.IID_IWbemClassObject, out pIWbemClassObject);
Marshal.Release(pUnk);
// The IWbemClassObjectFreeThreaded instance will own reference count on pIWbemClassObject
if(pIWbemClassObject != IntPtr.Zero)
return new IWbemClassObjectFreeThreaded(pIWbemClassObject);
}
return null;
}
[ResourceExposure( ResourceScope.None),DllImport("oleaut32.dll", PreserveSig=false)]
static extern IErrorInfo GetErrorInfo(int reserved);
}
//RCW for IErrorInfo
[ComImport]
[Guid("1CF2B120-547D-101B-8E65-08002B2BD119")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IErrorInfo
{
Guid GetGUID();
[return:MarshalAs(UnmanagedType.BStr)]
string GetSource();
[return:MarshalAs(UnmanagedType.BStr)]
string GetDescription();
[return:MarshalAs(UnmanagedType.BStr)]
string GetHelpFile();
uint GetHelpContext();
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using WbemClient_v1;
namespace System.Management
{
[ComImport, Guid("87A5AD68-A38A-43ef-ACA9-EFE910E5D24C"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IWmiEventSource
{
[PreserveSig]
void Indicate(IntPtr pIWbemClassObject);
[PreserveSig]
void SetStatus(
int lFlags,
int hResult,
[MarshalAs(UnmanagedType.BStr)] string strParam ,
IntPtr pObjParam
);
}
#if USEIWOS
// The following is a manually defined wrapper for IWbemObjectSink
// since the size_is attribute cannot be dealt with by TlbImp.
[Guid("7c857801-7381-11cf-884d-00aa004b2e24"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IWbemObjectSink
{
[PreserveSig]
void Indicate(
long lObjectCount,
[MarshalAs(UnmanagedType.Interface, SizeParamIndex=0)] IWbemClassObject [] apObjArray
);
[PreserveSig]
void SetStatus(
long lFlags,
int hResult,
[MarshalAs(UnmanagedType.BStr)] string strParam,
[MarshalAs(UnmanagedType.Interface)] IWbemClassObject pObjParam
);
};
#endif
//Class for calling GetErrorInfo from managed code
class WbemErrorInfo
{
public static IWbemClassObjectFreeThreaded GetErrorInfo()
{
IErrorInfo errorInfo = GetErrorInfo(0);
if(null != errorInfo)
{
IntPtr pUnk = Marshal.GetIUnknownForObject(errorInfo);
IntPtr pIWbemClassObject;
Marshal.QueryInterface(pUnk, ref IWbemClassObjectFreeThreaded.IID_IWbemClassObject, out pIWbemClassObject);
Marshal.Release(pUnk);
// The IWbemClassObjectFreeThreaded instance will own reference count on pIWbemClassObject
if(pIWbemClassObject != IntPtr.Zero)
return new IWbemClassObjectFreeThreaded(pIWbemClassObject);
}
return null;
}
[ResourceExposure( ResourceScope.None),DllImport("oleaut32.dll", PreserveSig=false)]
static extern IErrorInfo GetErrorInfo(int reserved);
}
//RCW for IErrorInfo
[ComImport]
[Guid("1CF2B120-547D-101B-8E65-08002B2BD119")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IErrorInfo
{
Guid GetGUID();
[return:MarshalAs(UnmanagedType.BStr)]
string GetSource();
[return:MarshalAs(UnmanagedType.BStr)]
string GetDescription();
[return:MarshalAs(UnmanagedType.BStr)]
string GetHelpFile();
uint GetHelpContext();
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AlignmentXValidation.cs
- CompilerError.cs
- ArraySegment.cs
- ShapeTypeface.cs
- _DomainName.cs
- TraceHandlerErrorFormatter.cs
- DataGridViewCellValidatingEventArgs.cs
- BamlMapTable.cs
- AxisAngleRotation3D.cs
- TreeNodeMouseHoverEvent.cs
- DataGridViewRow.cs
- ViewSimplifier.cs
- HotSpot.cs
- WebEventCodes.cs
- InputElement.cs
- ConditionalAttribute.cs
- XmlObjectSerializerReadContextComplex.cs
- UInt64.cs
- CachedRequestParams.cs
- XmlSerializationReader.cs
- StaticResourceExtension.cs
- WaitHandle.cs
- HandleCollector.cs
- FontStyleConverter.cs
- PrintControllerWithStatusDialog.cs
- SystemSounds.cs
- TemplateEditingVerb.cs
- FilteredReadOnlyMetadataCollection.cs
- HatchBrush.cs
- CustomGrammar.cs
- TypeCacheManager.cs
- Model3D.cs
- ToolCreatedEventArgs.cs
- GradientSpreadMethodValidation.cs
- Point3DConverter.cs
- XPathExpr.cs
- FormsAuthenticationUserCollection.cs
- HttpWebRequest.cs
- TextEditorTyping.cs
- XmlAnyElementAttributes.cs
- ImageListStreamer.cs
- AsymmetricKeyExchangeFormatter.cs
- ChtmlTextWriter.cs
- HttpHandlersSection.cs
- ObjectListField.cs
- XmlSerializerFactory.cs
- UIElement3DAutomationPeer.cs
- UserControl.cs
- ServiceCredentialsElement.cs
- Rules.cs
- TreeView.cs
- ConsoleTraceListener.cs
- ListenerElementsCollection.cs
- DbConnectionClosed.cs
- BindToObject.cs
- DeclarativeCatalogPart.cs
- XhtmlBasicSelectionListAdapter.cs
- Compiler.cs
- XPathNodeIterator.cs
- ProfilePropertySettingsCollection.cs
- AssemblyNameEqualityComparer.cs
- SspiSecurityToken.cs
- Matrix3D.cs
- MLangCodePageEncoding.cs
- DataGridViewColumnTypeEditor.cs
- WebPageTraceListener.cs
- CounterCreationData.cs
- PrivilegeNotHeldException.cs
- StylusButtonCollection.cs
- mediaeventargs.cs
- SmtpDigestAuthenticationModule.cs
- SortQueryOperator.cs
- CodeSubDirectory.cs
- ProviderSettings.cs
- FileRecordSequenceHelper.cs
- ScrollViewerAutomationPeer.cs
- DataRelationPropertyDescriptor.cs
- XmlILTrace.cs
- StringInfo.cs
- handlecollector.cs
- XmlCodeExporter.cs
- BadImageFormatException.cs
- ConfigurationElementCollection.cs
- DataBindingExpressionBuilder.cs
- MsmqIntegrationValidationBehavior.cs
- XmlSchemaDocumentation.cs
- Switch.cs
- DataControlImageButton.cs
- CompModSwitches.cs
- UriTemplateDispatchFormatter.cs
- ReflectPropertyDescriptor.cs
- WebBrowserDocumentCompletedEventHandler.cs
- EntityDataSourceDataSelectionPanel.cs
- SingleConverter.cs
- XmlNodeReader.cs
- Latin1Encoding.cs
- keycontainerpermission.cs
- OutputScopeManager.cs
- TableColumnCollection.cs
- MarkupCompilePass1.cs