开发者

Converting Deterministic Path Code from C# to C++

Does anyone know how I can convert this (from C#) to C++?

string location = Path.GetDirectoryName(Assembly.GetAssembly(typeof(ZigbeeCommUSB)).CodeBase);
location = location.Subs开发者_运维技巧tring(location.IndexOf("\\") + 1);

Thanks.

EDIT: Additional Information

This is to convert from C# to native C++. If there is another way to get the file path of the currently executing executable, I am open to ideas. Thanks.


  • Substring in C++
  • Getting path of current directory ( will help you on the way )
  • How to do IndexOf in C++
  • You can use Assembly.GetAssembly in C++ if you use Visual C++

Example of Assembly.GetAssembly from the above link

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 );

If you combind the above, you will probably come a bit closer to what you want to do. If this is going to be done in Native C++, you will have a bit more problem, there is something called "Fusion API" that might help you look for assemblies in the GAC.


To retrieve the path of the current executable, use GetModuleFileName using a NULL hModule argument.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜