c# - 如何在 C# 中使用 CreateUserProfileEx

标签 c# winapi pinvoke

我正在用 C# 构建一个小型应用程序,它可以使用 Windows API 在 Windows XP、Windows7 和 Windows 8 上创建用户配置文件

对于 Windows 7 和 8,方法 CreateProfile工作完美。

但是,当尝试使用 CreateUserProfileEx在 Windows XP 上,它不起作用,它返回一个错误,通知我在“UserEnv.dll”中找不到该方法,在阅读了更多 API 之后,我意识到我需要使用LoadLibraryGetProcAddress 链接到 Userenv.dll。

我搜索了一些与此相关的示例,但找不到可以给我一个好主意或解释如何执行此操作的内容。

如果有人可以在 C# 中放置一些示例或指出我可以查看的地方,我将非常感激。

最佳答案

after reading a little bit more the API, I realized that I would need to use the LoadLibrary and GetProcAddress to link to Userenv.dll.

Read a little bit more :

This function is not declared in the software development kit (SDK) headers and has no associated import library. You must use the LoadLibrary and GetProcAddress functions to link to Userenv.dll. The ANSI version of the function, CreateUserProfileExA is referenced from Userenv.dll as ordinal 153. The Unicode version, CreateUserProfileExW is referenced as ordinal 154.

Google a little bit :

Additionally, in Windows you can bind to exported DLL functions by their ordinal values. If you need to do this, an EntryPoint value such as "#1" or "#129" indicates the ordinal value of the unmanaged function in the DLL rather than a function name.

关于c# - 如何在 C# 中使用 CreateUserProfileEx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24474445/

相关文章:

.net - "An attempt was made to load a program with an incorrect format"即使平台相同

c#:一般将非托管数组转换为托管列表

c# - PInvoke 整数编码返回不正确的结果

c# - System.Predicate<T> : Is this really what it means, 或者这是它的用途?

c# - MediaElement 不播放流 WP7 中的音频

c++ - Win32 相当于 .net SendKeys

winapi - 在支持 Windows 8.1 的应用程序上缩放非客户区以支持每个监视器的高 DPI

c# - Visual Studio Code : "Program has more than one entry point defined"

c# - 如何将音频文件分割成帧???在 C# 中

c++ - 如何更改子窗口在父窗口中的位置并显示工具栏?