GetWindowsDirectory()。 问候,将 GetWindowsDirectory(). Regards, Will 对。那是因为在.Net环境中,应用程序预计将使用框架来实现。你可以下拉到API的水平,但这是一些 的工作。如果在.Net中有一个带有 方法的课程来获得你想要的东西,我不会感到惊讶。我现在没有时间做研究。 至于使用API​​,你有两个选择。一个是平台调用又名 P / Invoke。这是一个例子 #include" stdafx.h" #using< mscorlib.dll> using namespace System; using namespace System :: Runtime :: InteropServices; [DllImport(" Kernel32.dll",EntryPoint =" GetWindowsDirectoryW", CallingConvention = CallingConvention :: StdCall)] extern" C" int GetWindowsDirectory(wchar_t *,unsigned int); int _tmain() { wchar_t wszDir [260]; GetWindowsDirectory(wszDir,sizeof(wszDir)); 返回0; } 请注意,我硬编码了字符串的大小。这很糟糕,只在这里完成 作为权宜之计。 另一个选择是使用它只是工作。 IJW允许您有一个托管调用者 调用非托管函数。为此,我建议将原生的 API调用放在一个不使用框架的模块中,而不是使用/ CLR选项编译的。 问候, 将 Right. That''s because in the .Net environment, an application is expected touse the framwork. You can "drop down" to the level of the API but it is somework to do so. It wouldn''t surprise me if there is a class in .Net with amethod to get what you want. I don''t have time now to do the research. As for using the API, you have two choices. One is Platform Invoke akaP/Invoke. This is an example #include "stdafx.h"#using <mscorlib.dll> using namespace System;using namespace System::Runtime::InteropServices; [ DllImport("Kernel32.dll", EntryPoint="GetWindowsDirectoryW",CallingConvention=CallingConvention::StdCall) ]extern "C" int GetWindowsDirectory(wchar_t *, unsigned int); int _tmain(){wchar_t wszDir[260]; GetWindowsDirectory(wszDir, sizeof(wszDir)); return 0;} Note that I hardcoded the size of the string. That''s bad and only done hereas an expedient. Another option is to use "it just works". IJW lets you have a managed callercall into an unmanaged function. To do that, I''d suggest putting the nativeAPI call in a module which does not use the framework and which is notcompiled with the /CLR option. Regards,Will 这篇关于像IniFile = Visual C ++中的Application.ExecutablePath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-29 08:06