0

I'm trying to implement some WIA 2.0 code in my VS2012 C++ library and have run into a problem with the IWiaDevMgr2::GetImageDlg call, specifically the ppbstrFilePaths paraneter. I'm not quite sure how to declare/initialize it.

From the documentation at http://msdn.microsoft.com/en-us/library/windows/desktop/aa359932(v=vs.85).aspx:

ppbstrFilePaths [in] TYPE - BSTR**

The address of a pointer to an array of paths for the scanned files. Initialize the pointer to point to an array of size zero (0) before IWiaDevMgr2::GetImageDlg is called. See Remarks.

I've tried all sorts of variations on declaring this with no success, for example:

    // No scanner selection dialog, hr = E_OUTOFMEMORY
    BSTR *files = new BSTR[0];
    HRESULT hr = _pWiaDevMgr->GetImageDlg(0, NULL, *_parentHwnd, path, fileTemplate, numFiles, &files, &_pWiaItemRoot);

I've also tried things similar to this:

    // No scanner selection dialog, hr = E_OUTOFMEMORY
    BSTR **files = (BSTR**)CoTaskMemAlloc(0);
    *files = new BSTR[0];
    HRESULT hr = _pWiaDevMgr->GetImageDlg(0, NULL, *_parentHwnd, path, fileTemplate, &numFiles, files, &_pWiaItemRoot);

Can anyone point me in the right direction for declaring and initializing this BSTR**? I'm not a big C++ dev and pretty much guessing at this point.

DCreeron
  • 86
  • 2

1 Answers1

0

Turns out I was on the right track with my first try:

CComBSTR path("D:\\TestWiaScan");
CComBSTR fileTemplate("FileName");
LONG numFiles = 0L;

BSTR *files = new BSTR[0];
HRESULT hr1 = _pWiaDevMgr->GetImageDlg(0, NULL, _parentHwnd, path, fileTemplate, &numFiles, &files, &_pWiaItemRoot);
if (files)
{
    for(int i=0;i < numFiles;i++)
    {
        SysFreeString(files[i]);
    }
}
CoTaskMemFree(files);

if (_pWiaItemRoot)
{
    _pWiaItemRoot->Release();
    _pWiaItemRoot = NULL;
}

The reason my first try wasn't working was because of issues with the BSTR parameters I was passing in. Using CComBSTR or SysAllocString resolved that.

DCreeron
  • 86
  • 2