(根据windows 核心编程描述,很多A版本内部其实是调用的W版本,效率上W 更好,更推荐)
查看windows 一个函数的定义如下:
WINBASEAPI
_NullNull_terminated_
LPCH
WINAPI
GetEnvironmentStrings(
VOID
);
WINBASEAPI
_NullNull_terminated_
LPWCH
WINAPI
GetEnvironmentStringsW(
VOID
);
#ifdef UNICODE
#define GetEnvironmentStrings GetEnvironmentStringsW
#else
#define GetEnvironmentStringsA GetEnvironmentStrings
#endif // !UNICODE
可以发现是无法调用 GetEnvironmentStringsA 的, 而 GetEnvironmentStrings 使用的是W版本。
手动复制出来(依然写成A版本):
WINBASEAPI
_NullNull_terminated_
LPCH
WINAPI
GetEnvironmentStringsA(
VOID
);
发现依然不行。解决方案如下:
// 方案1
//extern "C" __declspec(dllimport) LPCH WINAPI GetEnvironmentStringsA(VOID);
// 方案2
extern "C" WINBASEAPI
_NullNull_terminated_
LPCH
WINAPI
GetEnvironmentStringsA(
VOID
);
任选一种方案,写到需要调用处前面,作为一个函数声明。