我试过网上找到的所有方法创建com组件,但是在vs6.0自带的查看工具中查看,都看不到组件中的方法。
请问谁有C#创建com组件和vc6中调用的例子?发给我[email protected]   万分感谢!!!
在vc6使用如下代码调用失败。
HINSTANCE hinstLib = LoadLibrary("ComTest.dll"); //我写的com组件
if(!hinstLib )
{
AfxMessageBox("11");
}
if(hinstLib)//到这里还是正常运行的,就是说能加载ComTest.dll
{
FARPROC  proc = GetProcAddress(hinstLib,"getname");//到这里就不行了,获取不到组件中方法的地址
if(!proc)
{
AfxMessageBox("21");
}
}

解决方案 »

  1.   

    我和你一样,到底怎么回事。我把dll生成tlb后,在vb里引用,类有,方法都没了,郁闷...
      

  2.   

    这个对你有用吗?
    <ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _
    Public Class ComClass1
       ' Use the Region directive to define a section named COM Guids. 
    #Region "COM GUIDs"
       ' These  GUIDs provide the COM identity for this class 
       ' and its COM interfaces. You can generate 
       ' these guids using guidgen.exe
        Public Const ClassId As String = "7666AC25-855F-4534-BC55-27BF09D49D46"
        Public Const InterfaceId As String = "54388137-8A76-491e-AA3A-853E23AC1217"
        Public Const EventsId As String = "EA329A13-16A0-478d-B41F-47583A761FF2"
    #End Region   Public Sub New()
          MyBase.New()
       End Sub   Function AddNumbers(ByVal X As Integer, ByVal Y As Integer)
          AddNumbers = X + Y
       End Function
    End Class
    注意   此属性简化 COM 对象的创建。若要创建 COM 对象,必须使用在“配置属性”对话框的“生成”节中选择的“注册 Com Interop”选项来编译项目。
      

  3.   

    我的问题已经解决了
    yadg(阿俊) 你的方法没有可能是因为你方法参数的数据类型有问题,你加一个没有参数的方法试试看。