• <small id='FtHhw'></small><noframes id='FtHhw'>

        <legend id='FtHhw'><style id='FtHhw'><dir id='FtHhw'><q id='FtHhw'></q></dir></style></legend>
          <bdo id='FtHhw'></bdo><ul id='FtHhw'></ul>
      1. <tfoot id='FtHhw'></tfoot>

      2. <i id='FtHhw'><tr id='FtHhw'><dt id='FtHhw'><q id='FtHhw'><span id='FtHhw'><b id='FtHhw'><form id='FtHhw'><ins id='FtHhw'></ins><ul id='FtHhw'></ul><sub id='FtHhw'></sub></form><legend id='FtHhw'></legend><bdo id='FtHhw'><pre id='FtHhw'><center id='FtHhw'></center></pre></bdo></b><th id='FtHhw'></th></span></q></dt></tr></i><div id='FtHhw'><tfoot id='FtHhw'></tfoot><dl id='FtHhw'><fieldset id='FtHhw'></fieldset></dl></div>

        从 .NET 使用 Python COM 服务器

        Consuming Python COM Server from .NET(从 .NET 使用 Python COM 服务器)
          <tbody id='bB5Gx'></tbody>

        <small id='bB5Gx'></small><noframes id='bB5Gx'>

        <legend id='bB5Gx'><style id='bB5Gx'><dir id='bB5Gx'><q id='bB5Gx'></q></dir></style></legend>
            <bdo id='bB5Gx'></bdo><ul id='bB5Gx'></ul>

            <i id='bB5Gx'><tr id='bB5Gx'><dt id='bB5Gx'><q id='bB5Gx'><span id='bB5Gx'><b id='bB5Gx'><form id='bB5Gx'><ins id='bB5Gx'></ins><ul id='bB5Gx'></ul><sub id='bB5Gx'></sub></form><legend id='bB5Gx'></legend><bdo id='bB5Gx'><pre id='bB5Gx'><center id='bB5Gx'></center></pre></bdo></b><th id='bB5Gx'></th></span></q></dt></tr></i><div id='bB5Gx'><tfoot id='bB5Gx'></tfoot><dl id='bB5Gx'><fieldset id='bB5Gx'></fieldset></dl></div>

                1. <tfoot id='bB5Gx'></tfoot>

                  本文介绍了从 .NET 使用 Python COM 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想使用 win32com 扩展实现 python com 服务器.然后从 .NET 中使用服务器.我使用以下示例来实现 com 服务器,它运行时没有问题,但是当我尝试使用 C# 使用它时,我收到 FileNotFoundException 并显示以下消息Retrieving the COM class factory for component with CLSID {676E38A6-7FA7-4BFF-9179-AE959734DEBB} 由于以下错误而失败:8007007e.".我也发布了 C# 代码.我想知道我是否遗漏了一些我希望得到帮助的东西.

                  I wanted to implement python com server using win32com extensions. Then consume the server from within the .NET. I used the following example to implement the com server and it runs without a problem but when I try to consume it using C# I got FileNotFoundException with the following message "Retrieving the COM class factory for component with CLSID {676E38A6-7FA7-4BFF-9179-AE959734DEBB} failed due to the following error: 8007007e." . I posted the C# code as well.I wonder if I'm missing something I would appreciate any help.

                  谢谢,莎拉

                  #PythonCOMServer.py
                  
                  import pythoncom
                  class PythonUtilities:
                      _public_methods_ = [ 'SplitString' ]
                      _reg_progid_ = "PythonDemos.Utilities"
                      # NEVER copy the following ID
                  
                      # Use"print pythoncom.CreateGuid()" to make a new one.
                      _reg_clsid_ = pythoncom.CreateGuid()
                      print _reg_clsid_
                      def SplitString(self, val, item=None):
                          import string
                          if item != None: item = str(item)
                          return string.split(str(val), item)
                  
                  # Add code so that when this script is run by
                  # Python.exe,.it self-registers.
                  
                  if __name__=='__main__':        
                      print 'Registering Com Server'
                      import win32com.server.register
                      win32com.server.register.UseCommandLine(PythonUtilities)
                  
                  
                  // the C# code
                  using System;
                  using System.Collections.Generic;
                  using System.Linq;
                  using System.Text;
                  using System.Reflection;
                  
                  namespace ConsoleApplication2
                  {
                      class Program
                      {
                          static void Main(string[] args)
                          {
                  
                                Type pythonServer;
                                object pythonObject;
                                pythonServer = Type.GetTypeFromProgID("PythonDemos.Utilities");
                                pythonObject = Activator.CreateInstance(pythonServer);
                  
                          }
                      }
                  }
                  

                  推荐答案

                  COM 服务器只是一个软件(DLL 或可执行文件),它将通过定义的协议接受远程过程调用 (RPC).协议的一部分规定服务器必须有一个唯一的 ID,存储在 Windows 的注册表中.在我们的例子中,这意味着您已经注册"了.不存在的服务器.因此错误(未找到组件).

                  A COM server is just a piece of software (a DLL or an executable) that will accept remote procedure calls (RPC) through a defined protocol. Part of the protocol says that the server must have a unique ID, stored in the Windows' registry. In our case, this means that you have "registered" a server that is not existing. Thus the error (component not found).

                  所以,它应该是这样的(和往常一样,这是未经测试的代码!):

                  So, it should be something like this (as usual, this is untested code!):

                  import pythoncom
                  
                  class HelloWorld:
                      _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER
                      _reg_clsid_ = "{B83DD222-7750-413D-A9AD-01B37021B24B}"
                      _reg_desc_ = "Python Test COM Server"
                      _reg_progid_ = "Python.TestServer"
                      _public_methods_ = ['Hello']
                      _public_attrs_ = ['softspace', 'noCalls']
                      _readonly_attrs_ = ['noCalls']
                      # for Python 3.7+
                      _reg_verprogid_ = "Python.TestServer.1"
                      _reg_class_spec_ = "HelloWorldCOM.HelloWorld"
                  
                      def __init__(self):
                          self.softspace = 1
                          self.noCalls = 0
                  
                      def Hello(self, who):
                          self.noCalls = self.noCalls + 1
                          # insert "softspace" number of spaces
                          return "Hello" + " " * self.softspace + str(who)
                  
                  if __name__ == '__main__':
                      if '--register' in sys.argv[1:] or '--unregister' in sys.argv[1:]:
                          import win32com.server.register
                          win32com.server.register.UseCommandLine(HelloWorld)
                      else:
                          # start the server.
                          from win32com.server import localserver
                          localserver.serve(['{B83DD222-7750-413D-A9AD-01B37021B24B}'])
                  
                  

                  然后你应该从命令行运行(假设脚本名为 HelloWorldCOM.py):

                  Then you should run from the command line (assuming the script is called HelloWorldCOM.py):

                  HelloWorldCOM.py --register
                  HelloWorldCOM.py
                  

                  类 HelloWorld 是服务器的实际实现.它公开了一个方法(Hello)和几个属性,两者之一是只读的.使用第一个命令,注册服务器;对于第二个,您运行它,然后它就可以在其他应用程序中使用.

                  Class HelloWorld is the actual implementation of the server. It expose one method (Hello) and a couple of attributes, one of the two is read-only. With the first command, you register the server; with the second one, you run it and then it becomes available to usage from other applications.

                  这篇关于从 .NET 使用 Python COM 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  How can I force the PropertyGrid to show a custom dialog for a specific property?(如何强制 PropertyGrid 显示特定属性的自定义对话框?)
                  Associate attribute with code generated property in .net(将属性与 .net 中的代码生成属性相关联)
                  Attribute to generate compilation error on method call?(在方法调用上生成编译错误的属性?)
                  Can you omit the parenthesis from attributes with no params?(您可以省略没有参数的属性中的括号吗?)

                2. <i id='B4rtw'><tr id='B4rtw'><dt id='B4rtw'><q id='B4rtw'><span id='B4rtw'><b id='B4rtw'><form id='B4rtw'><ins id='B4rtw'></ins><ul id='B4rtw'></ul><sub id='B4rtw'></sub></form><legend id='B4rtw'></legend><bdo id='B4rtw'><pre id='B4rtw'><center id='B4rtw'></center></pre></bdo></b><th id='B4rtw'></th></span></q></dt></tr></i><div id='B4rtw'><tfoot id='B4rtw'></tfoot><dl id='B4rtw'><fieldset id='B4rtw'></fieldset></dl></div>
                    <bdo id='B4rtw'></bdo><ul id='B4rtw'></ul>
                      <tbody id='B4rtw'></tbody>
                      <tfoot id='B4rtw'></tfoot>

                      • <legend id='B4rtw'><style id='B4rtw'><dir id='B4rtw'><q id='B4rtw'></q></dir></style></legend>
                        • <small id='B4rtw'></small><noframes id='B4rtw'>