[DllImport("userenv.dll", SetLastError=true, CharSet=CharSet.Auto)]
static extern bool GetProfilesDirectory(StringBuilder path, ref int size);
StringBuilder path = new StringBuilder(4*1024);
int size = path.Capacity;
if (GetProfilesDirectory(path, ref size) )
{
... use path value, size contains length...
}
// GUI + ICON:
// copy bfe.ico to cwd
// echo 'this icon bfe.ico' > this.rc
// windres this.rc O coff o this.res
// gcc Wall -Wl,--enable-stdcall-fixup -mnop-fun-dllimport mwindows +
// this.res usrprof.c /.s32/userenv.dll
// https://cygwin.com/cygwin-ug-net/using.html
// https://cygwin.com/cygwin-ug-net/using.html
// use gcc to compile
// gcc Wall -Wl,--enable-stdcall-fixup -mnop-fundllimport pleaz.c
// the default during compilation is to produce a console application.
// If you are writing a GUI program, you should either compile with
// mwindows as explained above, or add the string "-Wl,-subsystem,windows"
// to the GCC command line.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <windows.h>
#include <w32api/windows.h>
#include <w32api/userenv.h>
int main() {
DWORD size = 4*1024;
char *path = malloc(size);
if (GetProfilesDirectory(path, &size) ) {
printf("%d %s\n", (int)size, path);
MessageBox(NULL, path, "GetProfilesDirectory()", MB_OK);
}
return 0;
}
Contributed by John Refling