External DLL calls

BlitzPlus Forums/BlitzPlus Programming/External DLL calls

rogue(Posted 2005) [#1]
I added a Kernel32.desc file in my userlibs sub-directory. It has the following in it:

.lib "Kernel32.dll"

GetVersionEx%(lpOSVersionInfo*):"GetVersionExA"
GetPrivateProfileString%(sectionName$,keyName$,default$,retStr$,bufSize%,fileName$):"GetPrivateProfileStringA"
WritePrivateProfileString%(sectionName$,keyName$,strValue$,fileName$):"WritePrivateProfileStringA"

The WritePrivateProfileString call works great. However, the GetPrivateProfileString call seems to be failing. I am calling it like this in B+:

Const kTileWidth = 64
Local tileWidth$

GetPrivateProfileString( "GameDefs", "TileWidth", Str( kTileWidth ), tileWidth$, 16, "Game.ini" )

This always returns ""

Why doesn't this work? I am guessing the 5th parameter size is screwing things up. It should be a DWORD and I am passing an integer. Not sure if they are the same size for B+.


aab(Posted 2005) [#2]
The Return Type in the Decls File is '%' there. if your wanting it to return a string, changing it to '$' might help.


rogue(Posted 2005) [#3]
Actually the Win32 function returns an INT not a string, hence the % in the return type decls file. The string value is set in the 4th parameter. That parameter is a string with enough space allocated to hold the return string.


gman(Posted 2005) [#4]
for B+, you can initialize the string you are passing in retStr$ by setting it to a certain # of spaces. so for your example, you can set tileWidth$=" " and then you should start getting back values. im not sure the ramifications of this though since in theory its not supposed to work. the proper way to do it is to use a bank for retStr$ instead of a string. you can see some working declarations at:

kernel32.dll decls for INI access

i will see if i can post the function i use for reading when i get home.

GMan


gman(Posted 2005) [#5]
i added my INI access functions at:

more INI funcs

hope they give you what you need.

GMan


rogue(Posted 2005) [#6]
Your Ini routines work great. Thanks!