1

これを(C#から)C ++に変換する方法を知っている人はいますか?

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

ありがとう。

編集:追加情報

これは、C#からネイティブC++に変換するためのものです。現在実行中の実行可能ファイルのファイルパスを取得する別の方法がある場合、私はアイデアを受け入れます。ありがとう。

4

2 に答える 2

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

上記を組み合わせると、おそらくあなたがやりたいことに少し近づくでしょう。これをネイティブC++で行う場合は、もう少し問題が発生します。GACでアセンブリを探すのに役立つ「FusionAPI」と呼ばれるものがあります。

于 2011-01-20T22:33:22.153 に答える
1

現在の実行可能ファイルのパスを取得するには、NULLのhModule引数を使用してGetModuleFileNameを使用します。

于 2011-01-21T14:45:47.160 に答える