I have for a longer while struggled with the attempt to create an empty access database. I can easily do it with a small VB exe (attacht). I have also found a C++ doing the same thing (also attacht). I am no VC++ coder so I have not succeeded to analyse the code to translate it to MASM. I have read Ernest Murphy articals but understand almost nothing. I have come so far
invoke CoInitialize,NULL 

.if eax==S_OK

invoke CoUninitialize

I don't even know if this is the correct beginning. Is there someoneon the board who happens to have a masm code that createx an access database or something that could be of help in my efforts.

One solution can be to run the VB exe from my asm code, but rather not.

Posted on 2003-12-04 12:32:15 by minor28
I have another solution. I create an access file with the VB exe and include the file in my asm code as a RCDATA resource.
invoke CreateFile,SADD('Risk.mdb'),\

mov hFile,eax
invoke FindResource,hInstance,IDR_ACCESS,RT_RCDATA
mov hRCDATA,eax
invoke SizeofResource,hInstance,hRCDATA
mov dwSize,eax
invoke LoadResource,hInstance,hRCDATA
invoke WriteFile,hFile,eax,dwSize,addr dwSizeWritten,0
invoke CloseHandle,hFile

whoops I have an empty mdb file.

But I am still interested on my first question.

Posted on 2003-12-04 13:37:42 by minor28
I have simplyfied the VC++ code to following code
#import "c:\winnt\system32\msadox.dll" 

void main()

_CatalogPtr m_pCatalog = NULL;

m_pCatalog.CreateInstance(__uuidof (Catalog));

m_pCatalog->Create("Provider=Microsoft.JET.OLEDB.4.0;Data source = RiskDB.mdb");


The line #import produces two files "msadox.tlh" and "msadox.tli" when compiling.

The Main first line and last line I can code in masm. The remaining three is mystery. Can someone give me a hint?

Posted on 2003-12-05 06:52:04 by minor28
you create a Catalog COM object and use it's Create method to make the database

so what you'd need would be the ADOX.Catalog (and maybe some others, been a long time since I looked at ADOX) COM object layout so that you can create an instance of it and call on its virtual table.

I think Japhet had a nice example of how to do regular ADO with vpointer calling in ASM, you could take a look at it so you see how it works. In very simple terms you'd need to do the same thing but on a different 'object' so you'll need to translate the object's "layout" to an assembler compatible format.

Posted on 2003-12-05 07:00:32 by Hiroshimator
hi minor28,

I would suggest to generate the ado includes with comview (download from my site).

THere is a ADO sample as well, it modifies an existing database only, but it shouldnt be too hard to implement the db creation code.

Posted on 2003-12-05 12:34:27 by japheth
Humm, is there a way to do this with regular ODBC, or is ADO required?
Posted on 2003-12-05 12:40:51 by f0dder
Posted on 2003-12-05 13:52:37 by Hiroshimator
Yes, I tryed it.
invoke SQLConfigDataSource,0,ODBC_ADD_DSN,SADD("Microsoft Access Driver (*.mdb)"),\

SADD("CREATE_DB=.\\risk.mdb General\0")

returns false.

Posted on 2003-12-05 15:53:41 by minor28
Does SADD parse C-style strings?
Try passing
"CREATE_DB=.\risk.mdb General"
instead, and see if it works.
Posted on 2003-12-05 15:58:14 by f0dder

LOCAL local_text
local_text db quoted_text,0
EXITM <ADDR local_text>

"CREATE_DB=.\risk.mdb General\0" returns false
Posted on 2003-12-05 16:07:45 by minor28
you still shouldn't include \0, it's C-string lingo for "put a 0 byte here" - if the 0 is required, either figure out how to insert it with SADD, or put the string in the .data section.
Posted on 2003-12-05 16:10:08 by f0dder
"CREATE_DB=.\risk.mdb General" returns true. Now an empty working mdb file was created.

I had to change the "ODBCCP32.LIB" version a couple of times before the code compiled faultless.

Thanks for the help all of you
Posted on 2003-12-05 16:13:48 by minor28
Glad to have been of assistance, hope you have fun with ODBC :)
Posted on 2003-12-05 16:16:24 by f0dder
To whom it may concern.


.model flat,stdcall
option casemap:none

include windows.inc
include user32.inc
include kernel32.inc
include ODBCCP32.inc

includelib user32.lib
includelib kernel32.lib
includelib ODBCCP32.LIB

szDriver db "Microsoft Access Driver (*.mdb)",0
szAttributes db "CREATE_DB=.\DataBase.mdb General",0

invoke SQLConfigDataSource,0,ODBC_ADD_DSN,addr szDriver,addr szAttributes
invoke ExitProcess,0

end start

Posted on 2003-12-05 16:26:33 by minor28