我需要在 C++ MFC 中执行与下面的 C# .net 代码相同的操作,你们能帮帮我吗?
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);
}
}
}
我无法从 #261(或 261)入口点和/或其对 C++ 的确切签名访问 GetProcAddress。
编辑:这是诀窍
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) 而不是 "#261" 或 "261" 让工作完成!
谢谢!卡梅伦!