This is the first time I use COM and I'm learning ADO to port an application from ODBC to ADO

This is the code


LOCAL buffer[250] : BYTE
LOCAL ConnectionCLSID : CLSID
LOCAL ConnStringW[250] : WORD
LOCAL bstrConnString : DWORD

.data
ConnectionPid dw L(ADODB.Connection\0)
IID_Connection sIID__Connection
iConnection dd ?
ConnStringA db "Provider=Microsoft.Jet.OLEDB.4.0",3Bh,"Data Source=%s",3Bh,0

.code

invoke CLSIDFromProgID, addr ConnectionPid, addr ConnectionCLSID
.if eax == S_OK

invoke CoCreateInstance, addr ConnectionCLSID, NULL, CLSCTX_INPROC_SERVER, addr IID_Connection, addr iConnection
.if eax == S_OK

;Create the ConnectionString
invoke wsprintf, addr buffer, addr ConnStringA, addr FullDbPath
invoke MultiByteToWideChar, CP_ACP, 0, addr ConnStringA, -1, addr ConnStringW, 250
invoke SysAllocString, addr ConnStringW
mov bstrConnString, eax

invoke vf (iConnection, _Connection, Open), bstrConnString, NULL, NULL, -1
test eax, eax
.if FAILED
int 3
.endif

.else
invoke ReportError, 0
.endif
.else
invoke ReportError, 0
.endif

ret


Interfaces are taken from msado15.dll with COMView
_Connection.Open fails but I don't know where I'm wrong
Posted on 2003-06-25 09:13:23 by greenant
try to change


invoke wsprintf, addr buffer, addr ConnStringA, addr FullDbPath
invoke MultiByteToWideChar, CP_ACP, 0, addr ConnStringA, -1, addr ConnStringW, 250

to


invoke wsprintf, addr buffer, addr ConnStringA, addr FullDbPath
invoke MultiByteToWideChar, CP_ACP, 0, addr buffer, -1, addr ConnStringW, 250
Posted on 2003-06-25 11:28:13 by japheth
You are right.
Posted on 2003-06-25 11:45:28 by greenant