0

I can't register COM .dll in my office.

OS - 64-bit Windows 7;
Target Framework of dll is 4.0;
Office is 32-bit Word 2007 (x86 Word 2007)
Addin sets Low Level Keyboard Hook and uses the following unmanaged methods

    [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    private static extern IntPtr GetModuleHandle(string lpModuleName);

    [DllImport("user32.dll", SetLastError = true)]
    private static extern bool UnhookWindowsHookEx(IntPtr hhk);

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    private static extern IntPtr SetWindowsHookEx(int idHook, HookProcedure lpfn, IntPtr hMod, uint dwThreadId);

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);  

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    private static extern IntPtr GetForegroundWindow();

Below all combinations I tried is shown. Notes:

  • RegAsm 32 means performing
    C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe "my.dll" /codebase
  • RegAsm 64 means performing
    C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe "my.dll" /codebase
  • Normal (CU) means
    HKEY_CURRENT_USER\Software\Microsoft\Office\Word\Addins\ProgID
  • WOW (CU) means
    HKEY_CURRENT_USER\Software\Wow6432Node\Microsoft\Office\Word\Addins\ProgID
  • WOW (LM) means
    HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\Word\Addins\ProgID
  • Registry entry(WOW-CU,Normal-CU and WOW-LM) means creating progID folder with Description,FriendlyName,LoadBehavior in appropriate registry directory which encoded above
  • Output is AddinSpy output
  • When target cpu bitness!=RegAsm bitness RegAsm command fails, I will not show such obvoius entries in my list.

    1. target=32,regasm=32,registry=WOW(CU),output=no output. Word 2007 doesn't see WOW-CU?

    2. target=x86-64,regasm=64,registry=WOW(CU),output=no output. Word 2007 doesn't see WOW-CU?

    3. target=32,regasm=32,registry=Normal(CU),output=BadImageFormatException But addin works!

    4. target=x86-64,regasm=64,registry=Normal(CU),output= Dll Path is not found.

    5. target=32,regasm=32,registry=WOW(LM),output=BadImageFormatException But addin works!

    6. target=x86-64,regasm=64,registry=WOW(LM),output=BadImageFormatException

I heard that Office 2007 doesn't support registration for all users (local machine) but it looks like it does, as 5 and 6 showed. I mean Word can see registry WOW node in LM. On the contrary, WOW6432 nodes in Current User ignored as 1 and 2 showed. So, Word can't see WOW node in CU.

How I can register my addin? 3 and 5 make it work but `BadImageFormatException is so annoying I want to ged rid from it.

  • Your conclusions are all accurate. Surely nobody can guess why a BadImageFormatException would still allow an addin to work, this is not youtube.com. – Hans Passant Mar 12 '14 at 12:54
  • @HansPassant, I forgot addition to `BadImageFormatException` - This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. However, target framework is 4.0 and my PC has 4.0 Framework installed. –  Mar 13 '14 at 09:03
  • Word already has the CLR loaded, an old version. You need a [winword.exe.config file](http://stackoverflow.com/a/13237936/17034) that forces CLR v4 to be loaded. – Hans Passant Mar 13 '14 at 11:04
  • I can't find .config file, I searched over my PC but failed to find it, I tried to create `winword.exe.config` near WINWORD.EXE but after such action Word can't start. –  Mar 13 '14 at 11:42

0 Answers0