B
BMermuys
Hi,
inline
Use a stringbuffer instead:
[DllImport("advapi32.dll", CharSet=CharSet.Auto)]
extern static int GetUserName (StringBuilder name, ref int sz);
static string GetUserName()
{
int sz = 0;
StringBuilder sbName = new StringBuilder(sz);
GetUserName ( sbName, ref sz ); // get size
sbName.Capacity = sz; // allocates space for the name
GetUserName ( sbName, ref sz ); // get name
return sbName.ToString();
}
Have a look at the static Environment.Username property. It does the same
as GetUserName().
hth,
greetings
inline
Philip Carnstam said:Hi,
This is driving me nuts... How do I call the advapi32 function GetUserName.
Syntax:
bool GetUserName(String User, ref int Sz);
Use a stringbuffer instead:
[DllImport("advapi32.dll", CharSet=CharSet.Auto)]
extern static int GetUserName (StringBuilder name, ref int sz);
static string GetUserName()
{
int sz = 0;
StringBuilder sbName = new StringBuilder(sz);
GetUserName ( sbName, ref sz ); // get size
sbName.Capacity = sz; // allocates space for the name
GetUserName ( sbName, ref sz ); // get name
return sbName.ToString();
}
Have a look at the static Environment.Username property. It does the same
as GetUserName().
hth,
greetings