Can someone please point out why I am getting an 87 error? I am sure
it is obvious, but I am new to C# and seem to be having a lot of
stress understanding managed versus unmanaged code when API calls are
needed!
//
using System;
using System.Runtime. InteropServices ;
//
namespace DeviceClassLibr ary
{
/// <summary>
/// Device Class Library.
/// </summary>
//
//typedef struct _SP_DEVINFO_DAT A
// {
// DWORD cbSize;
// GUID ClassGuid;
// DWORD DevInst;
// ULONG_PTR Reserved;
// } SP_DEVINFO_DATA , *PSP_DEVINFO_DA TA;
[StructLayout(La youtKind.Sequen tial)]
public struct _SP_DEVINFO_DAT A
{
//
public Int32 theSize;
[MarshalAsAttrib ute(UnmanagedTy pe.ByValArray, SizeConst=16)]
public byte[] theClass;
public Int32 theInstance;
public Int64 theReserved;
}
//typedef struct _SP_DEVICE_INTE RFACE_DATA
// {
// DWORD cbSize;
// GUID InterfaceClassG uid;
// DWORD Flags;
// ULONG_PTR Reserved;
// } SP_DEVICE_INTER FACE_DATA, *PSP_DEVICE_INT ERFACE_DATA;
[StructLayout(La youtKind.Sequen tial)]
public struct _SP_DEVICE_INTE RFACE_DATA
{
//
public Int32 theSize;
[MarshalAsAttrib ute(UnmanagedTy pe.ByValArray, SizeConst=16)]
public byte[] theClass;
public Int32 theFlags;
public Int64 theReserved;
}
//typedef struct _SP_DEVICE_INTE RFACE_DETAIL_DA TA
// {
// DWORD cbSize;
// TCHAR DevicePath[ANYSIZE_ARRAY];
// } SP_DEVICE_INTER FACE_DETAIL_DAT A,
*PSP_DEVICE_INT ERFACE_DETAIL_D ATA;
[StructLayout(La youtKind.Sequen tial)]
public struct _SP_DEVICE_INTE RFACE_DETAIL_DA TA
{
//
public int theSize;
public byte[] thePath;
}
//
public enum DeviceError
{
//
Success = 0
}
public class DeviceClass
{
//
[DllImport("SETU PAPI", SetLastError = true)]
private static extern IntPtr SetupDiGetClass Devs (
byte[] theClass,
IntPtr theEnumerator,
IntPtr theOwner,
int theFlags);
[DllImport("SETU PAPI", SetLastError = true)]
private static extern bool SetupDiDestroyD eviceInfoList(
IntPtr theHandle
);
[DllImport("SETU PAPI", SetLastError = true)]
private static extern bool SetupDiEnumDevi ceInfo(
IntPtr theHandle,
int theIndex,
_SP_DEVINFO_DAT A theData);
// Constructor...
public DeviceClass()
{
//
}
// Destructor...
~DeviceClass()
{
//
}
public int Enumerate(strin g theClass, int theCode, ref IntPtr
theHandle)
{
int theResult = (int)DeviceErro r.Success;
Guid theGuid;
//
theGuid = new Guid(theClass);
theHandle = SetupDiGetClass Devs
(theGuid.ToByte Array(), IntPtr.Zero, IntPtr.Zero, theCode);
//
return (theResult);
}
public int UnEnumerate(ref IntPtr theHandle)
{
int theResult = (int)DeviceErro r.Success;
//
theHandle = IntPtr.Zero;
return (theResult);
}
public int RegistryPropert y(IntPtr theHandle, int theIndex)
{
int theResult = (int)DeviceErro r.Success;
_SP_DEVINFO_DAT A theData = new _SP_DEVINFO_DAT A();
//Buffer theBuffer;
//int theSize;
bool thePropertyOrNo t;
//
theData.theSize = Marshal.SizeOf( typeof(_SP_DEVI NFO_DATA));
thePropertyOrNo t = SetupDiEnumDevi ceInfo(theHandl e, theIndex,
theData);
theResult = Marshal.GetLast Win32Error();
return (theResult);
}
}
}
it is obvious, but I am new to C# and seem to be having a lot of
stress understanding managed versus unmanaged code when API calls are
needed!
//
using System;
using System.Runtime. InteropServices ;
//
namespace DeviceClassLibr ary
{
/// <summary>
/// Device Class Library.
/// </summary>
//
//typedef struct _SP_DEVINFO_DAT A
// {
// DWORD cbSize;
// GUID ClassGuid;
// DWORD DevInst;
// ULONG_PTR Reserved;
// } SP_DEVINFO_DATA , *PSP_DEVINFO_DA TA;
[StructLayout(La youtKind.Sequen tial)]
public struct _SP_DEVINFO_DAT A
{
//
public Int32 theSize;
[MarshalAsAttrib ute(UnmanagedTy pe.ByValArray, SizeConst=16)]
public byte[] theClass;
public Int32 theInstance;
public Int64 theReserved;
}
//typedef struct _SP_DEVICE_INTE RFACE_DATA
// {
// DWORD cbSize;
// GUID InterfaceClassG uid;
// DWORD Flags;
// ULONG_PTR Reserved;
// } SP_DEVICE_INTER FACE_DATA, *PSP_DEVICE_INT ERFACE_DATA;
[StructLayout(La youtKind.Sequen tial)]
public struct _SP_DEVICE_INTE RFACE_DATA
{
//
public Int32 theSize;
[MarshalAsAttrib ute(UnmanagedTy pe.ByValArray, SizeConst=16)]
public byte[] theClass;
public Int32 theFlags;
public Int64 theReserved;
}
//typedef struct _SP_DEVICE_INTE RFACE_DETAIL_DA TA
// {
// DWORD cbSize;
// TCHAR DevicePath[ANYSIZE_ARRAY];
// } SP_DEVICE_INTER FACE_DETAIL_DAT A,
*PSP_DEVICE_INT ERFACE_DETAIL_D ATA;
[StructLayout(La youtKind.Sequen tial)]
public struct _SP_DEVICE_INTE RFACE_DETAIL_DA TA
{
//
public int theSize;
public byte[] thePath;
}
//
public enum DeviceError
{
//
Success = 0
}
public class DeviceClass
{
//
[DllImport("SETU PAPI", SetLastError = true)]
private static extern IntPtr SetupDiGetClass Devs (
byte[] theClass,
IntPtr theEnumerator,
IntPtr theOwner,
int theFlags);
[DllImport("SETU PAPI", SetLastError = true)]
private static extern bool SetupDiDestroyD eviceInfoList(
IntPtr theHandle
);
[DllImport("SETU PAPI", SetLastError = true)]
private static extern bool SetupDiEnumDevi ceInfo(
IntPtr theHandle,
int theIndex,
_SP_DEVINFO_DAT A theData);
// Constructor...
public DeviceClass()
{
//
}
// Destructor...
~DeviceClass()
{
//
}
public int Enumerate(strin g theClass, int theCode, ref IntPtr
theHandle)
{
int theResult = (int)DeviceErro r.Success;
Guid theGuid;
//
theGuid = new Guid(theClass);
theHandle = SetupDiGetClass Devs
(theGuid.ToByte Array(), IntPtr.Zero, IntPtr.Zero, theCode);
//
return (theResult);
}
public int UnEnumerate(ref IntPtr theHandle)
{
int theResult = (int)DeviceErro r.Success;
//
theHandle = IntPtr.Zero;
return (theResult);
}
public int RegistryPropert y(IntPtr theHandle, int theIndex)
{
int theResult = (int)DeviceErro r.Success;
_SP_DEVINFO_DAT A theData = new _SP_DEVINFO_DAT A();
//Buffer theBuffer;
//int theSize;
bool thePropertyOrNo t;
//
theData.theSize = Marshal.SizeOf( typeof(_SP_DEVI NFO_DATA));
thePropertyOrNo t = SetupDiEnumDevi ceInfo(theHandl e, theIndex,
theData);
theResult = Marshal.GetLast Win32Error();
return (theResult);
}
}
}
Comment