你按照这个过程试试看,我在我的机器上测试没有问题 1 现在文件的目录下执行命令:sn -k mykey1.snk生成一个密钥对mykey1.snk 2 将你原来的代码修改如下 using System; using System.Runtime .InteropServices ; using System.Reflection;\\添加 [assembly: AssemblyKeyFileAttribute("mykey1.snk")]\\添加这一行 namespace textcom1 { /// <summary> /// Summary description for Class1. /// </summary>
[Guid("5F99DD3D-FFC7-4bc3-A4C4-88DEAB431AD1")] public interface text_Interface { string getname(string a ); } [Guid("8BAE3195-03E6-40de-8683-4285AC3F7C03"),InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface text_Events { } [Guid("21D73148-55D4-4a3a-8BD1-2433C0580EF3"),ClassInterface(ClassInterfaceType.None),ComSourceInterfaces(typeof(text_Events))] public class textcom:text_Interface { public textcom() { } public string getname (string a) { return a; } }} 3 csc /t:library 你的文件名.cs 4 gacutil /i 你的文件名.dll 5 regasm 你的文件名.dll
to dy_2000_abc(芝麻开门) ( 你是用VB调吗,怎么我用不可以,错误提示显示: Run-time error '91' Object variable or with block variable not set我mykey1.dll使用一个regsvr32 命令,得到错误提示: C:\mykey1.dll was loaded ,but the Dllregisteserver entry point was not found 希望得到回答。谢谢
奇怪,我在我的机器上调用没有问题: Imports System Imports Microsoft.VisualBasic.Interaction Namespace abc Public Class a <STAThread()> Shared Sub Main() Dim o as new Object o=CreateObject("textcom1.textcom") Console.WriteLine(o.getname()) End Sub End Class End Namespace
如果错误信息是找不到对象的话,有可能是组件没有注册成功。
1 现在文件的目录下执行命令:sn -k mykey1.snk生成一个密钥对mykey1.snk
2 将你原来的代码修改如下
using System;
using System.Runtime .InteropServices ;
using System.Reflection;\\添加
[assembly: AssemblyKeyFileAttribute("mykey1.snk")]\\添加这一行
namespace textcom1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
[Guid("5F99DD3D-FFC7-4bc3-A4C4-88DEAB431AD1")]
public interface text_Interface
{
string getname(string a );
}
[Guid("8BAE3195-03E6-40de-8683-4285AC3F7C03"),InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface text_Events
{
} [Guid("21D73148-55D4-4a3a-8BD1-2433C0580EF3"),ClassInterface(ClassInterfaceType.None),ComSourceInterfaces(typeof(text_Events))]
public class textcom:text_Interface
{
public textcom()
{
}
public string getname (string a)
{
return a;
}
}}
3 csc /t:library 你的文件名.cs
4 gacutil /i 你的文件名.dll
5 regasm 你的文件名.dll
你是用VB调吗,怎么我用不可以,错误提示显示:
Run-time error '91'
Object variable or with block variable not set我mykey1.dll使用一个regsvr32 命令,得到错误提示:
C:\mykey1.dll was loaded ,but the Dllregisteserver entry point was not found 希望得到回答。谢谢
你能不能用VB调用一下,好象C#对COM的兼容性真是很小,强大的功能是夸出来的
Imports System
Imports Microsoft.VisualBasic.Interaction
Namespace abc
Public Class a
<STAThread()> Shared Sub Main()
Dim o as new Object
o=CreateObject("textcom1.textcom")
Console.WriteLine(o.getname())
End Sub
End Class
End Namespace
算了,结贴吧,分全给你
你在工作?做什么?