DispatchID Failed...
-
#include <windows.h>
#include <stdio.h>void PlayWithAccess(IUnknown *p);
void CallOpenDatabase(IDispatch *d);
int main(int argc, char* argv[])
{HRESULT hRet;
CLSID clsid;
IUnknown *p=NULL;
hRet=CoInitialize(NULL);if(FAILED(hRet)) {
printf("It Failed...\n");
return 1;
}
hRet=CLSIDFromProgID(L"Access.Application",&clsid);if(FAILED(hRet)){
printf("CLSID Illegal...\n");
CoUninitialize();
return 1;
}hRet=CoCreateInstance(&clsid, NULL, CLSCTX_ALL, &IID_IUnknown, (IUnknown **)&p);
if(FAILED(hRet)) {
printf("Create Failed....");
CoUninitialize();
return 2;
}
PlayWithAccess(p); //////// Play with Access Application Com Object
p->lpVtbl->Release(p);
CoUninitialize();
return 0;
}
void PlayWithAccess(IUnknown *p)
{
char buf[100];
IDispatch *d=NULL;
HRESULT hret;
hret=p->lpVtbl->QueryInterface(p,&IID_IDispatch,(void **)&d);
if(FAILED(hret)){
printf("DispatchID Failed...\n");
sprintf(buf,"DispatchID failed w/err 0x%08lx", hret);
MessageBox(NULL, buf, "DispatchID", 0x10010);
return;
}printf("Got the IDispatch Interface from Object...\\n"); CallOpenDatabase(d); printf("Enter Return:"); gets(buf); d->lpVtbl->Release(d);// Release Reference }
void CallOpenDatabase(IDispatch *d) // Call Open database through IDispatch Interface
{ // Late IDispatch Binding....
VARIANTARG args[2];BSTR DBLocation=SysAllocString(L"D:/project/C/c\_ado/connDB02/Example.mdb"); OLECHAR \*MethodName=L"OpenCurrentDatabase"; // Got The Method Name from Type Library DISPID dispid=0; HRESULT hret; DISPPARAMS params; DISPID ids\[2\]={1,0}; hret=d->lpVtbl->GetIDsOfNames(d,&IID\_NULL,&MethodName,1,LOCALE\_USER\_DEFAULT,&dispid); printf("Got a Dispatch Identifier....%x\\n",dispid); memset(args,0,sizeof(args)); // Build Up arguments args\[0\].vt=VT\_BOOL; // Last Argument is Optional args\[0\].boolVal=FALSE; args\[1\].vt=VT\_BSTR; // First argument is DB Location args\[1\].bstrVal=DBLocation; memset(¶ms,0,sizeof(params)); params.cArgs=2; params.rgvarg=args; hret=d->lpVtbl->Invoke(d,dispid,&IID\_NULL,LOCALE\_USER\_DEFAULT,DISPATCH\_METHOD,¶ms,NULL,NULL,NULL); if(FAILED(hret)) { printf("Invoke Failed....\\n"); } SysFreeString(DBLocation); }
How to do?thanks!
-
#include <windows.h>
#include <stdio.h>void PlayWithAccess(IUnknown *p);
void CallOpenDatabase(IDispatch *d);
int main(int argc, char* argv[])
{HRESULT hRet;
CLSID clsid;
IUnknown *p=NULL;
hRet=CoInitialize(NULL);if(FAILED(hRet)) {
printf("It Failed...\n");
return 1;
}
hRet=CLSIDFromProgID(L"Access.Application",&clsid);if(FAILED(hRet)){
printf("CLSID Illegal...\n");
CoUninitialize();
return 1;
}hRet=CoCreateInstance(&clsid, NULL, CLSCTX_ALL, &IID_IUnknown, (IUnknown **)&p);
if(FAILED(hRet)) {
printf("Create Failed....");
CoUninitialize();
return 2;
}
PlayWithAccess(p); //////// Play with Access Application Com Object
p->lpVtbl->Release(p);
CoUninitialize();
return 0;
}
void PlayWithAccess(IUnknown *p)
{
char buf[100];
IDispatch *d=NULL;
HRESULT hret;
hret=p->lpVtbl->QueryInterface(p,&IID_IDispatch,(void **)&d);
if(FAILED(hret)){
printf("DispatchID Failed...\n");
sprintf(buf,"DispatchID failed w/err 0x%08lx", hret);
MessageBox(NULL, buf, "DispatchID", 0x10010);
return;
}printf("Got the IDispatch Interface from Object...\\n"); CallOpenDatabase(d); printf("Enter Return:"); gets(buf); d->lpVtbl->Release(d);// Release Reference }
void CallOpenDatabase(IDispatch *d) // Call Open database through IDispatch Interface
{ // Late IDispatch Binding....
VARIANTARG args[2];BSTR DBLocation=SysAllocString(L"D:/project/C/c\_ado/connDB02/Example.mdb"); OLECHAR \*MethodName=L"OpenCurrentDatabase"; // Got The Method Name from Type Library DISPID dispid=0; HRESULT hret; DISPPARAMS params; DISPID ids\[2\]={1,0}; hret=d->lpVtbl->GetIDsOfNames(d,&IID\_NULL,&MethodName,1,LOCALE\_USER\_DEFAULT,&dispid); printf("Got a Dispatch Identifier....%x\\n",dispid); memset(args,0,sizeof(args)); // Build Up arguments args\[0\].vt=VT\_BOOL; // Last Argument is Optional args\[0\].boolVal=FALSE; args\[1\].vt=VT\_BSTR; // First argument is DB Location args\[1\].bstrVal=DBLocation; memset(¶ms,0,sizeof(params)); params.cArgs=2; params.rgvarg=args; hret=d->lpVtbl->Invoke(d,dispid,&IID\_NULL,LOCALE\_USER\_DEFAULT,DISPATCH\_METHOD,¶ms,NULL,NULL,NULL); if(FAILED(hret)) { printf("Invoke Failed....\\n"); } SysFreeString(DBLocation); }
How to do?thanks!
Couple of observations here what's the problem? what error code are you getting? what sort of help do you require? It's extremely unlikely anyone's going to copy your code, compile it and come back with the answer - sorry A general suggestion, don't use Dispatch interfaces, they are the most unwieldy method of calling com objects, use the 'real' interface Another one, if you have access to ATL, use CComPtr's to help wrap the pointers, and use OLE DB Client Templates to talk with Access
-
Couple of observations here what's the problem? what error code are you getting? what sort of help do you require? It's extremely unlikely anyone's going to copy your code, compile it and come back with the answer - sorry A general suggestion, don't use Dispatch interfaces, they are the most unwieldy method of calling com objects, use the 'real' interface Another one, if you have access to ATL, use CComPtr's to help wrap the pointers, and use OLE DB Client Templates to talk with Access