[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 151
  • Last Modified:

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

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?
1 Solution
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)"
bc4942Author Commented:
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?
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", rentacoder.com is an option I guess.
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.
PAQed with no points refunded (of 125)

Community Support Moderator

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now