私は、win32com拡張を使用してpython comサーバーを実装したかったのです。 その後、.NET内からサーバーを使用します。 次の例を使用してcomサーバーを実装しましたが、問題なく実行しますが、C#を使用してそれを消費しようとすると、次のメッセージでFileNotFoundExceptionが発生しました」CLSID {676E38A6-7FA7-4BFF- 9179-AE959734DEBB}が次のエラーのため失敗しました:8007007e " 。私はC#コードも投稿しました。私が何かを見逃しているのであれば、何か助けていただければ幸いです。.NETからのPython COMサーバーの使用
おかげで、 サラ
#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);
}
}
}
Pythonコードでは警告し、すべての呼び出しで新しいGUIDを使用しないように注意してください。一度だけGUIDを作成します。 – gimel
投稿したコードは、COMサーバーを登録するためのものです。実際のサーバーも実装していますか? –
私はサーバーの登録が実行中であることを意味します。あなたは私に多くのガイドを教えてくれますか? ありがとう – Sarah