Re: please verify
On Wed, 13 Oct 1999 21:59:50 +0100, Flaminio <newpow at TIN.IT> wrote:
>Please verify the code below and please execute it to see which errors
>are in it :
>
>include machine.e
>include dll.e
>atom kernel, SetEnvironmentVariable
>kernel = open_dll("kernel32.dll")
>SetEnvironmentVariable = define_c_func(kernel, "SetEnvironmentVariableA",
{C_POINTER, C_POINTER},C_INT)
>? c_func(SetEnvironmentVariable, {allocate_string("ciao"),allocate_string
("oiac")})
>
Flaminio,
There is nothing wrong with the code above but keep in mind that the
SetEnvironmentVariable function sets the value of an environment variable
for the current process. You will have to use the GetEnvironmentVariable
function to retrieve the value. Below I give an example with output:
include get.e
include machine.e
include dll.e
atom kernel, SetEnvironmentVar, GetEnvironmentVar, buffer, i
kernel = open_dll("kernel32.dll")
buffer = allocate(50)
SetEnvironmentVar = define_c_func(kernel, "SetEnvironmentVariableA",
{C_POINTER, C_POINTER}, C_INT)
GetEnvironmentVar = define_c_func(kernel, "GetEnvironmentVariableA",
{C_POINTER, C_POINTER, C_INT}, C_INT)
? c_func(SetEnvironmentVar, {allocate_string("bkb"),allocate_string
("brian")})
? c_func(GetEnvironmentVar, {allocate_string("bkb"), buffer, 50})
i = wait_key()
The above snippet produces:
1
5
The '1' means that SetEnvironmentVar was successful. The '5' means that
environment variable 'bkb' holds a string of length '5' (the length
of 'brian'). I would have to peek at the location 'buffer' to read that
environment variable. (A bit of a hassle...)
Is there a reason you need an environment variable for your process?
Couldn't you just use a global variable or something?
|
Not Categorized, Please Help
|
|