I have a new instrument that I am trying to operate via a computer. I am programming the computer under DOS, using Assembly and Forth. The instrument comes with a software development kit build around a DLL.
How can I use their DLL?
What’s the basic structure of these things, and how do I communicate with one when I am not running Windows? How do I pass arguments back and forth? How do I call specific functions in the DLL?
BTW I have barely scratched the surface in Windows programming and hope that this is not the reason to dive into it. But I have plenty of documentation explaining how to use the DLL from within a Windows program, both from the point of view of Windows programming with DLLs in general, and from the point of view of using all the features within this particular DLL. I only want to know the methods of doing so without Windows.
I might be talking out of my ass here, but aren’t DLLs generally loaded with windows API calls and only runnable in a 32 bit enviroment? In that case, using it under DOS will probably not be possible.
I’m guessing the OP means he’s writing a console app that will run under 32 bit Windows (which means all versions since Windows 95, not including the latest 64 bit versions). A console app is just an application without a graphical UI (GUI) - its input and output are all text. Think of the DOS command “DIR” to display files in a directory. A lot of people think of a console app (wrongly) as a DOS app.
That being the case, even though it’s a console app you still have the Win32 API at your disposition. (From memory) You need to call LoadLibrary() - passing in the filename of the DLL you’re using. You can then locate the function(s) you want to call with GetProcAddress(). Don’t forget to call FreeLibrary() when you’re done. You will have to figure out how to handle linkage and calling conventions in your programming environment of choice (Forth/Assembler) Look up “Pascal calling convention” on Google/MSDN and ’ extern “C” ’ - the latter is how you access DLLs from C++ which might give you some clues. You’ll need to make sure you put the parameters on the stack in the right order for the DLL you’re calling (this is what the calling convention is about) and that you clean up the stack in your code (if required, depending on the calling convention). To actually call the function, what you will be doing in effect is pushing the parameters on the stack and branching to the address you retrieved with “GetProcAddress”, then maybe cleaning up the stack on return.
I’m not using Windows, only DOS. But I am using a DOS extender to program with the 32 bit environment. After a little further research I am guessing maybe I need to link the DLL into the extender by building a new version, but that I don’t have all the tools to do that - but my documentation is just talking about mixed-language programming in general, and makes no mention of DLLs per se.
I’m all about using stacks, that part’s no problem. Don’t think I know how to load the DLL and get its address, though maybe I can figure that out. But I definitely don’t know how to tell it which of its dozens of functions I want to call.
In that case, “You have enountered a problem that this troubleshooter cannot solve.”
Other options:
-Search Google groups - “Advanced search”, try different search terms like “DOS extender DLL”, limit groups searched to forth
-post your question to comp.lang.forth - someone will know the answer.
Your DOS extender may be able to convert the DLL so you can use it, but don’t count on it working. Even if you can load the DLL and call the function you need, that function might make calls to the Windows API that just don’t have an equivalent under DOS.
You might try using the DOS extender WDOSX, which is designed to convert Windows console apps to DOS, and has some stubs to replace the Windows kernel DLLs.