By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,490 Members | 1,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,490 IT Pros & Developers. It's quick & easy.

Error while implementing interface

P: n/a
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

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.
InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
public interface IWiaItem
[ComVisible(true), ComImport,
InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
public interface IWiaDevMgr
int EnumDeviceInfo(
long lFlag,
out IntPtr ppIEnum); // IEnumWIA_DEV_INFO **

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

int SelectDeviceDlg(
/* [in] */ int hwndParent,
/* [in] */ long lDeviceType,
/* [in] */ long lFlags,
/* [out][in] */ int pbstrDeviceID, // Bstr *
[Out] out IWiaItem i3);
Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.