Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用外接程序的Office菜单控件_C++_Vsto_Add In - Fatal编程技术网

C++ 使用外接程序的Office菜单控件

C++ 使用外接程序的Office菜单控件,c++,vsto,add-in,C++,Vsto,Add In,我开发了一个插件来控制Office 2016中指定菜单和功能区控件的启用状态 <commands> <command idMso="FileSendAsAttachment" enabled="false"/> <command idMso="FileEmailAsPdfEmailAttachment" enabled="false"/> <command idMso="FileEmailAsXpsEmailAttac

我开发了一个插件来控制Office 2016中指定菜单和功能区控件的启用状态

  <commands>    
    <command idMso="FileSendAsAttachment" enabled="false"/>
    <command idMso="FileEmailAsPdfEmailAttachment" enabled="false"/>
    <command idMso="FileEmailAsXpsEmailAttachment" enabled="false"/>
    <command idMso="FileInternetFax" enabled="false"/>
    ...

  </commands>  

  <ribbon>
  </ribbon>

  <backstage>    
  </backstage>

</customUI>
XML文件遵循以下格式:

<?xml version="1.0" encoding="utf-8" ?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">

  <commands>    
    <command idMso="FileSendAsAttachment" enabled="false"/>
    <command idMso="FileEmailAsPdfEmailAttachment" enabled="false"/>
    <command idMso="FileEmailAsXpsEmailAttachment" enabled="false"/>
    <command idMso="FileInternetFax" enabled="false"/>
    ...

  </commands>  

  <ribbon>
  </ribbon>

  <backstage>    
  </backstage>

</customUI>
  <commands>    
    <command idMso="FileSendAsAttachment" enabled="false"/>
    <command idMso="FileEmailAsPdfEmailAttachment" enabled="false"/>
    <command idMso="FileEmailAsXpsEmailAttachment" enabled="false"/>
    <command idMso="FileInternetFax" enabled="false"/>
    ...

  </commands>  

  <ribbon>
  </ribbon>

  <backstage>    
  </backstage>

</customUI>

...

安装外接程序后,根据策略,代理可能需要临时启用某些菜单。 因此,我只修改了XML文件中控件的enable属性并重新启动了Office,但所有菜单都已启用。 (但是,当我将其替换为原始XML文件时,它会再次标记为禁用。)

  <commands>    
    <command idMso="FileSendAsAttachment" enabled="false"/>
    <command idMso="FileEmailAsPdfEmailAttachment" enabled="false"/>
    <command idMso="FileEmailAsXpsEmailAttachment" enabled="false"/>
    <command idMso="FileInternetFax" enabled="false"/>
    ...

  </commands>  

  <ribbon>
  </ribbon>

  <backstage>    
  </backstage>

</customUI>
我的加载项是通过regsvr32.exe注册的,注册表是用HKCU编写的。 (Windows为64位,Office 2016为32位。)

  <commands>    
    <command idMso="FileSendAsAttachment" enabled="false"/>
    <command idMso="FileEmailAsPdfEmailAttachment" enabled="false"/>
    <command idMso="FileEmailAsXpsEmailAttachment" enabled="false"/>
    <command idMso="FileInternetFax" enabled="false"/>
    ...

  </commands>  

  <ribbon>
  </ribbon>

  <backstage>    
  </backstage>

</customUI>
有没有人有过类似的问题?
这是什么原因造成的?

安装外接程序后,我使用记事本修改了XML文件。我发现它是以utf-8编码方式存储的

  <commands>    
    <command idMso="FileSendAsAttachment" enabled="false"/>
    <command idMso="FileEmailAsPdfEmailAttachment" enabled="false"/>
    <command idMso="FileEmailAsXpsEmailAttachment" enabled="false"/>
    <command idMso="FileInternetFax" enabled="false"/>
    ...

  </commands>  

  <ribbon>
  </ribbon>

  <backstage>    
  </backstage>

</customUI>
我注意到格式被破坏了,因为BOM表被插入到XML文件的第一个字节中。如果将文件另存为ANSI,则可以正常工作

  <commands>    
    <command idMso="FileSendAsAttachment" enabled="false"/>
    <command idMso="FileEmailAsPdfEmailAttachment" enabled="false"/>
    <command idMso="FileEmailAsXpsEmailAttachment" enabled="false"/>
    <command idMso="FileInternetFax" enabled="false"/>
    ...

  </commands>  

  <ribbon>
  </ribbon>

  <backstage>    
  </backstage>

</customUI>
我希望你不要犯和我一样的错误

使用utf-16
  <commands>    
    <command idMso="FileSendAsAttachment" enabled="false"/>
    <command idMso="FileEmailAsPdfEmailAttachment" enabled="false"/>
    <command idMso="FileEmailAsXpsEmailAttachment" enabled="false"/>
    <command idMso="FileInternetFax" enabled="false"/>
    ...

  </commands>  

  <ribbon>
  </ribbon>

  <backstage>    
  </backstage>

</customUI>

  <commands>    
    <command idMso="FileSendAsAttachment" enabled="false"/>
    <command idMso="FileEmailAsPdfEmailAttachment" enabled="false"/>
    <command idMso="FileEmailAsXpsEmailAttachment" enabled="false"/>
    <command idMso="FileInternetFax" enabled="false"/>
    ...

  </commands>  

  <ribbon>
  </ribbon>

  <backstage>    
  </backstage>

</customUI>

...