by mcow » Fri Jun 21, 2019 5:03 pm
Dave Plummer, I have been doing more intensive work with this lately, and created some C++ code for dealing with the COM objects. When you get an IDispatch object, you need to look up the "DISPID" for the method(s) you want to call and then invoke them. This works roughly like (no guarantees this will compile as written):
Code: Select all
// your code from the earlier post
ISDBDatabase *pSDBDatabase;
pSDB->get_Database(&pSDBDatabase);
BSTR qs = SysAllocString(L"Author='Berio, Adolfo'");
IDispatch *pIDisp;
pSDBDatabase->QuerySongs(qs, &pIDisp);
// what do do next
HRESULT hr;
// Repeat the following for each method or property, save the IDs
wchar_t cname[]=L"EOF";
DISPID id;
hr = pIDisp->GetIDsOfNames(IID_NULL, &cname, 1, LOCALE_USER_DEFAULT, &id);
// then, to retrieve this property value:
DISPPARAMS dp = { NULL, NULL, 0, 0 };
VARIANT result;
hr = pIDisp->Invoke(id, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET,
&dp, &result, NULL, NULL);
bool eof = result.boolVal;
Method calls use DISPATCH_METHOD instead of _PROPERTYGET, and passing parameters is done via the DISPPARAMS object. Setting properties can also be done but with additional DISPPARAMS setup.
I don't understand why that "working fragment" you posted before works for you, since the CoCreateInstance() method also returns an IDispatch. Anyway, if you're still interested in getting this to work, DM me and I'll share some generic C++ code I've written to create classes that wrap the IDispatch with maybe a little less pain.
Dave Plummer, I have been doing more intensive work with this lately, and created some C++ code for dealing with the COM objects. When you get an IDispatch object, you need to look up the "DISPID" for the method(s) you want to call and then invoke them. This works roughly like (no guarantees this will compile as written):
[code] // your code from the earlier post
ISDBDatabase *pSDBDatabase;
pSDB->get_Database(&pSDBDatabase);
BSTR qs = SysAllocString(L"Author='Berio, Adolfo'");
IDispatch *pIDisp;
pSDBDatabase->QuerySongs(qs, &pIDisp);
// what do do next
HRESULT hr;
// Repeat the following for each method or property, save the IDs
wchar_t cname[]=L"EOF";
DISPID id;
hr = pIDisp->GetIDsOfNames(IID_NULL, &cname, 1, LOCALE_USER_DEFAULT, &id);
// then, to retrieve this property value:
DISPPARAMS dp = { NULL, NULL, 0, 0 };
VARIANT result;
hr = pIDisp->Invoke(id, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET,
&dp, &result, NULL, NULL);
bool eof = result.boolVal;
[/code]
Method calls use DISPATCH_METHOD instead of _PROPERTYGET, and passing parameters is done via the DISPPARAMS object. Setting properties can also be done but with additional DISPPARAMS setup.
I don't understand why that "working fragment" you posted before works for you, since the CoCreateInstance() method also returns an IDispatch. Anyway, if you're still interested in getting this to work, DM me and I'll share some generic C++ code I've written to create classes that wrap the IDispatch with maybe a little less pain.