سؤال

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

string location = Path.GetDirectoryName(Assembly.GetAssembly(typeof(ZigbeeCommUSB)).CodeBase);
location = location.Substring(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.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top