how do I use my DLL in BMax?
BlitzMax Forums/BlitzMax Programming/how do I use my DLL in BMax?
| ||
Ok, I have searched the forums, and the best I could come up with still doesn't work. I know the DLL works because it works in my Blitz3D program. What am I doing wrong in BlitzMax? (I'm new to it) This works: ; Blitz3D Local sErr$ Local sConStr$ = "provider=Microsoft.Jet.OLEDB.4.0;data source=Data.mdb;Jet OLEDB:Database Password=;" sErr = GGDB_Connect(sConStr, "", "") If sErr <> "" Then RuntimeError(sErr) sErr = GGDB_RSOpen("SELECT Animation_ID,Animation FROM Animation ORDER BY Animation") If sErr <> "" Then RuntimeError(sErr) While Not GGDB_RSEOF() Print GGDB_RSValue("Animation_ID") + ", " + GGDB_RSValue("Animation") GGDB_RSMoveNext() Wend GGDB_Disconnect() WaitKey End This doesn't work: ' BlitzMax Global dll% = LoadLibraryA("GG_DB.dll") Global GGDB_Connect$(ConnStr$, UserID$, Password$) Global GGDB_Disconnect$() Global GGDB_Exec$(SQL$) Global GGDB_RSOpen$(SQL$) Global GGDB_RSClose$() Global GGDB_RSValue$(DBField$) Global GGDB_RSEOF%() Global GGDB_RSBOF%() Global GGDB_RSMoveNext%() Global GGDB_RSMovePrevious%() Global GGDB_RSMoveFirst%() Global GGDB_RSMoveLast%() Global GGDB_RSRecordCount%() GGDB_Connect = GetProcAddress(dll, "_GGDB_Connect@12") GGDB_Disconnect = GetProcAddress(dll, "_GGDB_Disconnect@0") GGDB_Exec = GetProcAddress(dll, "_GGDB_Exec@4") GGDB_RSOpen = GetProcAddress(dll, "_GGDB_RSOpen@4") GGDB_RSClose = GetProcAddress(dll, "_GGDB_RSClose@0") GGDB_RSValue = GetProcAddress(dll, "_GGDB_RSValue@4") GGDB_RSEOF = GetProcAddress(dll, "_GGDB_RSEOF@0") GGDB_RSBOF = GetProcAddress(dll, "_GGDB_RSBOF@0") GGDB_RSMoveNext = GetProcAddress(dll, "_GGDB_RSMoveNext@0") GGDB_RSMovePrevious = GetProcAddress(dll, "_GGDB_RSMovePrevious@0") GGDB_RSMoveFirst = GetProcAddress(dll, "_GGDB_RSMoveFirst@0") GGDB_RSMoveLast = GetProcAddress(dll, "_GGDB_RSMoveLast@0") GGDB_RSRecordCount = GetProcAddress(dll, "_GGDB_RSRecordCount@0") Local sErr$ Local sConStr$ = "provider=Microsoft.Jet.OLEDB.4.0;data source=Data.mdb;Jet OLEDB:Database Password=;" sErr = GGDB_Connect(sConStr, "", "") If sErr <> "" Then RuntimeError(sErr) sErr = GGDB_RSOpen("SELECT Animation_ID,Animation FROM Animation ORDER BY Animation") If sErr <> "" Then RuntimeError(sErr) While Not GGDB_RSEOF() Print GGDB_RSValue("Animation_ID") + ", " + GGDB_RSValue("Animation") GGDB_RSMoveNext() Wend GGDB_Disconnect() WaitKey End Here is the contents of the decls file for Blitz3D: .lib "GG_DB.dll" GGDB_Connect$(ConnStr$,UserID$,Password$):"_GGDB_Connect@12" GGDB_Disconnect$():"_GGDB_Disconnect@0" GGDB_Exec$(SQL$):"_GGDB_Exec@4" GGDB_RSOpen$(SQL$):"_GGDB_RSOpen@4" GGDB_RSClose$():"_GGDB_RSClose@0" GGDB_RSValue$(Field$):"_GGDB_RSValue@4" GGDB_RSEOF%():"_GGDB_RSEOF@0" GGDB_RSBOF%():"_GGDB_RSBOF@0" GGDB_RSMoveNext%():"_GGDB_RSMoveNext@0" GGDB_RSMovePrevious%():"_GGDB_RSMovePrevious@0" GGDB_RSMoveFirst%():"_GGDB_RSMoveFirst@0" GGDB_RSMoveLast%():"_GGDB_RSMoveLast@0" GGDB_RSRecordCount%():"_GGDB_RSRecordCount@0" You can download all of the files and try it yourself if you want: http://www.gilligames.com/DB_Test.rar (27 kb download) |
| ||
What are the errors you're getting? The strings may be W/C Strings.. |
| ||
The BMax program just flat out crashes, Windows style. The crash error window says "Microsoft Visual C++ Runtime Library" at the top, then "Runtime Error!" and "abnormal program termination". I should mention that the dll was written in C++ in a slightly older version of Visual Studio. I don't remember which version specifically. |
| ||
Nobody knows how to do this? |
| ||
Do you have the MS VCC runtime library in your program directory? |
| ||
I don't usually runtime-load DLLs, preferring to plug them in at link-time, so my way requires a .def and a .a for MinGW. (both of which can be generated from the dll). So I can't be of much help in this case. However, I *can* access your mdb file via ODBC in BlitzMax using my own module - not that that helps you here of course.... |
| ||
@Plash: No. I don't even know what files that would be, and I'm pretty sure it's installed in Windows and isn't required in a program directory. @Brucy: I don't know what any of that means. All I want to know is how to get the same functionality from a dll that I used to get in Blitz3D. I don't see any documentation on it, and only partial descriptions in the forums. I created the dll myself because I couldn't find one that fit my needs before, but if you have a module that I could use too, then it would solve my issue (for now). Does BlitzMax support ODBC natively? How did you write your module? |
| ||
This may not be relevant to the issue, but you should definitely free the library once you're done with it. No. I don't even know what files that would be, and I'm pretty sure it's installed in Windows and isn't required in a program directory. I would assume it to be one of the C++ redistributables. What programming language and what compiler was used to make the dll? |
| ||
Like I mentioned above, the dll was written in C++ in a slightly older version of Visual Studio. I don't remember which version specifically. But that shouldn't be the issue, since it works perfectly from Blitz3D. That's what I don't understand. It must be something about how to do it with BlitzMax. |
| ||
Do you still have the working version in Blitz3D? Check for dlls in or near the source/binary directory. The only thing I can think of is not having one of the redistributable's.. It might be worth a try to download a bunch of msvc redistributable's, starting from like msvc60 and going up (a Google search should get you what you're looking for). |
| ||
The only thing I can think of is not having one of the redistributable's.. He makes a point. Keep in mind that VC++ does not always create standalone EXEs/DLLs, they often depend on the VC++ runtimes. |
| ||
That's not the issue. It only depends on kernel32.dll, ole32.dll and oleaut32.dll - according to Dependency Walker. I'm guessing it's just a wrapper for accessing ODBC, given the value of sConStr, which is a typical DSN-type string. As for why it breaks when Connect is called, I can't help I'm afraid. Does BlitzMax support ODBC natively? No. But through my BaH.Database and BaH.DBODBC modules, it can. There's an Access test app included with the odbc module. The downloads page is here : http://code.google.com/p/maxmods/downloads/list But you'll need to be setup with MinGW to build it, etc... |
| ||
Brucey, Thanks, I'll check it out. Do you have any docs for your module? |
| ||
Brucey, I created a folder named BaH.mod, then put the dbodbc.mod folder inside that. Then I called: bmk makemods BaH.dbodbc but there was no response by the compiler so I don't know if it did anything. I loaded up the access_test.bmx program and tried to run it, but I get a compile error that it can't find the interface for module "bah.dbodbc". I have a feeling it didn't compile, but I don't know why. I do have mingw installed, and was able to compile a small test module of my own. |
| ||
A simple Build Modules should do what you need. |
| ||
Compiling a module is a good way to test things out, but unless the module has any C or C++ code in it, it won't require MinGW, so it doesn't necessarily mean that is correctly installed. Open a command prompt and Type : gcc If MinGW is installed correctly you should see a message something like: gcc: no input files. |
| ||
It's correctly installed. I did what you suggested and it returned what you said. |
| ||
Make sure all the folder names are lowercase to begin with. You will also need the bah.database module, which is the base for the specific database drivers. With both installed, things would look like this : ...BlitzMax/mod/bah.mod/database.mod ...BlitzMax/mod/bah.mod/dbodbc.mod , and in each of those folders are all the files, like for example, dodbc.bmx. On the commandline you can also do this : bmk makemods -a bah which will have it re-build all modules under the bah.mod folder. If you run that command and nothing appears to happen, then either : 1) MinGW isn't properly installed. 2) You have a path wrong. HTH |
| ||
in regards to original question I think your function pointers need the "C" calling convention for blitz3d style and string suffix needs to be changed such as: Global GGDB_Connect$z(ConnStr$z, UserID$z, Password$z) "C" |
| ||
Thanks Brucey for the additional tips. I did not download the database module yet, so that's part of the problem. Still, do you have docs on usage? Skidracer, thanks for that tip. I'll also try that with my own DLL, which I'd prefer to use since my Blitz3D code is already using it and that's what I'm converting. |