Need help implementing a C++ DLL in my VB app

Posted on 2005-04-07
Last Modified: 2010-05-03
I have a VB app that is used in a medical environment to capture images from a digital camera.  We are wanting to switch to the Kodak DCS Pro/N.  The software development kit for the Kodak camera provides a firewire driver and a .dll with functions for capturing images, etc.  I have no idea how to use that C++ .dll in my vb app.  Does it have to be "converted" for use in VB?  Can it be called directly?  Where do I go from here?
Question by:bc4942
    LVL 53

    Expert Comment

    Declare Function myFunction Lib "MYLIB.DLL" (ByVal var1 As Long) As Long

    Where MYLIB.DLL is located either in the application path or in your system32 folder.

    Some interesting information:
    You have to use dllexport & dllimport to make the classes/functions/methods visible to VB

    Using dllimport and dllexport in C++
    You can declare C++ classes with the dllimport or dllexport attribute. These forms imply that the entire class is imported or exported. Classes exported this way are called exportable classes.

    The following example defines an exportable class. All its member functions and static data are exported:

    #define DllExport __declspec( dllexport )

    class DllExport C
    int i;
    virtual int func( void )
    { return 1; }

    Note that explicit use of the dllimport and dllexport attributes on members of an exportable class is prohibited.

    Your user MUST declare his functions as follows

    Private Declare Function GetTempPath Lib "kernel32" _
    Alias "GetTempPathA" (ByVal nBufferLength As Long, _
    ByVal lpBuffer As String) As Long

    The following topic was quite a good starting point for me when I did this a couple of years ago (MSDN Index/Search)

    "Export from a DLL Using __declspec(dllexport)"

    Author Comment

    I understand where you are leading me here and understand the basic concept.  I do not have access to C++ however and am limited on time to learn how to properly do this.  Where might I find someone to "convert" this for me?
    LVL 13

    Expert Comment

    Depending on your DLL, maybe you don't have to write anything in C, maybe you just have to set up some "Declares" in your VB code.

    If your DLL is not very complex and/or you don't need to implement all its functionality maybe you can get help here in ee, if you can provide the documentation of the dll.

    If what you really want is to "find someone to convert this for you", is an option I guess.
    LVL 16

    Expert Comment

    VB6?  Here are some options...

    1) Your best best might be to use the Windows standard TWAIN drivers, in which case you wouldn't need to directly use the DLL at all, but just the standard windows features.

    2) If the DLL is an activeX dll, you can add it to the references in your VB project, choose Project --> References, click browse and find and double-click the DLL.  If you don't get any errors, you will be able to use the DLL from VB.  You can see what is available by pressing F2 and choosing the appropriate library.

    3) If the DLL isn't an ActiveX DLL, but uses standard calling mechansims and conforms to certain rules, you will have to declare the functions in your VB project, but you won't have to use C++.  In your VB app you'd use something like
    Private Declare Function SomeKodakFunction Lib "Kodak.dll" (ByVal WhateverParamsAreNeeded As Long) As Long
    but you would have to decipher the dll declarations from the documentation, or a .h file if they provided one.

    4) If the DLL doesn't use standard calling mechanisms or requires thing VB 6 can't do, then you need to wrap it in some C++ to clean it up.

    Accepted Solution

    PAQed with no points refunded (of 125)

    Community Support Moderator

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now