简体   繁体   English

在外部文件中使用VB.NET DLL函数不起作用

[英]Using VB.NET DLL functions in external file not working

I created a DLL in VB.Net. 我在VB.Net中创建了一个DLL。 I know in C you can export certain functions to allow them to be visible to external files that uses the library 我知道在C语言中您可以导出某些函数,以使使用库的外部文件可以看到它们

However, my VB.Net library cannot be used. 但是,不能使用我的VB.Net库。 For instance, in another program, after having added my DLL it just cannot find any functions ( I tried allowing the functions to be Public but didn't change much). 例如,在另一个程序中,添加了我的DLL之后,它找不到任何功能(我尝试允许这些功能为“公开”,但变化不大)。

Any reason why? 有什么原因吗? Is it a VB.Net thing? 这是VB.Net的东西吗?

EDIT: 编辑:

Here's the deal: I'm writing a DLL in VB which is supposed to allow another department to run test ( Layer goes like this : SQL SERVER -- > DLL --> test app). 达成协议:我正在VB中编写一个DLL,它应该允许另一个部门运行测试(层是这样的:SQL SERVER-> DLL->测试应用程序)。 I have no idea how the other department is allowed to run the test but here's a code snippet ,which I hope, will shed some light on my issue: 我不知道如何允许其他部门运行测试,但是下面是一个代码片段,希望该片段可以阐明我的问题:

Public Class duct

  //Only the Info should be  be accessible from other application(s)



    Public lt as String
    Private database As String


    Public Function Info(ByVal serialNumber As String) As String
        Dim conn As SqlConnection
        conn = connectionPd()
        Return lt(conn, serialNumber)


    End Function

      Private Function connect() As SqlConnection
        Dim _in As StreamReader
        Dim conn As New SqlConnection
        Dim str As String = String.Empty
        Dim servername As String = String.Empty

        Try
            _in = New StreamReader("file path here")
            While _in.Peek >= 0
                str = _in.ReadLine

                If str.Contains("someString") Then

                    Dim temp(), temp1() As String
                    temp = str.Split("=")
                    temp1 = temp(1).Split(Chr(34))
                    servername = temp1(1)
                ElseIf str.Contains("SomeString") Then
                    Dim temp(), temp1() As String
                    temp = str.Split("=")
                    temp1 = temp(1).Split(Chr(34))
                    database = temp1(1)
                End If
            End While

        Catch ex As Exception
            MsgBox(ex.ToString())
        End Try


        Try
            conn = New SqlConnection("Server = " & servername & ";" & " Trusted_Connection=yes")
            conn.Open()
            Return conn
        Catch msg As Exception
            MsgBox(msg.ToString())
            Return conn
        End Try

    End Function


    Private Function connectionPd() As SqlConnection
        Dim conn As SqlConnection

        conn = connect()
        Return conn

    End Function

End Class

It sounds like somebody's trying to call the VB .NET DLL from C or C++ or some other native language. 听起来有人在尝试从C或C ++或其他某种本地语言调用VB .NET DLL。 This doesn't work. 这行不通。 There's a huge thing about hosting the CLR you would have to go through or use C++/CLR to write a bridge DLL. 关于托管CLR,您必须经历或使用C ++ / CLR编写桥DLL的事情很大。

I think what you are looking for is how to make your .Net DLL COM Visible. 我认为您正在寻找的是如何使您的.Net DLL COM可见。

The DLL created with VB .NET is executable only if the application runs the same version of .NET Framework you used to build the DLL. 仅当应用程序运行用于生成DLL的相同版本的.NET Framework时,才能使用VB .NET创建的DLL是可执行的。

Since C/C++ do not use the .Net Framework it will be impossible to load. 由于C / C ++不使用.Net Framework,因此将无法加载。 Thus, you must make this DLL COM Visible. 因此,您必须使此DLL COM可见。

Here are a few links from a google search on how to do that : 以下是Google搜索提供的有关此操作的一些链接:

Turn a simple C# DLL into a COM interop component 将简单的C#DLL转换为COM互操作组件

Making a .NET Dll COM-Visible 使.NET Dll COM可见

I hope this will point you towards the right direction. 我希望这会为您指明正确的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM