DLL and Strings

BlitzMax Forums/BlitzMax Beginners Area/DLL and Strings

Ian Lett(Posted 2009) [#1]
Hello all,

i have a dll that returns a pointer to a string but i can seem to work out how to read the actual string its self. the coad is simple:


Global gethostname() "win32"
Global p:Int

dll = LoadlibraryA ("network.dll")
gethostname= getprocaddress(dll,"gethostname")
p=gethostname()
Print p

this returds a number in p but if i use:

Global p:Int ptr

i get compile error unable to convert int to int prt. at the line 'p=gethostname()'

any ideas on how i can reteve the string ?


Brucey(Posted 2009) [#2]
How about?
Global gethostname:byte ptr() "win32"

... String.FromCString(gethostname())




Ian Lett(Posted 2009) [#3]
thanks Brucey i understand the first line but how do i impliment the next bit, no matter what i do all i get is an complie error expecting expression but encounterd a malformed string literal.

sorry to be a bit slow and all.

ian


Azathoth(Posted 2009) [#4]
String.FromCString(gethostname()) returns a string.


Brucey(Posted 2009) [#5]
After much rummaging around MinGW... I came up with this :
Local dll = LoadLibraryW("wsock32.dll")

Global gethostname:Int(buf:Byte Ptr, i:Int) "win32" = getprocaddress(dll,"gethostname")
If gethostname Then
	Local buf:Byte[512]
	gethostname(buf, 512)
	Print String.FromCString(buf)
End If

Note that I am using a different dll for starters ;-)


SebHoll(Posted 2009) [#6]
I know it isn't quite as reliable, but it's very easy just to read the COMPUTERNAME environment variable (if it is this that you want):

Print getenv_("COMPUTERNAME")



Brucey(Posted 2009) [#7]
I know it isn't quite as reliable

Not very :-)


Ian Lett(Posted 2009) [#8]
A big thanks to all of you for your help, got it working at last.

Ian


Kistjes(Posted 2009) [#9]
I know it isn't quite as reliable

Why not?


Brucey(Posted 2009) [#10]
Because it is a value that can be changed on-the-fly.
It's harder to change the system host name.

Better to use system APIs for such things... but, the choice is there, I suppose :-)