473,386 Members | 1,699 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,386 software developers and data experts.

Error while implementing interface

LGS
These three lines work fine in c++.

hr = CoInitialize(NULL);
hr = CoCreateInstance(CLSID_WiaDevMgr, NULL, CLSCTX_ALL, IID_IWiaDevMgr,
(LPVOID *)&iDM);
hr = iDM->SelectDeviceDlg(NULL, 0, 0, NULL, &iRoot);

However, attempts to implement this in c# are proving difficult. Since
there is no idl or tlb for Windows Image Acquisition (WIA), I'm rolling my
own. Clearly I've done it incorrectly, but I can't spot it. I'm not looking
for someone to write the interface for me. Just for any general interop
tips, troubleshooting, or references.

I've included some code snippets in case something jumps out at someone.
The interfaces here are in wia.h in the platform sdk.

The error is that calls to SelectDeviceDlg keep returning
System.NullReferenceException:

Guid g = new Guid("a1f4e726-8cf1-11d1-bf92-0060081ed811");

IWiaDevMgr iw = (IWiaDevMgr) Activator.CreateInstance(
Type.GetTypeFromCLSID( g, true ) );
IWiaItem pRoot;
iw.SelectDeviceDlg(0, 1, 0, 0, out pRoot);

The (partial) interface listings are below. I've tried everything I can
think of. I've changed the parameter types to IntPtr, int, I've tried
MarshalAs, ref, nothing seems to work.
[Guid("4db1ad10-3391-11d2-9a33-00c04fa36145"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
public interface IWiaItem
{
etc
[ComVisible(true), ComImport,
Guid("5eb2502a-8cf1-11d1-bf92-0060081ed811"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
public interface IWiaDevMgr
{
[PreserveSig]
int EnumDeviceInfo(
long lFlag,
out IntPtr ppIEnum); // IEnumWIA_DEV_INFO **

[PreserveSig]
int CreateDevice(
[MarshalAs(UnmanagedType.BStr)] string bstrDeviceID,
IntPtr ppWiaItemRoot); // IWiaItem **

//[PreserveSig]
int SelectDeviceDlg(
/* [in] */ int hwndParent,
/* [in] */ long lDeviceType,
/* [in] */ long lFlags,
/* [out][in] */ int pbstrDeviceID, // Bstr *
[Out] out IWiaItem i3);
etc
Nov 16 '05 #1
0 2462

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

Similar topics

6
by: Martyn Lawson | last post by:
Hi, I am currently working as an Analyst on a .NET Web Project using ASP.NET and C#.NET. I have a couple of, at least what should be, quick questions: 1. My understanding of UML says that...
67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
9
by: Tyler | last post by:
I am attempting to extend a legacy VB6 application by making it use a .NET component written in C# exposed through COM interop. Everything appeared to be going well (VB application creates the...
5
by: Colin McGuire | last post by:
Hi all, when I write the class below Private Class employee End Class and then add the line "Implements IVF" which is an interface I have written, the IDE modifies my code to display
7
by: Scott M. | last post by:
In a typical class, do I need to indicate that it implements the IDisposable interface and then create a Dispose method that implements the Dispose required by the IDisposable interface or can I...
2
by: larzeb | last post by:
I receive the following error from the compiler: ScheduledInfo' must implement 'Property AddrLine1() As String' for interface 'ICASSBatch'. Implementing property must have matching...
1
by: Gomathi | last post by:
hi all, How to implement an interface in ASP.Net?. Consider my interface name is IExample. Then whatz mean by IExample ie = (IExample)obj1 Kindly let me know about this implementing interface...
3
by: David Veeneman | last post by:
I'm new to VB.NET, and I am translating an object model from C# to VB.NET, and I have come across an odd problem implementing an interface. The interface is a custom interface, IDrillDown, which...
6
by: Raj Wall | last post by:
Hi, I am trying to implement the IEqualityComparer interface for a struct so I can use it as the Key for a Dictionary. My struct declaration has: public struct Ring : IEqualityComparer {...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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.