Blitz3D: links to DLL function lists.

Blitz3D Forums/Blitz3D Beginners Area/Blitz3D: links to DLL function lists.

Leafus(Posted 2013) [#1]
Heyawl,

Blitz3D has the CallDLL command and I can't figure out:

a) a good place to look for DLL filenames with a description of what they do. (without installing any programs I can't see source of to compile myself)

b) the functions within those DLL files once found, along with parameters and return values.

For myself, I am wanting to do what I am sure will prove to be a simple thing that will involve nothing more than a standard System32 DLL, but I have no knowledge of such things, nor much of languages outside of the Blitz range. I want to know the Application Folder of the calling program (ie. my blitz game). I know it is a simple command in BlitzMax, and when I went looking in the System topic of the Blitz3D inline 2D help page I figured the only way around it's absence would be to use the CallDLL function I saw in there. I would also appeciate a breakdown of DLL variable structures (ie bytes per float/int/string/pointers/any types I don't know about... how strings work... how pointers work... anything that would be helpful to do with DLLs really).

Anyway, I've waffled on for long enough. If nothing else I hope my thought that this would make a good resource topic for posting of external DLL related links etcetera may prove fruitful.

Also any help with my personal problem would be appreciated please.

Thanking yaz all for reading and in advance for any help offered.

-Leafus :oD


Yasha(Posted 2013) [#2]
The first thing is that the CallDLL command is more or less obsolete. It's been replaced by the rather superior "userlibs" system, which is handy because due to the limitations of CallDLL it can't actually do what you want anyway (it requires functions to have a different signature from the Windows API, so it definitively can't be used to call Windows system functions).

(CallDLL does have one use that userlibs can't achieve easily, which is that since it takes the function name as a string you can technically use it to dynamically select a function by name - 99% of the time, and in your use case, this isn't necessary or relevant.)


The "userlibs" system lets you make Blitz3D aware of your DLL and the functions it contains at compile-time. It can find and link to them internally and make the DLL functions usable like any other B3D command or user-defined function. As you can imagine this is much more useful than messing around with banks.

To set up a userlib, all you need is to create a .decls file with the name of the DLL and declarations for the functions you want it to export, and place this file in your Blitz3D/userlibs folder. When you restart the compiler (or, in IDEal, tell it to "refresh definitions"), it will be aware of the newly added functions and you can treat them as integrated commands. The DLL itself can be placed in your /userlibs folder, or in your project folder (the latter might be better, so you don't forget that the DLL has to go with the program when it's compiled and ready to distribute).

Windows system DLLs do not need to be copied (in fact, doing so is an incredibly bad idea and will ruin your system, plus redistributing them is illegal), because the third location the program knows how to search is the Windows System folder. Just trust that it will find any DLLs located there on its own (this includes kernel32, user32, OpenGL, etc.). Since you want a system function, this means that the DLL will be provided and you don't need to copy or move that file - you only need the .decls.

There are examples of .decls files in the code archives: http://www.blitzbasic.com/codearcs/codearcs.php?cat=14

In fact you'll find .decls there for the kernel32 and user32 libraries so those are probably what you want anyway - just copy them to your Blitz3D/userlibs folder and restart, and the functions will be available.

Documentation for Windows system functions can be found at MSDN: http://msdn.microsoft.com/en-us/library/windows/desktop/aa904962.aspx

The documentation for each function is good, but actually browsing MSDN is a nightmare (and they keep changing the layout!) - better to just stick the function name you want into Google and follow the MSDN result link. Once you get "into" the API docs there are plenty of crosslinks to narrow down your search.


Be warned that the Windows API is designed for people writing in C, which has a larger range of data types than Blitz3D, so not all Windows functions are usable directly. B3D only supports 32-bit integers ("DWORD" on MSDN), single-precision floats, char* (strings), and void* (which is specific to .decls functions and slightly complicated compared to B3D user-defined functions - don't be afraid to ask for help if this becomes relevant).


I actually have no idea how to do the specific thing you want to do, but I hope the above helps you find out.


jfk EO-11110(Posted 2013) [#3]
One thing that usually sucks is the lack of information about those windows constants, that are mentioned in all those help files. The easiest way to determine their values is: Get a copy of microsoft visual C, then copy all ,H files and all .CHM files (actually all header files and help files. The help files will explain each DLL, eg. there may be kernel32.chm for kernel32.dll) and the .h files contain the immediate values for even the most exotic, ungooglable constant. Then you can search the constant, using a search tool, but ironicly the system search is too stupid to find anything and claims that there ain't no matches, which is absolutely crappy, so I wrote myself a lil search tool that searches all .h files and lists the line(s) that contains the wanted constant. took me 10 minutes. I wonder what those highly paid guys at microsoft do all the time, or if they maybe wanna prevent us from finding things for some sick reason. But the real sad part is: android is even worse.


virtlands(Posted 2013) [#4]
Hi Leafus, The CallDLL function is rather obsolete.

I've listed some sample programs that use CallDll, in case you'd want. ::
-----------------------------------------------------------------------------
Title: Getting Drive Info with KERNEL32.DLL
created by author Klaas, in 2003, uses CallDLL (....) command.

source code: https://www.dropbox.com/s/9efaoqjhxf1jh0l/Getting%20Drive%20Info%20with%20KERNEL32.DLL_549.bb
-----------------------------------------------------------------------------
The old BlitzSys package uses CallDLL ::
; BLITZ SYS INCLUDE - V1.05
; ----
; Simple Win32 API Function Support! - Written by Rob Hutchinson & Joseph Cox 2001-2002

download link: http://uploadingit.com/file/oufitjhfvxgvj1tk/BlitzSys%20V1.05%20(complete).zip
-----------------------------------------------------------------------------
; Title: CPU Info
; Author: BlitzSupport
; Date: 2002-08-23 01:32:40

link: http://www.blitzbasic.com/codearcs/codearcs.php?code=403

code snippet::: size = CallDLL (dll$, "_FindCPUNameLength")
( It is missing its DLL. )
-----------------------------------------------------------------------------
The "userlibs" system lets you make Blitz3D aware of your DLL and the functions it contains at compile-time.

As Yasha said, 'userlibs' are superior. The only downside with 'userlibs'
is that if your program can't detect a customized DLL immediately at startup, it will crash.

If you're thinking of using techniques like packing DLLs into
your main program, so that your program is advanced enough to self-install, that won't work,
because the moment your program starts up and detects that a DLL is missing, it will crash,
(even if those DLLs are already packed inside).
Therefore, you'll need to create a special installer.
__ I learned that logic bug the hard way. __

{ THat was so funnny, it took me a couple of days to find that bug. }
-----------------------------------------------------------------------------
Said jfk EO-11110,
One thing that usually sucks is the lack of information about those windows constants

In many cases, various languages keep their constants a secret, or try to make it hard,

..because they DON'T WANT YOU TO KNOW what their constants are.

So, a clever tactic I learned is to force the programming language to "print" its own constants.

In a PureBasic example, I wanted to know the constant values of ::
#PB_Keyboard_Qwerty, #PB_Keyboard_International, #PB_Keyboard_AllowSystemKeys



I think that can work with Windows Constants too, I'm not sure.
Just print them to the screen, and you'll not need to search through .h files.


jfk EO-11110(Posted 2013) [#5]
I guess you're wrong about that. they are included in the dlls at compilation time and windows, even if it was smart, could know only those of the active dlls.


virtlands(Posted 2013) [#6]
I guess you're wrong about that. they are included in the dlls

Please clarify, wrong about which ? What's included in the dlls?


jfk EO-11110(Posted 2013) [#7]
the .h files are included in the dll sourcecode, like

INCLUDE "myconstants.bb"

, hence named header files. dlls are just some sort of compiled exes.


virtlands(Posted 2013) [#8]
...could know only those of the active dlls.
I see.


virtlands(Posted 2013) [#9]
I finally got this to work.

(I only started to learn Pelles-C a few days ago...I'm a noob, (or newbie?) .)

Here's a simple DLL created in Pelles C that works in Blitz3D:

-- Pelles-C source Code for SampleDLL --
https://www.dropbox.com/s/90tvvcnw3t1ttuf/SampleDLL.zip

The DLL function is named f1 ; all it does is add two numbers together.



The Blitz3D usage is simple: { 7 = f1(3,4) }



----------------------------------------------------
You'll need to create some DECLS information, as follows:

.lib "SampleDLL.dll"
f1%(a%,b%) : "_f1@8"

(You can name it SampleDLL.DECLS if you wish.)
----------------------------------------------------

If you want to download Pelles C, here is their link:
http://www.smorgasbordet.com/pellesc/

Pelles-C apparently makes it easy to create DLLs.
I used the New-Project-Win32 DLL Wizard menu; That's likely the best way to do it.

Some bonus points on Pelles C that I like:
(a) There are apparently no license restrictions on sharing/distributing DLLs created in Pelles C.
(b) Pelles C supports Assembly language.
------------------------------------------------------
I also have TinyC installed.
TinyC's assembly language syntax is something I'm not used to (called GNU assembler), so I won't touch that for now.


Leafus(Posted April) [#10]
Hi guys,

thanks for replying. I tend to be scatty and unfocused and I just came on here to download BlitzMax and was surprised to see I've left 7 or 9 posts at some points (most of which I am the thread creator of) and decided to investigate.

Don't worry there is nothing funny afoot here or expected elsewhere. I am just scatty. Just writing this to say thank yous.

I'm sorry to say I can't remember what I wanted it for. I'm not that clever and have had no success with programming ever and what's more I very rarely go anywhere near forums let alone post on them.

Thank you. :)

I hope at least that others may have benefitted from your contribution here.

I have benefitted from your kindness.

If anyone replies to this please expect none from me (certainly not for another inappropriate amount of time anyway). Thank you.

[edit 1/4hr later - further uselessy waffling] just the 3 threads infected, not so bad, 4 posts me replying on own thread. the other was a tantrum on blitz3dsdk owner headcount poll that this other thread of mine (a few years later!) addressed in a slightly (underlined) more composed fashion. But forums and I equals bad idea! Best wishes to you all (including Mark Sibley (sorry if misspelled) who did do his best to address the very problem I had, probably solved it, I guess others had that problem too). Like I say, I'm just not that clever nor should I be let loose on forums haha. Hopefully I'll remember that in the future. Where do I want to be 26 years from now Skidracer? Haha. Where is it that I am now exactly? I guess I don't know is the correct answer to both of those. ;op Good luck - Leafus <3 xx