Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Even though this question was put ages ago, I want to answer it. I struggled much through the day with this, but got it done eventually.</p> <p>Code 0x800a03ec is ambiguous, it means essentially, (NO OFFENSE MEANT!), you dumbhead! you did something pretty stupid, try finding it out for yourself. Close to the old "syntax error" without further elucidation.</p> <p>So, there is no single meaning for code 0x800a03ec and, googling around, you can see it occurs when using zero based addressing in ranges, and many other gotcha situations.</p> <p>The gotcha in this case is that you have to pass the parameters to a DISPATCH_METHOD call <strong>IN REVERSE</strong>. Obviously, with a single parameter this will not lead to trouble, and many dispatch calls can do with a single parameter.</p> <p>So, when I want to open a workbook with just the filename, everything is OK.</p> <pre><code>AutoWrap(DISPATCH_METHOD, &amp;Result, pExcelWorkbooks, "Open", 1, fn); </code></pre> <p>But e.g. the following code does not work:</p> <pre><code>_variant_t fn("MyExcelBook.xlsx"), updatelinks(0), readonly(true); VARIANT Result; hr = Autowrap(DISPATCH_METHOD, &amp;Result, pExcelWorkbooks, "Open", 3, fn, updatelinks, readonly); </code></pre> <p>It produces 0x800a03ec and won't load the workbook.</p> <p>To amend this without rewriting all your calls, the AutoWrap function should be extended as follows:</p> <pre><code>// Allocate memory for arguments.. VARIANT * pArgs = new VARIANT[cArgs + 1]; // Extract arguments.. if (autoType &amp; DISPATCH_METHOD) { // reverse (variable) DISPATCH parameters after cArgs for (int i = 1; i &lt;= cArgs; i++) pArgs[cArgs-i] = va_arg(marker, VARIANT); } else { for (int i = 0; i &lt; cArgs; i++) pArgs[i] = va_arg(marker, VARIANT); } </code></pre> <p>(only relevant part shown, see earlier post for the whole method).</p> <p>So now I call the C++ version of workbooks.open()</p> <pre><code>_variant_t fn("MyExcelBook.xlsx"), updatelinks(0), readonly(true), optional(DISP_E_PARAMNOTFOUND, VT_ERROR); VARIANT Result; readonly, hr = Autowrap(DISPATCH_METHOD, &amp;Result, pExcelWorkbooks, "Open", 7, fn, updatelinks, optional, optional, optional, readonly); // copy the dispatch pointer to the workbook pointer if (Result.vt == VT_DISPATCH) { pExcelWorkbook = Result.pdispVal; // save the workbook pointer to close it later if needed if (pExcelWorkbook) IDworkBooks.push_back(pExcelWorkbook); } </code></pre> <p>As you can see, you do not have to fill in the tail options you are not going to use anyway, as in some VB code and C#.</p> <p>Happy coding, Jan</p> <p>PS, I see the reverse thing was noted before (see above).. I couldn't figure out where I had seen it until now...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload