I need to do the same as the C# .net code below in C++ MFC
can you guys help me out?
using System;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
[DllImport("shell32.dll", EntryPoint = "#261",
CharSet = CharSet.Unicode, PreserveSig = false)]
public static extern void GetUserTilePath(
string username,
UInt32 whatever, // 0x80000000
StringBuilder picpath, int maxLength);
public static string GetUserTilePath(string username)
{ // username: use null for current user
var sb = new StringBuilder(1000);
GetUserTilePath(username, 0x80000000, sb, sb.Capacity);
return sb.ToString();
}
[STAThread]
static void Main(string[] args)
{
string path =GetUserTilePath(null);
Console.WriteLine("path = %s", path);
}
}
}
I cant get to the GetProcAddress from the #261 (or 261) entry point and/or its exactly signature to C++.
EDIT: Here is the Trick
HMODULE shell32Dll= ::LoadLibrary(L"shell32.dll");
HRESULT (__stdcall *getUserImage)(LPCWSTR userName,
DWORD zero , LPWSTR outPath, UINT size);
(FARPROC&)getUserImage = ::GetProcAddress(shell32Dll, MAKEINTRESOURCEA(261));
if(getUserImage)
{
WCHAR outPath[MAX_PATH];
getUserImage(NULL,0x80000000,outPath,MAX_PATH);
}
MAKEINTRESOURCEA(261) instead of “#261” or “261” make get the job done!
Thank you! Cameron!
From the GetProcAddr documentation:
It turns out you should be calling it like so: