These three lines work fine in c++.
hr = CoInitialize(NU LL);
hr = CoCreateInstanc e(CLSID_WiaDevM gr, NULL, CLSCTX_ALL, IID_IWiaDevMgr,
(LPVOID *)&iDM);
hr = iDM->SelectDeviceDl g(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.NullRefe renceException:
Guid g = new Guid("a1f4e726-8cf1-11d1-bf92-0060081ed811");
IWiaDevMgr iw = (IWiaDevMgr) Activator.Creat eInstance(
Type.GetTypeFro mCLSID( g, true ) );
IWiaItem pRoot;
iw.SelectDevice Dlg(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(C omInterfaceType .InterfaceIsIUn known)]
public interface IWiaItem
{
etc
[ComVisible(true ), ComImport,
Guid("5eb2502a-8cf1-11d1-bf92-0060081ed811"),
InterfaceType(C omInterfaceType .InterfaceIsIUn known)]
public interface IWiaDevMgr
{
[PreserveSig]
int EnumDeviceInfo(
long lFlag,
out IntPtr ppIEnum); // IEnumWIA_DEV_IN FO **
[PreserveSig]
int CreateDevice(
[MarshalAs(Unman agedType.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