我想使用win32com扩展实现python com服务器,然后从.NET中调用服务器。我使用以下示例实现了com服务器,它可以正常运行,但是当我尝试使用C#消费它时,出现了FileNotFoundException,并显示以下消息:“检索具有CLSID {676E38A6-7FA7-4BFF-9179-AE959734DEBB} 的组件的COM类工厂失败,原因是以下错误:8007007e。” 我也发布了C#代码。我想知道是否有遗漏,感谢您的帮助。
谢谢, Sarah
谢谢, Sarah
#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);
}
}
}