C++ ADO OpenSchema

// lpcn->OpenSchema returns adErrInvalidArgument
//
// I need to be able to to this, I don't want to import msado15.dll
// because i don't want exceptions thrown.
//
// I've been researching this for 2 DAYS.  How do I make it work?

ADORecordset* ADOListTables(ADOConnection* lpcn){
    HRESULT hr = S_OK;
    ADORecordset* lprs = 0;

    VARIANT vtempty = {VT_EMPTY};
    hr = lpcn->OpenSchema(adSchemaTables,vtempty,vtempty,&lprs);

    // hr is adErrInvalidArgument and lprs is NULL.

    return lprs;
};
madhtrrAsked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
Hm, from the docs (http://msdn2.microsoft.com/en-us/library/ms221627.aspx - "VARIANT and VARIANTARG "):

VT_EMPTY

No value was specified. If an optional argument to an Automation method is left blank, do not pass a VARIANT of type VT_EMPTY. Instead, pass a VARIANT of type VT_ERROR with a value of DISP_E_PARAMNOTFOUND.

Have you tried

ADORecordset* ADOListTables(ADOConnection* lpcn){
    HRESULT hr = S_OK;
    ADORecordset* lprs = 0;

    VARIANT vtempty;
    vtempty.vt = VT_ERROR;
    vtempty.scode = DISP_E_PARAMNOTFOUND;

    hr = lpcn->OpenSchema(adSchemaTables,vtempty,vtempty,&lprs);

    return lprs;
};

?
0
 
jkrCommented:
See http://support.microsoft.com/kb/182831 ("HOWTO: Using the ADO OpenSchema Method from Visual C++") for an example on how to use that method. You will find more at http://msdn2.microsoft.com/en-us/library/ms676557.aspx ("OpenSchema Method Example (VC++) ")
0
 
madhtrrAuthor Commented:
Hi jkr!  hope your doin good:)

I saw both of those in my travels.  they both import msado15.dll, use a com wrapper, and reqiure a try catch blocks to catch 'exceptions'.  I am using the method from the raw ADOConnection pointer:

HRESULT OpenSchema(long, VARIANT ,VARIANT ,ADORecordset**)

not

_RecordsetPtr OpenSchema(long, /*optional*/ VARIANT, /*optional*/ VARIANT)

 like in the examples.  I made those work by just leaving out the optionals. I cannot do that without the wrappers in msado15.dll

There are 3 ways to do it, I am using the one that reqires the most coding but gives the most control instead of the ADODB wrappers ...

0
 
madhtrrAuthor Commented:
you ROCK.

Not only did you solve the problem, you have taught me that I need read the documentation THOROUGHLY, even if it is not exactly the same as what I am doing ATM:)
0
All Courses

From novice to tech pro — start learning today.