x64 Microstf Excel (2019) で C# COM アドインを表示するのに苦労しています。これまで、アドインは x86 Microsoft Excel でのみ表示され、Microsoft Excel x64 では表示されませんでした。
私のアドイン (クラス ライブラリ) は AnyCPU にコンパイルされており、非常に基本的なものです。1 つの関数で 1 つのクラスのみを作成しました。複雑な Dll は参照されていません。
COM 登録に以下のコードを使用しています。
[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type type)
{
Registry.ClassesRoot.CreateSubKey(GetSubKeyName(type));
}
[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type type)
{
Registry.ClassesRoot.DeleteSubKey(GetSubKeyName(type), false);
}
private static string GetSubKeyName(Type type)
{
string s = @"CLSID\{" + type.GUID.ToString().ToUpper() + @"}\Programmable";
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey("CLSID\\{" +
type.GUID.ToString().ToUpper() + "}\\InprocServer32");
if (key != null)
{
key.SetValue("", System.Environment.GetFolderPath(System.Environment.SpecialFolder.System) +
@"\mscoree.dll");
}
return s;
}
上記のコードは、x86 Excel で完全に機能します。
調査を行った後、x64 Excel で表示するには、COM アドインを x64 レジストリに登録する必要があることを理解しました。次の行を使用してそれを実行しましたが、何も機能しませんでした。
// Version 1 : Registration to "Excel\\Addins" path
[ComRegisterFunction()]
private static void ComRegister(Type type)
{
string keyPath = "Software\\Microsoft\\Office\\Excel\\AddIns\\{" + type.GUID.ToString().ToUpper() + "}";
RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
RegistryKey key = baseKey.CreateSubKey(keyPath);
if (key != null)
key.SetValue("", System.Environment.GetFolderPath(System.Environment.SpecialFolder.System) + @"\mscoree.dll");
}
// Version 2 : Restration to "Wow6432Node"
[ComRegisterFunction]
public static void RegisterFunction(Type type)
{
string s = @"Wow6432Node\\CLSID\{" + type.GUID.ToString().ToUpper() + @"}\Programmable";
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey("Wow6432Node\\CLSID\\{" +
type.GUID.ToString().ToUpper() + "}\\InprocServer32");
if (key != null)
{
key.SetValue("", System.Environment.GetFolderPath(System.Environment.SpecialFolder.System) +
@"\mscoree.dll");
}
Registry.ClassesRoot.CreateSubKey(s);
}
この非常に基本的なアドインを x64 Excel で機能させるのを手伝ってくれる人はいますか?
前もって感謝します