How can I use Windows-Path: %HOMEPATH% ??

 

Hi, I tried the google glass bowl and the 'local' search but none of them spoke to me.

How can I use windwos %HOMEPATH% - one of the windows-paths? (http://www.askvg.com/list-of-environment-variables-in-windows-xp-vista-and-7/)

Thanks in advance!

gooly

 
gooly:

Hi, I tried the google glass bowl and the 'local' search but none of them spoke to me.

How can I use windwos %HOMEPATH% - one of the windows-paths? (http://www.askvg.com/list-of-environment-variables-in-windows-xp-vista-and-7/)

Thanks in advance!

gooly


Not sure if you are on the correct forum, this is neither Google, nor Microsoft here.
 

I found it!

This works:

#import "kernel32.dll"
        bool ExpandEnvironmentStringsA(string lpSrc, string & lpDst[], string nSize);
        int GetEnvironmentVariableA(string lpName, string lpBuffer, string nSize);
#import

   string   g[1] = {""};
   GetEnvironmentVariableA("USERPROFILE", g[0], 1000);
   //ExpandEnvironmentStringsA("%HOMEPATH%",g, StringLen(g[0]));
   Print("USERPROFILE = >"+g[0]+"<");

But this causes mt4 to crash immediately - interesting way to stop everything immediately:

#import "kernel32.dll"
        bool ExpandEnvironmentStringsA(string lpSrc, string & lpDst[], string nSize);
        int GetEnvironmentVariableA(string lpName, string lpBuffer, string nSize);
#import

   string   g[1] = {""};
   //GetEnvironmentVariableA("USERPROFILE", g[0], 1000);
   ExpandEnvironmentStringsA("USERPROFILE",g, StringLen(g[0]));
   Print("USERPROFILE = >"+g[0]+"<");


%HOMEPATH% does not return this path: C:\Users\{username}

but only \Users\{username}

gooly

 
gooly: This works:
   string   g[1] = {""};
   GetEnvironmentVariableA("USERPROFILE", g[0], 1000);
I doubt it. 1) You have to pass the array not an element g[0], 2) The buffer is zero length but you tell GEVA it's 1000, so you are over-writing other memory. Try:
string g[] = {"12345678 1 2345678 2 2345678 3 2345678 4 2345678 5 2345678 ​6 2345678 ​7 2345678 ​8 2345678 ​9 23456789"};​
int len = GetEnvironmentVariableA("USERPROFILE", g, StringLen(g[0]);
string envVar = StringSubstr(g[0], 0, len);
Print("USERPROFILE = >"+envVar+"<");
GetEnvironmentVariable function (Windows)
 

hmm - your (partly) right ;)

if I do this (in a script) (no matter whether I define g[] = {..} or g[1] = {..}:

        string g[1] = {"12345678 1 2345678 2 2345678 3 2345678 4 2345678 5 2345678 ​6 2345678 ​7 2345678 ​8 2345678 ​9 23456789"};
        GetEnvironmentVariableA("USERPROFILE", g, StringLen(g[0]));
I get this compiler-errors:
',' - left square parenthesis expected for array        C:\Users\..\experts\scripts\testScript.mq4 (22, 41)
',' - parameter expected        C:\Users\..\experts\scripts\testScript.mq4 (22, 41)


If I do this:

        string g[1] = {"12345678 1 2345678 2 2345678 3 2345678 4 2345678 5 2345678 ​6 2345678 ​7 2345678 ​8 2345678 ​9 23456789"};
        GetEnvironmentVariableA("USERPROFILE", g[], StringLen(g[0]));
I get this compiler errors:
']' - wrong dimension   C:\Users\..\experts\scripts\testScript.mq4 (22, 42)
',' - parameter expected        C:\Users\..\experts\scripts\testScript.mq4 (22, 43)

Only this compiles without an error:

        string g[1] = {"12345678 1 2345678 2 2345678 3 2345678 4 2345678 5 2345678 ​6 2345678 ​7 2345678 ​8 2345678 ​9 23456789"};
        GetEnvironmentVariableA("USERPROFILE", g[0], StringLen(g[0]));

I know it against the 'rules' but... ?

Gooly

 
 int GetEnvironmentVariableA(string lpName, string lpBuffer, string nSize);
string lpBuffer not string& lpBuffer. Try dropping the array:
string g="12345678 1 2345678 2 2345678 3 2345678 4 2345678 5 2345678 ​6 2345678 ​7 2345678 ​8 2345678 ​9 23456789"};
int len = GetEnvironmentVariableA( "USERPROFILE", g, StringLen(g) );
 

ok this is working - thanks!:

        string g = "12345678 1 2345678 2 2345678 3 2345678 4 2345678 5 2345678 ?6 2345678 ?7 2345678 ?8 2345678 ?9 23456789";
        GetEnvironmentVariableA("USERPROFILE", g, StringLen(g));

gooly

Reason: