Ok, I want to describe one way to use a COM library (ADO in this example).
This way uses midl.exe, so the PSDK has to be installed.
1. create an empty directory, say 'test'
2. in the directory 'test' invoke 'midl msado15.idl'
3. copy the files 'msado15_i.c' and 'msado15.h' to your project
4. browse the header file for the available interfaces and use that
modifyed example from timovjl:
#define UNICODE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <wchar.h>
#include <ole2.h>
#include <stdio.h>
#include "msado15.h"
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "ole32.lib")
#pragma comment(lib, "oleaut32.lib")
WCHAR *szAppName = L"MSADOTest";
int main(int argc, char **argv)
{
HRESULT hr;
//_Connection *pConn = NULL;
Connection15 *pConn = NULL;
hr = CoInitialize(NULL);
//hr = CoCreateInstance(&CLSID_Connection, NULL, CLSCTX_ALL, &IID__Connection, (void **)&pConn);
hr = CoCreateInstance(&CLSID_Connection, NULL, CLSCTX_ALL, &IID_Connection15, (void **)&pConn);
if (hr)
MessageBox(0, L"Error CoGetClassObject()", szAppName, 0);
else
{
// STDMETHOD(Open)(THIS,BSTR,BSTR,BSTR,LONG);
//hr = pConn->lpVtbl->Open(pConn, NULL, NULL, NULL, -1);
//hr = pConn->lpVtbl->Open(pConn, L"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb;", NULL, NULL, -1);
hr = pConn->lpVtbl->Open(pConn, L"Driver={Microsoft Access Driver (*.mdb)};Dbq=test.mdb;", NULL, NULL, -1);
if (!hr)
{
LONG nState;
pConn->lpVtbl->get_State(pConn, &nState);
pConn->lpVtbl->Close(pConn);
wprintf(L"nState = %d\n", nState);
}
else wprintf(L"Error in Open() : %Xh\n", hr);
pConn->lpVtbl->Release(pConn);
pConn = NULL;
}
CoUninitialize();
return 0;
}
You have to create an empty database 'test.mdb' to use the example.
As you can see: you have not to deal with UUIDs and you have not to define INITGUID nor to include <guiddef.h>.
That's all handeled by 'msado15_i.c'.
In the above example both interfaces '_Connection' and 'Connection15' are working. I don't know the difference.
There are also two different connection strings which also both are working.
The header file 'msado15.h' is to big for the ide.
It would be nice, if some people could try these steps and report.
czerny