Click here to Skip to main content
15,913,722 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: THREE TIER WITH ASP.NET WEBSERVICES Pin
Not Active14-Aug-11 18:53
mentorNot Active14-Aug-11 18:53 
QuestionDATAREPEATER GUIDE Pin
AleBio10-Aug-11 3:36
AleBio10-Aug-11 3:36 
AnswerRe: DATAREPEATER GUIDE Pin
Dave Kreskowiak10-Aug-11 7:22
mveDave Kreskowiak10-Aug-11 7:22 
AnswerRe: DATAREPEATER GUIDE Pin
Eddy Vluggen10-Aug-11 12:34
professionalEddy Vluggen10-Aug-11 12:34 
AnswerRe: DATAREPEATER GUIDE Pin
sivakumat11-Aug-11 1:34
sivakumat11-Aug-11 1:34 
QuestionSystem Enumeration - CreateClassEnumerator Pin
SarahJMR8-Aug-11 8:52
SarahJMR8-Aug-11 8:52 
QuestionRe: System Enumeration - CreateClassEnumerator Pin
Shameel10-Aug-11 5:20
professionalShameel10-Aug-11 5:20 
AnswerRe: System Enumeration - CreateClassEnumerator Pin
SarahJMR10-Aug-11 5:36
SarahJMR10-Aug-11 5:36 
Hi,

Thank you for the response. Here is a better description of the problem. To answer your specific question, oEnum, the Activator.CreateInstance call.

I am trying to enumerate system devices using .Net. The problem that I have is that Activator.CreateInstance returns null, even though I pass in a valid System Device Enumeration GUIID class. You can search the registry and find it.

The result of Type.GetTypeFromCLSID(clsidSystemDeviceEnum, true) copy and pasted from the debugger window holding the oEnum variable is:

{Name = "__ComObject" FullName = "System.__ComObject"}


A Google search yielded a couple of hits that showed that Activator.CreateInstance will sometimes return a null when the type is "__ComObject" but the hits never went deeper. Several articles talk about device enumeration and all gave the same code, namely to start by enumerating the System Device Enumeration object.

You can see the code below. Please ignore the clsidDeviceClass. That is not relevant in the code below. That is used below in the part of the code not visible (in the etc., etc., etc. part). That variable will hold the SCSI Storage object, which is one of the system devices. Just to be specific, this variable will have the value, clsidDeviceClass = new Guid("2ACCFE60-C130-11D2-B082-00A0C91EFB8B");.

First thing is first and that is to resolve why I receive a null from the call to Activator.CreateInstance and of course how I can resolve the problem so that I get a valid object back.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Runtime.InteropServices.ComTypes;
using System.Collections;


public void CreateClassEnumerator([In] System.Guid clsidDeviceClass, [Out] out System.Runtime.InteropServices.ComTypes.IEnumMoniker ppEnumMoniker, [In] uint dwFlags)
{
                Guid clsidSystemDeviceEnum;
//            ICreateDevEnum pSysDevEnum;


                // Initialize the return value.
                ppEnumMoniker = null;

                try
                {
                                // Defined in "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\uuids.h" on line 960
                                clsidSystemDeviceEnum = new Guid("62BE5D10-60EB-11d0-BD3B-00A0C911CE86");

                                // Get the COM type from the class ID.
                                Type comType = Type.GetTypeFromCLSID(clsidSystemDeviceEnum, true);

                                // Create the COM instance for this object.
                                object oEnum;
                                oEnum = Activator.CreateInstance(comType);

                                // Create the device enumerator (COM) object.
//                            pSysDevEnum = oEnum as ICreateDevEnum;

                                // etc., etc., etc.
                }

                catch (Exception ex)
                {
                                MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK);
                }
}


Thanks,

Sarah
GeneralRe: System Enumeration - CreateClassEnumerator Pin
Shameel10-Aug-11 5:54
professionalShameel10-Aug-11 5:54 
GeneralRe: System Enumeration - CreateClassEnumerator Pin
SarahJMR10-Aug-11 6:02
SarahJMR10-Aug-11 6:02 
GeneralRe: System Enumeration - CreateClassEnumerator Pin
Shameel10-Aug-11 6:10
professionalShameel10-Aug-11 6:10 
GeneralRe: System Enumeration - CreateClassEnumerator Pin
SarahJMR10-Aug-11 6:17
SarahJMR10-Aug-11 6:17 
GeneralRe: System Enumeration - CreateClassEnumerator Pin
Shameel10-Aug-11 9:10
professionalShameel10-Aug-11 9:10 
GeneralRe: System Enumeration - CreateClassEnumerator Pin
SarahJMR10-Aug-11 9:11
SarahJMR10-Aug-11 9:11 
GeneralRe: System Enumeration - CreateClassEnumerator Pin
Shameel10-Aug-11 9:14
professionalShameel10-Aug-11 9:14 
GeneralRe: System Enumeration - CreateClassEnumerator Pin
SarahJMR10-Aug-11 9:18
SarahJMR10-Aug-11 9:18 
GeneralRe: System Enumeration - CreateClassEnumerator Pin
Shameel10-Aug-11 9:22
professionalShameel10-Aug-11 9:22 
GeneralRe: System Enumeration - CreateClassEnumerator Pin
SarahJMR10-Aug-11 9:24
SarahJMR10-Aug-11 9:24 
Questionhi Pin
leila1234567896-Aug-11 0:08
leila1234567896-Aug-11 0:08 
Questionhi Pin
leila1234567896-Aug-11 0:06
leila1234567896-Aug-11 0:06 
AnswerRe: hi Pin
#realJSOP17-Aug-11 4:13
professional#realJSOP17-Aug-11 4:13 
QuestionNot... Is, or IsNot... Pin
Sander Rossel3-Aug-11 7:33
professionalSander Rossel3-Aug-11 7:33 
AnswerRe: Not... Is, or IsNot... Pin
Dave Kreskowiak3-Aug-11 8:52
mveDave Kreskowiak3-Aug-11 8:52 
GeneralRe: Not... Is, or IsNot... Pin
Sander Rossel3-Aug-11 20:16
professionalSander Rossel3-Aug-11 20:16 
GeneralRe: Not... Is, or IsNot... Pin
David Skelly3-Aug-11 22:01
David Skelly3-Aug-11 22:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.