DLL and Strings
BlitzMax Forums/BlitzMax Beginners Area/DLL and Strings| 
 | ||
| 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 ? | 
| 
 | ||
| How about? Global gethostname:byte ptr() "win32" ... String.FromCString(gethostname()) | 
| 
 | ||
| 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 | 
| 
 | ||
| String.FromCString(gethostname()) returns a string. | 
| 
 | ||
| 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 ;-) | 
| 
 | ||
| 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") | 
| 
 | ||
|  I know it isn't quite as reliable  Not very :-) | 
| 
 | ||
| A big thanks to all of you for your help, got it working at last. Ian | 
| 
 | ||
|  I know it isn't quite as reliable   Why not? | 
| 
 | ||
| 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 :-) |