Page 1 of 1

Posted: Wed Nov 20, 2002 9:54 am
by BackupUser
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

Posted: Wed Nov 20, 2002 11:39 am
by BackupUser
Restored from previous forum. Originally posted by Danilo.

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)
cya,
...Danilo

(registered PureBasic user)

Posted: Wed Nov 20, 2002 12:12 pm
by BackupUser
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?

Posted: Wed Nov 20, 2002 12:40 pm
by BackupUser
Restored from previous forum. Originally posted by Kale.

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)
i have no idea why it still works? :)

--Kale

New to PureBasic and falling in Love! :)

Posted: Wed Nov 20, 2002 3:54 pm
by BackupUser
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

Posted: Wed Nov 20, 2002 6:38 pm
by BackupUser
Restored from previous forum. Originally posted by Kale.

ah! thanks Timo :)

--Kale

New to PureBasic and falling in Love! :)