 |
|
 |
I'm using 'Computer' for a class name. I seem to get the GUID OK, but I'm having a tough time understanding what's wrong after that.
|
|
|
|
 |
|
 |
Hi,
I find your code useful. Can I use it in a commercial application? Any terms and conditions?
Thanks!
|
|
|
|
 |
|
|
 |
|
 |
Hi,
First - thank you for the nice example project!
Would it be possible to get device info in a tree-like structure. For instance, if you open Windows device manager and let Windows to display devices "by connection" - so that each USB root hub has child devices under it. In a simple case - if a USB mouse is connected to USB root hub, the usb root hub is the parent device and mouse is child device.
How to implement this functionality using the Setup API + CM_* calls?
Best regards,
Alex
|
|
|
|
 |
|
 |
Hi Alex.
>First - thank you for the nice example project!
Thank you for your good words.
I am not sure about your question. May be you find some addition functionality in the WMI. If I'll be in good humour I'll try to add something about in ".NET - Diving into System Programming - Part 4".
Vladimir aka Macavity
|
|
|
|
 |
|
 |
Does .NET 20 or 30 added some "easy" support for device enumeration??
Or we should continue to use P/Invoke like in Vladimir Afanasyev's superb post??
|
|
|
|
 |
|
 |
Hi.
I think we can find some answers in the WMI.
Best Regards.
Vladimir aka Macavity
|
|
|
|
 |
|
 |
Hi,
I'm writing you to ask if I can use your DevInfo class to a little project that I would post at CodeProject (with your credits, of course!).
I need a class that can enumerate webcams plugged into the PC.
I didn't test your class on this yet, but it seems what I need.
|
|
|
|
 |
|
 |
Hi!
I am not sure about webcams. But you can use my program if you need.
Best Regards.
|
|
|
|
 |
|
 |
--------------------------------------------------------------------------
here is VC# code (Working)
--------------------------------------------------------------------------
class Class1
{
[DllImport("setupapi.dll")]//
public static extern Boolean
SetupDiClassGuidsFromNameA(string ClassN, ref Guid guids, UInt32 ClassNameSize, ref UInt32 ReqSize);
[STAThread]
static void Main(string[] args)
{
UInt32 RequiredSize = 0;
Guid[] guids=new Guid[1];
bool res=SetupDiClassGuidsFromNameA("DiskDrive",ref guids[0],RequiredSize, ref RequiredSize);
}
--------------------------------------------------------------------------
Here is the code that i convert to VC++(no working)
--------------------------------------------------------------------------
#include "stdafx.h"
#using
using namespace System::Runtime::InteropServices;
using namespace System;
using namespace System::Text;
[DllImportAttribute("setupapi.dll", CharSet=CharSet::Auto)]
extern "C" Boolean
SetupDiClassGuidsFromNameA(String *ClassN, Guid* guids, UInt32 ClassNameSize, unsigned int *ReqSize);
int _tmain()
{
UInt32 RequiredSize = 0;
Guid guids = new Guid[1];
SetupDiClassGuidsFromNameA(S"DiskDrive", guids[0], RequiredSize, &RequiredSize);
Console::WriteLine(RequiredSize.ToString());
return 0;
}
--------------------------------------------------------------------------The Correct behaviour is the RequiredSize should be Greater than 0, but the code that i have convert the RequiredSize always return 0.
can any one help me.
|
|
|
|
 |
|
 |
--------------------------------------------------------------------------
here is VC# code (Working)
--------------------------------------------------------------------------
class Class1
{
[DllImport("setupapi.dll")]//
public static extern Boolean
SetupDiClassGuidsFromNameA(string ClassN, ref Guid guids, UInt32 ClassNameSize, ref UInt32 ReqSize);
[STAThread]
static void Main(string[] args)
{
UInt32 RequiredSize = 0;
Guid[] guids=new Guid[1];
bool res=SetupDiClassGuidsFromNameA("DiskDrive",ref guids[0],RequiredSize, ref RequiredSize);
}
--------------------------------------------------------------------------
Here is the code that i convert to VC++(no working)
--------------------------------------------------------------------------
#include "stdafx.h"
#using
using namespace System::Runtime::InteropServices;
using namespace System;
using namespace System::Text;
[DllImportAttribute("setupapi.dll", CharSet=CharSet::Auto)]
extern "C" Boolean
SetupDiClassGuidsFromNameA(String *ClassN, Guid* guids, UInt32 ClassNameSize, unsigned int *ReqSize);
int _tmain()
{
UInt32 RequiredSize = 0;
Guid guids = new Guid[1];
SetupDiClassGuidsFromNameA(S"DiskDrive", guids[0], RequiredSize, &RequiredSize);
Console::WriteLine(RequiredSize.ToString());
return 0;
}
--------------------------------------------------------------------------The Correct behaviour is the RequiredSize should be Greater than 0, but the code that i have convert the RequiredSize always return 0.
can any one help me.
|
|
|
|
 |
|
 |
--------------------------------------------------------------------------
here is VC# code (Working)
--------------------------------------------------------------------------
class Class1
{
[DllImport("setupapi.dll")]//
public static extern Boolean
SetupDiClassGuidsFromNameA(string ClassN, ref Guid guids, UInt32 ClassNameSize, ref UInt32 ReqSize);
[STAThread]
static void Main(string[] args)
{
UInt32 RequiredSize = 0;
Guid[] guids=new Guid[1];
bool res=SetupDiClassGuidsFromNameA("DiskDrive",ref guids[0],RequiredSize, ref RequiredSize);
}
--------------------------------------------------------------------------
Here is the code that i convert to VC++(no working)
--------------------------------------------------------------------------
#include "stdafx.h"
#using
using namespace System::Runtime::InteropServices;
using namespace System;
using namespace System::Text;
[DllImportAttribute("setupapi.dll", CharSet=CharSet::Auto)]
extern "C" Boolean
SetupDiClassGuidsFromNameA(String *ClassN, Guid* guids, UInt32 ClassNameSize, unsigned int *ReqSize);
int _tmain()
{
UInt32 RequiredSize = 0;
Guid guids = new Guid[1];
SetupDiClassGuidsFromNameA(S"DiskDrive", guids[0], RequiredSize, &RequiredSize);
Console::WriteLine(RequiredSize.ToString());
return 0;
}
--------------------------------------------------------------------------
The Correct behaviour is the RequiredSize should be Greater than 0, but the code that i have convert the RequiredSize always return 0.
can any one help me.
|
|
|
|
 |
|
 |
Hi
I would like to get the current state of a specific device, if it is disabled or enabled ?
Is that possible ? and how do I do it ? (if it's posible with code example )
Thanx.
GG.
|
|
|
|
 |
|
 |
Hi
I suggest you to read comments from next part of article
(.NET - Diving into System Programming - Part 3,
http://www.codeproject.com/csharp/DivingSysProg3.asp).
Read carefully "Device anable/disable" comments thread.
There you find good messages from Ian_001 and HiAle.
Vladimir.
|
|
|
|
 |
|
 |
Hi
Thank you for answering!
I looked at (.NET - Diving into System Programming - Part 3,
http://www.codeproject.com/csharp/DivingSysProg3.asp).
I can enable and disable any device using code supplied by Ian_001 and HiAle ,but the problem is that if I disable a device 3 times ,than I also have to use the enable function 3 times ,if not ,the device will still stay disabled.
This is why I would like to get the current state of a device before disableing it ,so I don't allow the disable function if the device is allready disabled.
I hope it's not confusing and you can help me with this
GG.
|
|
|
|
 |
|
 |
Hi.
Frankly I am not ready to give answer just now.
I hope to do it on the next week.
Best Regards.
Vladimir.
|
|
|
|
 |
|
 |
I need some script using WMI that shows me the files for the device drivers
installed on my PC. Does anybody know hou could I do that?
|
|
|
|
 |
|
 |
Follow ref. should help you (for XP and Windows Server 2003):
List Plug and Play Signed Drivers
http://www.microsoft.com/technet/scriptcenter/scripts/hardware/devices/hwdevbo4.mspx
Vladimir.
|
|
|
|
 |
|
 |
After the line
if( NewDeviceInfoSet.ToInt32() == -1 )
there is no '{'.
I haven't looked to see if the '{'s and '}'s balance, so there may be a '}' missing too.
If you choose to use a single statement as the body of the 'if' without enclosing it in {} (condemned by coding standards), the indenting needs care.
While I'm looking at that line, what does -1 stand for? Not even the MSDN page on SetupDiGetClassDevs says anything about -1 in the Return Values section of the page. Magic numbers bad!
|
|
|
|
 |
|
 |
hobyrne wrote: If you choose to use a single statement as the body of the 'if' without enclosing it in {} (condemned by coding standards), the indenting needs care.
Yes of course - no need to use { and } in this case.
hobyrne wrote: While I'm looking at that line, what does -1 stand for? Not even the MSDN page on SetupDiGetClassDevs says anything about -1 in the Return Values section of the page. Magic numbers bad!
-1 means INVALID_HANDLE_VALUE.
Vladimir.
|
|
|
|
 |
|
 |
But may be
if( NewDeviceInfoSet.ToInt32() == -1 )
if(!res)
{
//device information is unavailable:
DeviceName=new StringBuilder("");
return -3;
}
is error.
May follow will better:
if( NewDeviceInfoSet.ToInt32() == -1 )
{
//device information is unavailable:
DeviceName=new StringBuilder("");
return -3;
}
|
|
|
|
 |
|
 |
Is there any reason for not using the Unicode Win32 APIs?
Isn't it a good idea to use GCHandle when using WIN32 APIs which have pointers as parameters? The existing code works, but it makes implicit assumptions about the managed memory layout.
Apart from these issues your code has been really helpful!
Richard Lyon
|
|
|
|
 |
|
 |
RLyon wrote:
Is there any reason for not using the Unicode Win32 APIs?
Frankly, firstly I did this code for C++ (I prefer Borland C++ Builder) and not for Microsoft .Net. I wanted that code works for various OS begining Win98. This was reason why
I don't used Unicode. The source I put in Borland codecentral. And now I only transfer this code from C++ to C#.
RLyon wrote:
Isn't it a good idea to use GCHandle when using WIN32 APIs which have pointers as parameters? The existing code works, but it makes implicit assumptions about the managed memory layout.
May be you are right - I don't think about this matter.
RLyon wrote:
Apart from these issues your code has been really helpful!
Oh! Many thanks.
|
|
|
|
 |
|
 |
Have you looked at or considered what effort is involved in using the WMI objects in WBEM to enumerate these things, instead of using direct Win32 API calls?
Just curious...
Regardless, thanks for a very good article.
|
|
|
|
 |
|
 |
Thank you.
WMI is really a good thing.
But exist some problems with WMI.
I mean that I had problems...
I write about it in Part 3.
Best Regards.
|
|
|
|
 |