DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: writing/calling a .DLL in VB (visual studio 2010)

  1. #1
    Join Date
    Mar 2010

    writing/calling a .DLL in VB (visual studio 2010)

    Visual Studio 2010 (VB)

    I want to call the function do_barcode() in the dll AxBarcodeCG.dll

    i have added a reference to axbarcode to the project containing the caller code, but when i run it i get the error "Unable to find an entry point named 'do_barcode' in DLL 'axbarcodecg'."

    can anyone see what i am doing wrong?

    PS i am new to VS 2010 and DLL writing.

    PPS there is probably a more elegant way to build a printer escape sequence that the one i have used,.

    thanks in advance.

    // *************************************************** //

    Public Class AxBarcodeCG

    Public Const DLL_PROCESS_DETACH = 0
    Public Const DLL_PROCESS_ATTACH = 1
    Public Const DLL_THREAD_ATTACH = 2
    Public Const DLL_THREAD_DETACH = 3

    Public Function DllMain(ByVal hInst As Long, ByVal fdwReason As Long,
    ByVal lpvReserved As Long) As Boolean
    Select Case fdwReason
    ' No per-process cleanup needed
    DllMain = True
    ' No per-thread initialization needed
    ' No per-thread cleanup needed
    End Select

    End Function

    Public Function do_barcode(ByVal var As String) As String

    Dim myString As String

    myString = Chr(27) + Chr(16) + Chr(65) + Chr(8) + Chr(4) + Chr(0) + Chr(0) + Chr(3) + Chr(1) + Chr(1) + Chr(1) + Chr(1)
    myString = myString + Chr(27) + Chr(16) + Chr(66) + Chr(14) + Chr(65) + "1111-1234567" + Chr(103)

    Return myString

    End Function

    End Class

    // ************************************************************************* //

    // Caller Code

    Public Class Form1
    Private Declare Function do_barcode Lib "axbarcodecg" (ByVal escapestr As String) As String
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Me.TextBox1.Text = do_barcode(1)
    End Sub

    End Class

  2. #2
    Join Date
    Feb 2004
    Longueuil, Québec
    Try to see if the company that designed AxBarcodeCG.dll has a .NET version of that dll.

    The way you are trying to call it, it looks like an old C or C++ dll, and those are hard to get to from .NET. Most of the code published for those has been written in VB6 and does not translates directly to .NET. dll were mostly replaced by COM dlls during the 90's, and those are now being replaced by .NET dlls. Too bad Microsoft decided to keep the same extension. Although they have the same function, the 3 types of dll are different beasts and do not have the same calling conventions. What you are trying to do is to use a 2010 technology to call a dll that was buits on a technology of the 80's, that is quite a step, that usually can be gapped, not always.

    It does not seem at first sight to be an issue with your own thing, but for instance, the AsAny keyword in VB6 does not work in VB.NET where you need to work with overloading

    Unfortunately, I won't be able to help you more than this, having had very little experience with that stuff in .NET.

    Hope somebody else will be able to help you with your current code if you cannot do otherwise.

    Good luck.
    Jacques Bourgeois

  3. #3
    Join Date
    Mar 2010
    Thanks Jacques,
    I wrote axbarcodecg.dll , and i wrote that and the caller in visual studio 2010.

    the first block of source code is the dll.

    thanks again for responding.

  4. #4
    Join Date
    Feb 2004
    Longueuil, Québec
    Ooops did not look carefully enough, and since you use old conventions, I was mistaken.

    We have stopped using all uppercases constants around the time VB4 came on the market, in the middle of the 90's. Usually, when you see those in modern code, it is to call old code.

    The Declare statement, as I might have mentioned before, is used to link with old C/C++ dlls or to call Windows internal functions (which are for the most part written that way to enable old applications to still work in the newer versions of Windows). It has never been used to communicate with a dll written in VB.

    What I was was looking like old code I haven't seen for a while.



    Although your constants will work as they are, the conventions that have become common in recent years would rather give something like

    Public Const DllProcessDetach = 0

    The uppercase with underscore convention dates from the time when code had to be written all in uppercase... wich has gone away in Windows. People who program in C tend to stick to those old conventions out of habit. Same goes for field names in databases.


    As for the connection to the dll, Decalre does not work because when you use that, the system tries to connect to your VB dll as if it was an old C++ dll. That will never work.

    To use a modern dll, go into the Project menu and activate Add Reference. Your dll will probably not appear in the list of available dlls shown there, but you can go into the Browse tab, point to your dll and click OK. Once a dll has been referenced that way, you can use call it from anywhere in the project.

    If you want to see the dlls that are actually referenced in your project (and maybe make sure that your's has been added to the list), open the Project properties, last option in the Project tab. In the References tab, you will see all the dlls actually available for your code.

    If you ever try to use one of the framework classes and you get an error message to the effect that it is not recogized, it is probably because you did not add the dll that contains that class to the references. The documentation for all classes / properties / methods / events usually tells you, somewhere at the top of each page, the name of the dll you need in order to use that class.

    Hope this helps, and sorry for my mistake.
    Last edited by JBourgeois; 03-08-2010 at 11:48 PM.
    Jacques Bourgeois

  5. #5
    Join Date
    Mar 2010
    THanks Jaque,
    i added the reference, removed the declare and it still says Unable to find an entry point named XXX.

    thanks for the replies so far.


  6. #6
    Join Date
    Feb 2004
    Longueuil, Québec
    Hi Colin.

    Looking back at your original code, I see another problem: the way you are calling your class: Me.TextBox1.Text = do_barcode(1)

    In object programming, in order to use a class, you first have to create an object (a variable pointing to that class).

    You can they use that variable to call methods (procedures/routines) inside that object.

    Dim yourVariable As New AxBarcodeCG()
    Me.TextBox1.Text = yourVariable.do_barcode("1")
    Note that because you declare the paramater to pass to do_barcode as a String, you need to pass "1", between double quotes, instead of simply 1. 1 alone might work, depending on compiler settings set in the project properties, but this requires a conversion from Integer (1 is an Integer) to a String ("1" is a String), which is not as efficient and might sometimes lead to errors.

    Hope this works, I do not have time to copy and test your class in my development environment to make sure that I did not miss anything.
    Jacques Bourgeois

Similar Threads

  1. VB code in Visual Studio 2008
    By mqdias in forum .NET
    Replies: 4
    Last Post: 12-26-2007, 10:59 AM
  2. ANN: Release of DeKlarit 2.0 for Microsoft Visual Studio .NET
    By Maria Jose Serres in forum dotnet.announcements
    Replies: 0
    Last Post: 02-19-2003, 03:54 PM
  3. Microsoft gains Visual Studio .NET momentum
    By Patrick Troughton in forum .NET
    Replies: 1
    Last Post: 02-12-2003, 10:31 AM
  4. Replies: 2
    Last Post: 08-30-2002, 02:03 PM
  5. Visual Studio.NET Resources
    By Robert Scoble in forum ASP.NET
    Replies: 0
    Last Post: 07-20-2000, 04:11 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center