0

I created a DLL in VB.Net. I know in C you can export certain functions to allow them to be visible to external files that uses the library

However, my VB.Net library cannot be used. 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).

Any reason why? Is it a VB.Net thing?

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). 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
MMTYL
  • 15
  • 1
  • 6
  • 1
    What environment you are using? – Fabio Jun 03 '16 at 17:20
  • 1
    You're going to need to provide more information. What code is trying to call your VB.NET DLL? What does your .NET code look like? etc. – DWRoelands Jun 03 '16 at 17:22
  • no reason I do it all the time. Are the DLL methods exposed? – coder32 Jun 03 '16 at 17:24
  • Mhm I can try to show the code but I didn't run the test unfortunately. I was just told the DLL gave some errors and didn't allow its object to be seen. I'll show what I have ( it was a test run). @Coder32 I believed its not possible to exposed them from what I read? : https://social.msdn.microsoft.com/Forums/vstudio/en-US/c22ddd79-b3b6-45f4-9315-6d1c9743dbec/building-a-dll-in-vbnet?forum=vbgeneral . The code that tries to call it is beyond me, again, I'm doing this with minimal knowledge of what uses it. I'll edit with more information that I myself know – MMTYL Jun 03 '16 at 17:29
  • @Fabio both DLL and test in VS 2010 – MMTYL Jun 03 '16 at 17:35
  • Show code where you trying to use this dll? Is it C or C++? – Fabio Jun 03 '16 at 17:48
  • In C I believe , I've never seen the source code though. I have no access to the specific source code however. Another department has it. I believe i need to make a wrapper class as Joshua mentionned – MMTYL Jun 03 '16 at 18:06
  • why you can't write your code in C too? – Fabio Jun 04 '16 at 04:50

2 Answers2

1

It sounds like somebody's trying to call the VB .NET DLL from C or C++ or some other native language. 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.

Joshua
  • 40,822
  • 8
  • 72
  • 132
0

I think what you are looking for is how to make your .Net DLL COM Visible.

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.

Since C/C++ do not use the .Net Framework it will be impossible to load. Thus, you must make this DLL COM Visible.

Here are a few links from a google search on how to do that :

Turn a simple C# DLL into a COM interop component

Making a .NET Dll COM-Visible

I hope this will point you towards the right direction.

Community
  • 1
  • 1
Martin Verjans
  • 4,675
  • 1
  • 21
  • 48