1

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.

3
  • Which part of it are you having trouble with? Are you converting from C# to Managed C++? Or are you trying to convert to native C++? Commented Jan 20, 2011 at 22:25
  • Visual C++ ? or Standard C++ ? Commented Jan 20, 2011 at 22:30
  • This is for native C++. I need to get the location of the executable. Commented Jan 21, 2011 at 14:43

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, Filip. I've added some additional details to my original post.
@Jim, Check my second point "Getting path of current directory", that GetCurrentDir and should be what you are looking for.
Thanks. Microsoft now calls the function GetCurrentDirectory.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.