Request: Can someone do a translation of those variables to dark basic pro? And can someone look over the dll doc i posted here under the code button?
What else do we need to add to this tutorial on making dll calls in dark basic pro?
If you see something that needs edited, please mention it. I have marked spots I think need edited with xxxedit .
I have also put some of your comments in there that seems important and of use.
Dll Call Translation Strategy
1. Find out what dll's you already have, by taking a look in your windows system folder and in windows xp, also look in windows system32 folder.
2. Since programs install dlls into the system or system32 folder, you will most likely increase the number of dlls you have by installing more programs. Dark basic also has its own plugin folder that dlls made for it can be installed to add commands to dark basic. See the documentation for this in dark basic pro help in the editor.
xxxedit this, by adding line that shows directions on how to get to that exact info.
3. Also look at the dark basic pro topic, dll, list of known dlls. This often gives web sites where you can buy a dll, or obtain a free download of it. Such dlls most likely contain a doc file on how to install the dll, and how to make the dark basic pro calls to the dll, and documents what the commands arid what they are. The sample dark basic pro calls to the dll, if a dll call is used, will help you understand the format of making the calls, and if its a dll that gets installed in dark basic pro's plugin folder, then the docs will most likely contain sample code that will help you learn how to make use of dll's as plugins to dark basic pro.
4. After you know the name of a dll, you can go search at www.msdn.com The Microsoft development web page, and if the dll is used by windows, most likely there will be sample code on how to call the dll, and what commands the dll contains. This code will often be in the c++ language,
Therefore it would be good for you to learn c++ variable types since your going to have to figure out a dark basic variable and or mem block plus variable type, or other structure to represent the variable and type in dark basic pro. Therefore, also start learning about mem blocks in your dark basic Manuel, and take a look at the sample and show case examples given by your help option in dark basic pro editor for mem blocks
5. Usually a tutorial exist for about any dll used by windows. That tutorial is probably in a language other than dbp. Even though the tutorial is not in dbp, it will most likely be helpful to read it. It is a good practice to go to a search site like www.google.com And search for the dll's tutorial. Just enter the name and the word tutorial in the search box, and also if you need to, do this with the commands can often pull up more tutorials Entering the dlls name then dark basic, then tutorial will often pull up what dark basic tutorials exist for the dll..
6. Dlls have commands, and if you know what the command name is, it is good practice to also do a search on that command, and see what more you can learn about it. Do this both at a web search site like google, and also at the MSDN site.
7. Try loading a dll into a text editor like word, and then scan through it for the readable text contained in it. This sometimes can give you clues on what an unknown dll might be for., and can lead to other terms to search for at search sites, and eventually lead you to the documentation and or tutorials for it.
8. table which helps you translate the C++ variable type declaration to its equivalent in Visual Basic, and Dark Basic Pro:
xxxxedit If dark basc pro is not the same as visual basic please add the dark basic translation to this table
ATOM ByVal variable as Integer
BOOL ByVal variable as Long
BYTE ByVal variable as Byte
CHAR ByVal variable as Byte
COLORREF ByVal variable as Long
DWORD ByVal variable as Long
HWND ByVal variable as Long
HDC ByVal variable as Long
HMENU ByVal variable as Long
INT ByVal variable as Long
UINT ByVal variable as Long
LONG ByVal variable as Long
LPARAM ByVal variable as Long
LPDWORD variable as Long
LPINT variable as Long
LPUINT variable as Long
LPRECT variable as Type any variable of that User Type
LPSTR ByVal variable as String
LPCSTR ByVal variable as String
LPVOID variable As Any use ByVal when passing a string
LPWORD variable as Integer
LPRESULT ByVal variable as Long
NULL ByVal Nothing or ByVal 0& or vbNullString
SHORT ByVal variable as Integer
VOID Sub Procecure not applicable
WORD ByVal variable as Integer
WPARAM ByVal variable as Long
empty
--------------------------------------------------------------------------------
User
Joined: Mon Aug 26th 2002
Location: 3 boats down from the candy Posted: 26th Apr 2005 19:59
--------------------------------------------------------------------------------
First of all this function is not in the Kernel32.dll but in Advapi32.dll.
LPSTR is a buffer that'll receive in null terminated string and LPDWORD is a pointer to a DWord (that's similar to an Integer (same size) but can only store positive value). In PlayBasic the code would look like this:
+ Code Snippet
LoadDll "advapi32.dll", 1
user$ = Make$(" ", 256)
CreateBank 1,4
pointer = GetBankPtr(1)
PokeBankInt 1, 0, 256
CallDll 1, "GetUserNameA", user$, pointer
size = PeekBankInt(1, 0)
Print Left$(user$, size-1)
Sync
WaitKey
9.IanM
--------------------------------------------------------------------------------
Moderator
Joined: Wed Sep 11th 2002
Location: In my moon base Posted: 26th Apr 2005 20:03
--------------------------------------------------------------------------------
?
Well, the code in DBPro is like this:
+ Code Snippet
` BOOL GetUserName(LPTSTR lpBuffer, LPDWORD nSize);
`
` BOOL is a 4 byte value that will contain either 0 (false) or 1 (true)
` LPTSTR is a pointer to a string - because it is a TSTR, then care has to be taken to get
` the correct (non-unicode) version
` LPDWORD is a pointer to a 4 bytes unsigned value
load dll "advapi32.dll", 1
` Allocate 4 bytes to use as a DWORD - the NameSize variable
` will effectively become a pointer to a dword.
NameSize = make memory(4)
` Set the size value to zero
*NameSize = 0
` Calling the routine for the first time.
` Passing a 'null' string value, and a size of zero will cause the routine
` to determine the size of string needed, putting the size in the NameSize
` memory location, and doing nothing else.
Result = call dll(1, "GetUserNameA", 0, NameSize)
` Now the NameSize has a value - create a string large enough to hold the name
` and call the routine again, this time with a valid string to put the result
` into.
Name$ = space$( *NameSize )
Result = call dll(1, "GetUserNameA", Name$, NameSize)
print Name$
print *NameSize
` Cleanup the DLL
delete memory NameSize
delete dll 1
wait key
IanM
--------------------------------------------------------------------------------
Moderator
Joined: Wed Sep 11th 2002
Location: In my moon base Posted: 29th Apr 2005 13:25
--------------------------------------------------------------------------------
Next thing is a C following a LP indicates a const pointer. LPCSTR indicates a pointer to a const string, one that can not or will not be modified. LPSTR on the other hand is not const and may be changed.
You might also see a T mixed in there. Don't worry about this for now, unless you are intentionally working with Unicode, it means nothing.
Quote: "You might also see a T mixed in there. Don't worry about this for now, unless you are intentionally working with Unicode, it means nothing"
It actually means quite a bit. If there is a T in one of your *STR types, then that means that there are two versions of the function. One with an A appended to the name for the ASCII version, and one with a W appended for the Unicode version (sometimes only one of these is available).
Calling these from DBPro, you will always want the one with the A on the end of the name.