Regarding GetDefaultUserProfileDirectory

  • Thread starter Thread starter Visual Systems AB \(Martin Arvidsson\)
  • Start date Start date
V

Visual Systems AB \(Martin Arvidsson\)

Hi!

In c# I use [DllImport("userenv.dll")] to fetch the
GetDefaultUserProfileDirectory
But there are a LPTZStr and i don't know what the equalient is in c# for
that.

Anyone who can give me a code snippet on how it should look to import this
function?

Regards

Martin Arvidsson
 
Martin,

Your declaration would be:

[DllImport("userenv.dll", SetLastError=true, CharSet=CharSet.Auto)
static extern bool GetDefaultUserProfileDirectory(
string lpProfileDir,
[MarshalAs(UnmanagedType.U4)] ref lpcchSize);

You can also get a lot of the declarations you need for Windows API
functions at http://www.pinvoke.net (there is even an add in for VS.NET
which will do this for you).

Hope this helps.
 
Anyone who can give me a code snippet on how it should look to import this
function?

[DllImport("userenv.dll", CharSet=CharSet.Auto)]
static extern bool GetDefaultUserProfileDirectory(StringBuilder
lpProfileDir, ref uint lpcchSize);



Mattias
 
This is wrong, see Mattias' declaration instead.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Nicholas Paldino said:
Martin,

Your declaration would be:

[DllImport("userenv.dll", SetLastError=true, CharSet=CharSet.Auto)
static extern bool GetDefaultUserProfileDirectory(
string lpProfileDir,
[MarshalAs(UnmanagedType.U4)] ref lpcchSize);

You can also get a lot of the declarations you need for Windows API
functions at http://www.pinvoke.net (there is even an add in for VS.NET
which will do this for you).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)



Visual Systems AB (Martin Arvidsson) said:
Hi!

In c# I use [DllImport("userenv.dll")] to fetch the
GetDefaultUserProfileDirectory
But there are a LPTZStr and i don't know what the equalient is in c# for
that.

Anyone who can give me a code snippet on how it should look to import
this
function?

Regards

Martin Arvidsson
 
Back
Top