473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

System.NullReferenceException in Interop

Hi there,

I am getting a System.NullReference exception when calling an unmanaged
method CreateClassEnumerator. I am really new to Interop, so that I am
having trouble finding out a solution. The code is the following :

<code>

using System;

using System.Runtime.InteropServices;

using System.Collections;

namespace COMInterop1

{

/*
[

object,

uuid(29840822-5B84-11D0-BD3B-00A0C911CE86),

pointer_default(unique)

]
interface ICreateDevEnum : IUnknown

{

import "oaidl.idl";

HRESULT CreateClassEnumerator(

[in] REFCLSID clsidDeviceClass,

[out] IEnumMoniker ** ppEnumMoniker,

[in] DWORD dwFlags);

}*/
[//System device Enumerator Import, implements ICreateDevEnum
Guid("62BE5D10-60EB-11d0-BD3B-00A0C911CE86"),ComImport]

public class SystemDeviceEnumerator

{

}

//Managed declaration of ICreateDevEnum

[Guid("29840822-5B84-11D0-BD3B-00A0C911CE86"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]

interface ICreateDevEnum {

void CreateClassEnumerator([In] Guid clsidDeviceClass, [Out] out
UCOMIEnumMoniker ppEnumMoniker, [In] UInt32 dwFlags);

}

public class Tester

{
static void Main ()

{

Guid deviceClass = new Guid("860BB310-5D01-11d0-BD3B-00A0C911CE86");
UCOMIEnumMoniker EnumMon;
UInt32 dFlag = 0;
SystemDeviceEnumerator de = new SystemDeviceEnumerator();

ICreateDevEnum Ide = (ICreateDevEnum)de;

try

{

Ide.CreateClassEnumerator(deviceClass, out EnumMon, dFlag);
}

catch (Exception e)

{

Console.WriteLine(e.ToString());

Console.Read();

}

}

}

}

</code>

Nov 15 '05 #1
0 1537

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

Similar topics

3
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in...
0
by: Yoni Rabinovitch | last post by:
Hi, I am new to C#, so I apologise if this is a stupid question. I have some 3rd party C++ code, which gets built as static libraries (not DLLs). I want to create a C# form, which will call...
1
by: Rafael | last post by:
Hi, I hope I can find some help for this problem IDE: Visual Studio.NET 2003 Developer Editio Language: C# Problem: "An unhandled exception of type 'System.NullReferenceException' occurred in...
0
by: muralidharan | last post by:
WebForm1.aspx Code: <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView id="TreeView1" Height="520"...
2
by: Raed Sawalha | last post by:
i have a windows form(Main) with listview, when click an item in listview i open other window form (Sub) which generate the selected item from parent window in as treeview items when click any item...
1
by: msnews.microsoft.com | last post by:
I'm trying to fill an array of objects but when I add the first object I get a NullReferenceException. ----------------------------------------------------------------------------...
2
by: sxiao | last post by:
Hi, there I got a NullReferenceException when there are more than one users trying to open the same page at the same time. The senerio is: Two users logged into the web application using the...
6
by: William Mild | last post by:
I must be getting brain fried. I can't see the error. Create a new web form with the following code begind: Public Class test Inherits System.Web.UI.Page Public Class ReportCardData ...
3
by: Alex J. | last post by:
I just started to learn C# (my background is in C++), and right now I study the sockets, TCP/IP etc... so, I found a usefull source code at:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.