Restored from previous forum. Originally posted by Tecor400.
I All,
I am newbie in this forun, and I have a question:
How I can get the value from a Environment Variable? (like "PATH" or "TEMP"?
Best Regards
Joaquin
How to Get Environment Variable
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Danilo.
cya,
...Danilo
(registered PureBasic user)
Code: Select all
TEMP$ = Space(1000)
GetEnvironmentVariable_("TEMP",TEMP$,1000)
PATH$ = Space(1000)
GetEnvironmentVariable_("PATH",PATH$,1000)
MessageRequester("INFO","TEMP: "+TEMP$+Chr(13)+"PATH: "+PATH$,0)
...Danilo
(registered PureBasic user)
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by TheBeck.
I was trying to figure this out too but wasn't fast enough.
Danilo, your reply to this question raises another question for me. According to WIN32.HLP the second argument for GetEnvironmentVariable is supposed to be the address to the buffer. I solved this by using @Buffer$ to send the address of the Buffer$ variable, not the variable contents. However your example code works fine. So I have concluded that PureBasic must just send your variable address and not the actual contents of it when calling an external dll. Is my conclusion correct? Also your first argument is supposed to be an address, does PureBasic pass the address to where text is stored?
I was trying to figure this out too but wasn't fast enough.
Danilo, your reply to this question raises another question for me. According to WIN32.HLP the second argument for GetEnvironmentVariable is supposed to be the address to the buffer. I solved this by using @Buffer$ to send the address of the Buffer$ variable, not the variable contents. However your example code works fine. So I have concluded that PureBasic must just send your variable address and not the actual contents of it when calling an external dll. Is my conclusion correct? Also your first argument is supposed to be an address, does PureBasic pass the address to where text is stored?
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Kale.
Yeah your right TheBeck! that should read:
i have no idea why it still works? 
--Kale
New to PureBasic and falling in Love!
Yeah your right TheBeck! that should read:
Code: Select all
TEMP$ = Space(1000)
GetEnvironmentVariable_("TEMP",@TEMP$,1000)
PATH$ = Space(1000)
GetEnvironmentVariable_("PATH",@PATH$,1000)
MessageRequester("INFO","TEMP: "+TEMP$+Chr(13)+"PATH: "+PATH$,0)
--Kale
New to PureBasic and falling in Love!
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by freak.
OK, I'll clear that up... (we had this discussion before)
Usually you need the @, if it says pointer, but Strings are handled internally as Pointers to where the string is actually stored.
(Like in Structures, a String Member has 4 Bytes, => it's a Pointer to the String)
So when it comes to API, you can use just the String (but only with strings!!), and
Purebasic will pass the Pointer.
But I still add the @, just to make it more readable.
Hope this helps...
Timo
OK, I'll clear that up... (we had this discussion before)
Usually you need the @, if it says pointer, but Strings are handled internally as Pointers to where the string is actually stored.
(Like in Structures, a String Member has 4 Bytes, => it's a Pointer to the String)
So when it comes to API, you can use just the String (but only with strings!!), and
Purebasic will pass the Pointer.
But I still add the @, just to make it more readable.
Hope this helps...
Timo
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm