2011-01-20 37 views
1

有谁知道我可以如何将它(从C#)转换为C++?将确定性路径代码从C#转换为C++

string location = Path.GetDirectoryName(Assembly.GetAssembly(typeof(ZigbeeCommUSB)).CodeBase); 
location = location.Substring(location.IndexOf("\\") + 1); 

谢谢。

编辑:附加信息

这是从C#转换为本地C++。如果还有另一种方式来获取当前正在执行的可执行文件的文件路径,我愿意接受。谢谢。

+0

它的哪个部分有问题?你是否从C#转换到托管C++?或者你想转换为本机C++? – 2011-01-20 22:25:36

+0

Visual C++?或标准C++? – 2011-01-20 22:30:27

回答

1

Assembly.GetAssembly的例子从上面的链接

Assembly^ SampleAssembly; 
// Instantiate a target object. 
Int32 Integer1(0); 
Type^ Type1; 
// Set the Type instance to the target class type. 
Type1 = Integer1.GetType(); 
// Instantiate an Assembly class to the assembly housing the Integer type. 
SampleAssembly = Assembly::GetAssembly(Integer1.GetType()); 
// Gets the location of the assembly using file: protocol. 
Console::WriteLine("CodeBase= {0}", SampleAssembly->CodeBase); 

如果结合上述内容,您可能会更接近您想要做的事情。 如果这将在Native C++中完成,您将遇到更多问题,有一些名为"Fusion API"的内容可能会帮助您在GAC中查找程序集。

1

要检索当前可执行文件的路径,请使用GetModuleFileName使用NULL hModule参数。