473,769 Members | 6,538 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieving dbcc_name string from a DEV_BROADCAST_D EVICEINTERFACE structure

I'm trying to get the Name of the USB device pluged in from the
RegisterDeviceN otification that I've used P/Invoke to marshal. I have
seen a similar posting on the VisualBasic newgroups but I do not know
how to translate the ReDim that occurs there into C#. Or wither this
will actually give me what I'm looking for.
The code I'm posting seems to work although I don't know how to
set the length of the name correctly in the Marshal.PtrToSt ructure()
call.

Thanks all for any help.
Hopefully this VB->VC translation can help someone out there as well

Jeff
Visual Basic Code:
=============== ===
Imports System.Runtime. InteropServices
Imports System.Windows. Forms
Imports System.Text
Public Class Form1
Inherits System.Windows. Forms.Form

Public Class Win32
Public Const WM_DEVICECHANGE = &H219
Public Const DBT_DEVICEARRIV AL = &H8000
Public Const DBT_DEVICEREMOV ECOMPLETE = &H8004
Public Const DEVICE_NOTIFY_W INDOW_HANDLE = 0
Public Const DEVICE_NOTIFY_S ERVICE_HANDLE = 1
Public Const DBT_DEVTYP_DEVI CEINTERFACE = 5
Public Shared GUID_IO_MEDIA_A RRIVAL As Guid = New
Guid("A5DCBF10-6530-11D2-901F-00C04FB951ED")

<StructLayout(L ayoutKind.Seque ntial)> _
Public Class DEV_BROADCAST_D EVICEINTERFACE
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
Public dbcc_classguid As Guid
Public dbcc_name As Short
End Class
<StructLayout(L ayoutKind.Seque ntial,
CharSet:=CharSe t.Unicode)> _
Public Class DEV_BROADCAST_D EVICEINTERFACE1
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
<MarshalAs(Unma nagedType.ByVal Array,
ArraySubType:=U nmanagedType.U1 , SizeConst:=16)> _
Public dbcc_classguid( ) As Byte
<MarshalAs(Unma nagedType.ByVal Array, SizeConst:=128) > _
Public dbcc_name() As Char
End Class
<StructLayout(L ayoutKind.Seque ntial)> _
Public Class DEV_BROADCAST_H DR
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
End Class

<DllImport("use r32.DLL", SetLastError:=T rue)> _
Public Shared Function _
RegisterDeviceN otification(ByV al IntPtr As IntPtr, ByVal
NotificationFil ter As IntPtr, ByVal Flags As Int32) As IntPtr
End Function

<DllImport("ker nel32.DLL")> _
Public Shared Function _
GetLastError() As Integer
End Function
End Class

Public Sub New()
MyBase.New()
InitializeCompo nent()
RegisterHidNoti fication()
End Sub

Public Sub RegisterHidNoti fication()
Dim dbi As Win32.DEV_BROAD CAST_DEVICEINTE RFACE = New
Win32.DEV_BROAD CAST_DEVICEINTE RFACE
Dim size As Integer
size = Marshal.SizeOf( dbi)
Dim gd As Guid
' MsgBox(Marshal. SizeOf(gd))
' MsgBox(Marshal. SizeOf(New
Win32.DEV_BROAD CAST_DEVICEINTE RFACE1))
dbi.dbcc_size = size
dbi.dbcc_device type = Win32.DBT_DEVTY P_DEVICEINTERFA CE
dbi.dbcc_reserv ed = 0
dbi.dbcc_classg uid = Win32.GUID_IO_M EDIA_ARRIVAL
Dim Buffer As IntPtr
Buffer = Marshal.AllocHG lobal(size)
Marshal.Structu reToPtr(dbi, Buffer, True)
Dim r As IntPtr
r = Win32.RegisterD eviceNotificati on(Handle, Buffer,
Win32.DEVICE_NO TIFY_WINDOW_HAN DLE)
Marshal.PtrToSt ructure(Buffer, dbi)
If r.ToInt32 = IntPtr.Zero.ToI nt32 Then
MessageBox.Show (Win32.GetLastE rror().ToString ())
End If
End Sub

Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = Win32.WM_DEVICE CHANGE Then
OnDeviceChange( m)
End If
MyBase.WndProc( m)
End Sub

Private Sub OnDeviceChange( ByVal msg As Message)
Dim wParam As Integer
wParam = msg.WParam.ToIn t32()
If wParam = Win32.DBT_DEVIC EARRIVAL Then
Dim o As New Win32.DEV_BROAD CAST_HDR
Dim b As New Win32.DEV_BROAD CAST_DEVICEINTE RFACE1
Dim gd As Guid
Marshal.PtrToSt ructure(msg.LPa ram, o)
If (o.dbcc_devicet ype = Win32.DBT_DEVTY P_DEVICEINTERFA CE)
Then
Dim strsize As Integer = (o.dbcc_size - 28) / 2
ReDim b.dbcc_name(str size)
Marshal.PtrToSt ructure(msg.LPa ram, b)
MsgBox(New Guid(b.dbcc_cla ssguid).ToStrin g)
Dim str As New String(b.dbcc_n ame, 0, strsize)
MsgBox(str)
End If
MessageBox.Show ("Arrival")
ElseIf wParam = Win32.DBT_DEVIC EREMOVECOMPLETE Then
MessageBox.Show ("Remove")
End If
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
components = New System.Componen tModel.Containe r
Me.Text = "Form1"
Dim t As New Guid("d07433c0-a98e-11d2-917a-00a0c9068ff3")
End Sub
End Class
Visual CSharp Equivilent
=============== =========
using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Runtime. InteropServices ;

namespace WindowsApplicat ion1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows. Forms.Form
{
private System.Componen tModel.Containe r components = null;

public Form1()
{
InitializeCompo nent();
RegisterDeviceN otification();
}

private void InitializeCompo nent()
{
this.components = new System.Componen tModel.Containe r();
this.Size = new System.Drawing. Size(300,300);
this.Text = "Form1";
}

[STAThread] static void Main()
{
Application.Run (new Form1());
}

void RegisterDeviceN otification()
{
Win32.DEV_BROAD CAST_DEVICEINTE RFACE dbi = new
Win32.DEV_BROAD CAST_DEVICEINTE RFACE();
int size = Marshal.SizeOf( dbi);
dbi.dbcc_size = size;
dbi.dbcc_device type = Win32.DBT_DEVTY P_DEVICEINTERFA CE;
dbi.dbcc_reserv ed = 0;
dbi.dbcc_classg uid = Win32.GUID_DEVI NTERFACE_USB_DE VICE;
dbi.dbcc_name = 0;
IntPtr buffer = Marshal.AllocHG lobal(size);
Marshal.Structu reToPtr(dbi, buffer, true);
IntPtr r = Win32.RegisterD eviceNotificati on(Handle, buffer,
Win32.DEVICE_NO TIFY_WINDOW_HAN DLE);
if(r == IntPtr.Zero)
MessageBox.Show (Win32.GetLastE rror().ToString ());
}
protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case Win32.WM_DEVICE CHANGE: OnDeviceChange( ref m); break;
}
base.WndProc (ref m);
}
void OnDeviceChange( ref Message msg)
{
int wParam = (int)msg.WParam ;
if((wParam == Win32.DBT_DEVIC EARRIVAL) || (wParam ==
Win32.DBT_DEVIC EREMOVECOMPLETE ))
{
// Read the dhdr.dbcc_devic etype - The Following code could also
be used
////////////////////////////////////////////////////////////////////////
//Win32.DEV_BROAD CAST_HDR dhdr;
//dhdr = (Win32.DEV_BROA DCAST_HDR)
Marshal.PtrToSt ructure(msg.LPa ram,typeof(Win3 2.DEV_BROADCAST _HDR));
//if (dhdr.dbcc_devi cetype == Win32.DBT_DEVTY P_DEVICEINTERFA CE)
int dbccSize = Marshal.ReadInt 32(msg.LParam,0 );
int devType = Marshal.ReadInt 32(msg.LParam,4 );

if(devType == Win32.DBT_DEVTY P_DEVICEINTERFA CE)
{
Win32.DEV_BROAD CAST_DEVICEINTE RFACE1 dip;
dip = (Win32.DEV_BROA DCAST_DEVICEINT ERFACE1)
Marshal.PtrToSt ructure(msg.LPa ram,typeof(Win3 2.DEV_BROADCAST _DEVICEINTERFAC E1));
string csTemp = new string(dip.dbcc _name);
MessageBox.Show (csTemp + " arrived/removed");
}
}
}
}
public class Win32
{
public const int WM_DEVICECHANGE = 0x0219;
public const int DBT_DEVICEARRIV AL = 0x8000, // system
detected a new device
DBT_DEVICEREMOV ECOMPLETE = 0x8004; // device is gone
public const int DEVICE_NOTIFY_W INDOW_HANDLE = 0,
DEVICE_NOTIFY_S ERVICE_HANDLE = 1;
public const int DBT_DEVTYP_DEVI CEINTERFACE = 0x00000005; // device
interface class
public static Guid GUID_DEVINTERFA CE_USB_DEVICE = new
Guid("A5DCBF10-6530-11D2-901F-00C04FB951ED");

[StructLayout(La youtKind.Sequen tial)] public class DEV_BROADCAST_H DR
{
public int dbcc_size;
public int dbcc_devicetype ;
public int dbcc_reserved;
}
[StructLayout(La youtKind.Sequen tial)] public class
DEV_BROADCAST_D EVICEINTERFACE
{
public int dbcc_size;
public int dbcc_devicetype ;
public int dbcc_reserved;
public Guid dbcc_classguid;
public short dbcc_name;
}

[StructLayout(La youtKind.Sequen tial, CharSet=CharSet .Unicode)]
public class DEV_BROADCAST_D EVICEINTERFACE1
{
public int dbcc_size;
public int dbcc_devicetype ;
public int dbcc_reserved;
[MarshalAs(Unman agedType.ByValA rray, ArraySubType=Un managedType.U1,
SizeConst=16)] public byte [] dbcc_classguid;
[MarshalAs(Unman agedType.ByValA rray, SizeConst=128)] public char []
dbcc_name;
}

[DllImport("user 32.dll", SetLastError=tr ue)] public static extern
IntPtr RegisterDeviceN otification( IntPtr hRecipient, IntPtr
NotificationFil ter, Int32 Flags);
[DllImport("kern el32.dll")] public static extern int GetLastError();
}

}
Nov 16 '05 #1
1 11251
Not directly a code translation, but another way to achieve the same (or
better) result.
Using System.Manageme nt classes, you can install an event listener for USB
device controller events, these events are generated when USB devices are
connected. Note that every USB device consists of at least one or more
devices, for instance a USB disk generates 3 events when connected.

Following is a complete sample, just compile and try it out.

// This code demonstrates how to monitor the UsbControllerDe vice for
// the arrival of pnp device creation/operation events
using System;
using System.Componen tModel;
using System.Runtime. InteropServices ;
using System.Manageme nt;
class WMIEvent {
public static void Main() {
USBEvent usbEvnt = new USBEvent();
usbEvnt.Start() ;
Console.ReadLin e(); // block main thread for test purposes
usbEvnt.Stop();
}
}

internal class USBEvent
{
ManagementEvent Watcher w= null;

internal void Start()
{
// Bind to local machine
try {
WqlEventQuery q = new WqlEventQuery() ;
q.EventClassNam e = "__InstanceOper ationEvent";
q.WithinInterva l = new TimeSpan(0,0,3) ;
q.Condition = @"TargetInstanc e ISA 'Win32_USBContr ollerDevice' ";
w = new ManagementEvent Watcher(q);
w.EventArrived += new EventArrivedEve ntHandler(this. UsbEventArrived );
w.Start(); // Start listen for events
}
catch(Exception e) {this.Stop();}
}
internal void Stop() {
w.EventArrived -= new EventArrivedEve ntHandler(this. UsbEventArrived );
w.Stop();
w.Dispose();
}
public void UsbEventArrived (object sender, EventArrivedEve ntArgs e) {
//Get the Event object and display all it properties
ManagementBaseO bject mbo =
(ManagementBase Object)e.NewEve nt["TargetInstance "];
using(Managemen tObject o = new
ManagementObjec t(mbo["Dependent"].ToString()))
{
o.Get();
if (o.Properties.C ount == 0)
{
Console.WriteLi ne("No further device properties, device removed?");
}
foreach(Propert yData prop in o.Properties)
Console.WriteLi ne("{0} - {1}", prop.Name, prop.Value);
Console.WriteLi ne("-------------------------------");
}
}
}

Willy.

"Jeffrey B. Holtz" <jh****@accurat etechnologies.c om> wrote in message
news:93******** *************** ***@posting.goo gle.com...
I'm trying to get the Name of the USB device pluged in from the
RegisterDeviceN otification that I've used P/Invoke to marshal. I have
seen a similar posting on the VisualBasic newgroups but I do not know
how to translate the ReDim that occurs there into C#. Or wither this
will actually give me what I'm looking for.
The code I'm posting seems to work although I don't know how to
set the length of the name correctly in the Marshal.PtrToSt ructure()
call.

Thanks all for any help.
Hopefully this VB->VC translation can help someone out there as well

Jeff
Visual Basic Code:
=============== ===
Imports System.Runtime. InteropServices
Imports System.Windows. Forms
Imports System.Text
Public Class Form1
Inherits System.Windows. Forms.Form

Public Class Win32
Public Const WM_DEVICECHANGE = &H219
Public Const DBT_DEVICEARRIV AL = &H8000
Public Const DBT_DEVICEREMOV ECOMPLETE = &H8004
Public Const DEVICE_NOTIFY_W INDOW_HANDLE = 0
Public Const DEVICE_NOTIFY_S ERVICE_HANDLE = 1
Public Const DBT_DEVTYP_DEVI CEINTERFACE = 5
Public Shared GUID_IO_MEDIA_A RRIVAL As Guid = New
Guid("A5DCBF10-6530-11D2-901F-00C04FB951ED")

<StructLayout(L ayoutKind.Seque ntial)> _
Public Class DEV_BROADCAST_D EVICEINTERFACE
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
Public dbcc_classguid As Guid
Public dbcc_name As Short
End Class
<StructLayout(L ayoutKind.Seque ntial,
CharSet:=CharSe t.Unicode)> _
Public Class DEV_BROADCAST_D EVICEINTERFACE1
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
<MarshalAs(Unma nagedType.ByVal Array,
ArraySubType:=U nmanagedType.U1 , SizeConst:=16)> _
Public dbcc_classguid( ) As Byte
<MarshalAs(Unma nagedType.ByVal Array, SizeConst:=128) > _
Public dbcc_name() As Char
End Class
<StructLayout(L ayoutKind.Seque ntial)> _
Public Class DEV_BROADCAST_H DR
Public dbcc_size As Integer
Public dbcc_devicetype As Integer
Public dbcc_reserved As Integer
End Class

<DllImport("use r32.DLL", SetLastError:=T rue)> _
Public Shared Function _
RegisterDeviceN otification(ByV al IntPtr As IntPtr, ByVal
NotificationFil ter As IntPtr, ByVal Flags As Int32) As IntPtr
End Function

<DllImport("ker nel32.DLL")> _
Public Shared Function _
GetLastError() As Integer
End Function
End Class

Public Sub New()
MyBase.New()
InitializeCompo nent()
RegisterHidNoti fication()
End Sub

Public Sub RegisterHidNoti fication()
Dim dbi As Win32.DEV_BROAD CAST_DEVICEINTE RFACE = New
Win32.DEV_BROAD CAST_DEVICEINTE RFACE
Dim size As Integer
size = Marshal.SizeOf( dbi)
Dim gd As Guid
' MsgBox(Marshal. SizeOf(gd))
' MsgBox(Marshal. SizeOf(New
Win32.DEV_BROAD CAST_DEVICEINTE RFACE1))
dbi.dbcc_size = size
dbi.dbcc_device type = Win32.DBT_DEVTY P_DEVICEINTERFA CE
dbi.dbcc_reserv ed = 0
dbi.dbcc_classg uid = Win32.GUID_IO_M EDIA_ARRIVAL
Dim Buffer As IntPtr
Buffer = Marshal.AllocHG lobal(size)
Marshal.Structu reToPtr(dbi, Buffer, True)
Dim r As IntPtr
r = Win32.RegisterD eviceNotificati on(Handle, Buffer,
Win32.DEVICE_NO TIFY_WINDOW_HAN DLE)
Marshal.PtrToSt ructure(Buffer, dbi)
If r.ToInt32 = IntPtr.Zero.ToI nt32 Then
MessageBox.Show (Win32.GetLastE rror().ToString ())
End If
End Sub

Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = Win32.WM_DEVICE CHANGE Then
OnDeviceChange( m)
End If
MyBase.WndProc( m)
End Sub

Private Sub OnDeviceChange( ByVal msg As Message)
Dim wParam As Integer
wParam = msg.WParam.ToIn t32()
If wParam = Win32.DBT_DEVIC EARRIVAL Then
Dim o As New Win32.DEV_BROAD CAST_HDR
Dim b As New Win32.DEV_BROAD CAST_DEVICEINTE RFACE1
Dim gd As Guid
Marshal.PtrToSt ructure(msg.LPa ram, o)
If (o.dbcc_devicet ype = Win32.DBT_DEVTY P_DEVICEINTERFA CE)
Then
Dim strsize As Integer = (o.dbcc_size - 28) / 2
ReDim b.dbcc_name(str size)
Marshal.PtrToSt ructure(msg.LPa ram, b)
MsgBox(New Guid(b.dbcc_cla ssguid).ToStrin g)
Dim str As New String(b.dbcc_n ame, 0, strsize)
MsgBox(str)
End If
MessageBox.Show ("Arrival")
ElseIf wParam = Win32.DBT_DEVIC EREMOVECOMPLETE Then
MessageBox.Show ("Remove")
End If
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
components = New System.Componen tModel.Containe r
Me.Text = "Form1"
Dim t As New Guid("d07433c0-a98e-11d2-917a-00a0c9068ff3")
End Sub
End Class
Visual CSharp Equivilent
=============== =========
using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Runtime. InteropServices ;

namespace WindowsApplicat ion1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows. Forms.Form
{
private System.Componen tModel.Containe r components = null;

public Form1()
{
InitializeCompo nent();
RegisterDeviceN otification();
}

private void InitializeCompo nent()
{
this.components = new System.Componen tModel.Containe r();
this.Size = new System.Drawing. Size(300,300);
this.Text = "Form1";
}

[STAThread] static void Main()
{
Application.Run (new Form1());
}

void RegisterDeviceN otification()
{
Win32.DEV_BROAD CAST_DEVICEINTE RFACE dbi = new
Win32.DEV_BROAD CAST_DEVICEINTE RFACE();
int size = Marshal.SizeOf( dbi);
dbi.dbcc_size = size;
dbi.dbcc_device type = Win32.DBT_DEVTY P_DEVICEINTERFA CE;
dbi.dbcc_reserv ed = 0;
dbi.dbcc_classg uid = Win32.GUID_DEVI NTERFACE_USB_DE VICE;
dbi.dbcc_name = 0;
IntPtr buffer = Marshal.AllocHG lobal(size);
Marshal.Structu reToPtr(dbi, buffer, true);
IntPtr r = Win32.RegisterD eviceNotificati on(Handle, buffer,
Win32.DEVICE_NO TIFY_WINDOW_HAN DLE);
if(r == IntPtr.Zero)
MessageBox.Show (Win32.GetLastE rror().ToString ());
}
protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case Win32.WM_DEVICE CHANGE: OnDeviceChange( ref m); break;
}
base.WndProc (ref m);
}
void OnDeviceChange( ref Message msg)
{
int wParam = (int)msg.WParam ;
if((wParam == Win32.DBT_DEVIC EARRIVAL) || (wParam ==
Win32.DBT_DEVIC EREMOVECOMPLETE ))
{
// Read the dhdr.dbcc_devic etype - The Following code could also
be used
////////////////////////////////////////////////////////////////////////
//Win32.DEV_BROAD CAST_HDR dhdr;
//dhdr = (Win32.DEV_BROA DCAST_HDR)
Marshal.PtrToSt ructure(msg.LPa ram,typeof(Win3 2.DEV_BROADCAST _HDR));
//if (dhdr.dbcc_devi cetype == Win32.DBT_DEVTY P_DEVICEINTERFA CE)
int dbccSize = Marshal.ReadInt 32(msg.LParam,0 );
int devType = Marshal.ReadInt 32(msg.LParam,4 );

if(devType == Win32.DBT_DEVTY P_DEVICEINTERFA CE)
{
Win32.DEV_BROAD CAST_DEVICEINTE RFACE1 dip;
dip = (Win32.DEV_BROA DCAST_DEVICEINT ERFACE1)
Marshal.PtrToSt ructure(msg.LPa ram,typeof(Win3 2.DEV_BROADCAST _DEVICEINTERFAC E1));
string csTemp = new string(dip.dbcc _name);
MessageBox.Show (csTemp + " arrived/removed");
}
}
}
}
public class Win32
{
public const int WM_DEVICECHANGE = 0x0219;
public const int DBT_DEVICEARRIV AL = 0x8000, // system
detected a new device
DBT_DEVICEREMOV ECOMPLETE = 0x8004; // device is gone
public const int DEVICE_NOTIFY_W INDOW_HANDLE = 0,
DEVICE_NOTIFY_S ERVICE_HANDLE = 1;
public const int DBT_DEVTYP_DEVI CEINTERFACE = 0x00000005; // device
interface class
public static Guid GUID_DEVINTERFA CE_USB_DEVICE = new
Guid("A5DCBF10-6530-11D2-901F-00C04FB951ED");

[StructLayout(La youtKind.Sequen tial)] public class DEV_BROADCAST_H DR
{
public int dbcc_size;
public int dbcc_devicetype ;
public int dbcc_reserved;
}
[StructLayout(La youtKind.Sequen tial)] public class
DEV_BROADCAST_D EVICEINTERFACE
{
public int dbcc_size;
public int dbcc_devicetype ;
public int dbcc_reserved;
public Guid dbcc_classguid;
public short dbcc_name;
}

[StructLayout(La youtKind.Sequen tial, CharSet=CharSet .Unicode)]
public class DEV_BROADCAST_D EVICEINTERFACE1
{
public int dbcc_size;
public int dbcc_devicetype ;
public int dbcc_reserved;
[MarshalAs(Unman agedType.ByValA rray, ArraySubType=Un managedType.U1,
SizeConst=16)] public byte [] dbcc_classguid;
[MarshalAs(Unman agedType.ByValA rray, SizeConst=128)] public char []
dbcc_name;
}

[DllImport("user 32.dll", SetLastError=tr ue)] public static extern
IntPtr RegisterDeviceN otification( IntPtr hRecipient, IntPtr
NotificationFil ter, Int32 Flags);
[DllImport("kern el32.dll")] public static extern int GetLastError();
}

}

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3211
by: BlackHawke | last post by:
Hello! In our game package (www.andromedaonline.net) we are having problems with sounds. We have placed them in a jar file, and are trying to access them from there. The jar file has a directory structure. A number of sounds have the same name, but are in a different directory (for example, our game has 5 races. Each race has the same set of sounds- button clicks, etc, but the actual sound is different).
35
2555
by: NickName | last post by:
I understand it's easy to list all saved queries of a given Access database via Msysobjects system table. However, I have not seen any posting over this NG or other similar ones that also include SQL statement(content) of these queries, though I've noticed some VB code for that. Is that because it's simply impossible to get a query content (not query resultset) from a SQL stmt? Thanks in advance.
5
7736
by: jan axelson | last post by:
My application is using RegisterDeviceNotification() to detect attachment and removal of a USB HID-class device. The form is receiving WM_DEVICECHANGE messages with wParam set to DBT_DEVICEARRIVAL or DBT_DEVICEREMOVECOMPLETE. I want to identify the device that has arrived or been removed by examining the dbcc_name member of the DEV_BROADCAST_DEVICEINTERFACE structure.
2
1116
by: Jay Banks | last post by:
I'm working on a project that lists a few hundred items in a checked listbox. The listbox entries are all backed up by a structure, and only the descriptiong of the structure is shown in the listbox. Here's my structure: Public Structure ItemData Dim Descriptiong As String Dim Cost As Single Dim Quantity As Integer Dim Frequency As Single
0
4227
by: AvecFromage | last post by:
Hi, I'd like to be able to read the positions of all the Icons on my WinXP desktop. I've had a look around to see how to do it and I've come up with the code below...but it doesn't work. :o( The x and y properties of my POINT structure are always zero. It seems the structure isn't getting updated at all from the SendMessage function and so the code just displays the default values.
8
8496
by: Chad | last post by:
To anyone who is smarter than I am when it comes to WMI: Here is what I am trying to do: 1) Detect a USB pen drive when it is inserted 2) Retrieve the drive letter of the pen drive 3) Check for a specific folder on the pen drive I keep receiving an error message that reads: An unhandled exception of type 'System.ExecutionEngineException'
5
2656
by: Randy Smith | last post by:
Hi ALL, I wonder if anyone has been using n-tier to bind to a GridView control by using the ObjectDataSource. This is our first OOP web application, and we have no tables. Right now we are simply working with objects in memory. So, it appears as though Microsoft requires that our datamapper classes reside inside a folder called "App_Code", and NO WHERE ELSE. So, has anyone successfully been able to place their datamappers in a...
1
1680
by: lmwasisebe | last post by:
hie guys i having problems retrieving xml values, this is the structure of the problem: I have a database with the following fields, 1)id 2)state 3)request. the request field contains a xml file converted to a string. the problem now is that i have to retrieve certain values from that xml string in the request field and save the in some other databse please assist
3
2723
by: =?Utf-8?B?UHJpeWE=?= | last post by:
Hi, Could someone tell me how to retrieve a drive's drive letter from user mode given its device name? Any information is greatly appreciated. Thanks, Priya
3
8755
by: BlackShadow33p1 | last post by:
I'm trying to write a program in C++ that gets the handles of all the visible entries in the windows taskbar. The method I've used so far is to send the TB_GETBUTTON message to the taskbar. Supposedly the window handle for an entry is in the dwData structure in the TBBUTTON structure but I'm having a hard time retrieving the handle from the structure correctly. It seems when I look at the data I've retrieved, it is not a handle (negative...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10219
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.