Google Answers Logo
View Question
Q: Calling DLL procedures from a simple C++ program ( Answered 5 out of 5 stars,   3 Comments )
Subject: Calling DLL procedures from a simple C++ program
Category: Computers > Programming
Asked by: hyco-ga
List Price: $100.00
Posted: 09 Aug 2005 08:15 PDT
Expires: 08 Sep 2005 08:15 PDT
Question ID: 553557
I have bought and assembled a hobbyist Velleman K8055 USB interface
pcb that should let me interface a pc to external hardware, both input
and output. The hardware works fine I think (well, it runs some test
software anyway) but as I know very little about DLL's and C++ I
cannot follow the (very limited) instructions on how to write a
program in C++ that can talk to it. I suspect the errors I am making
are very elementary, like not having files in the right directories.
The kit is from You can search for code k8055 using
the search bar at the bottom left, and get some info on the board. I
have the basic software manual, which I don't think you can download
but which I can email. Some paid for help with C programming may
follow, if you can solve this first problem !

Request for Question Clarification by studboy-ga on 09 Aug 2005 12:35 PDT
Hi hyco-ga

I maybe able to help--
what kind of program do you intend to write?
If you want a sample program, I maybe able to provide one.


Request for Question Clarification by theta-ga on 09 Aug 2005 21:14 PDT
Hi hyco-ga,
   I have some experience programming for HW interface boards, so I
should be able to help out. While the user manual on the Velleman
website is encrypted, I was able to find another copy here:
    This manual provides sample code for interfacing with the board
using C++, Visual Basic and Delphi. Could you check with the user
manual you have and verify that this is for the same board? Also, it
would help other researchers working on this problem if you would
upload the software manual you have to a publicly available board such
as Just upload your file to this website, and
post a link to it here.
    Also, if you could provide some clarification regarding your exact
development needs, it would help us researchers assist you better.
    - What C++ compiler/IDE are you using? (for example, Visual C++ 6
or C++ Builder 5 etc.)
    - What version of the Windows operating system are you working on?
(Windows 98/Me/2000/XP/2003)
    - Do you just want help with compiling and running one of the
sample C/C++ programs from the manual for now, or do you require one
with some specific functionality?
    - Also, the manual will mention a DLL file that you must use (for
example K8055D.DLL). You will have been provided with .h and .lib
files with the same name as the .dll file (for example, K8055D.h and
K8055D.lib). Could you search for these files, upload them to the
Rapidshare[] website, and post a link to them
here? The researchers will need them to properly compile the sample
program on their test systems.


Clarification of Question by hyco-ga on 10 Aug 2005 01:54 PDT
Thanks Theta, to take your points one by one:

I have been playing with a free compiler called Dev CPP from (latest version beta, but I now think this
could be a bad choice as I have just been told by Velleman that "The
DLL works with Borland C++, but not with Microsoft's one, because of
the calling convention.". I don't really mind what compiler is used -
Borland obviously sounds like a reasonable option, if the DLL is

My pc is running XP professional. 

The manual is here (your link is also correct):

The files are here:

I'd consider the question fully answered if I end up with a working
small C++ program that is capable of reading and writing digital and
analogue variables to the test board.

I can then develop the program logic myself once i/o is sorted.

I would also like to know whether is easy to develop a windows screen
interface (to display variables and allow input), and would consider a
further $100 tip to make this happen. This is a nice to have though,
not a need.


Request for Question Clarification by theta-ga on 10 Aug 2005 04:26 PDT
Hi hyco-ga,
  I will get right on it.
  A small query - is it necessary that you use C++? Since the board
has a Visual Basic programming interface, you might find that simpler
especially if you plan to do GUI work.
  In any case, I am currently working on testing out a solution with C++ Builder.


Clarification of Question by hyco-ga on 10 Aug 2005 05:42 PDT
In terms of languages, my possibly suspect preference for C++ is
derived from my need to develop prototype code that will run on my pc
via the USB interface, and then could be ported to run on a
microcontroller as part of a small volume production product. The real
world product is actually a commercial boiling water unit - the inputs
are level and temperature sensors and the outputs are solenoid valve
and heating element.

Thus something that can run on a pc and also microcontroller with few
changes is of primary interest.

I might be interested VB too, for other applications when the desire
for a nice interface outweighs portability.

If you think there is a better way for any of this, let me know !

  real goal which is to develop algorthims that control an automatic
boiling water unit. really trying to develop controllers for  hinking
The purpose of C++ is that when I have written the real code and
tested the logic , I (or someone) can port this to a microcontroller

Clarification of Question by hyco-ga on 10 Aug 2005 05:43 PDT
Oops - forget the last paragraph.
Subject: Re: Calling DLL procedures from a simple C++ program
Answered By: theta-ga on 10 Aug 2005 22:56 PDT
Rated:5 out of 5 stars
Hi hyco-ga,
   I have uploaded an example c++ program that will read from and
write to the first analog channel on the board. You can download the
file from:
   The instructions to get it compiling and running properly follow:
    - STEP 1: Getting the compiler
        The example program that I have provided is a simple console
program, which has been tested with the Borland C++ 5.5 compiler.
Borland provides this compiler as a free download on their website.
You can download it from:
            - Borland C++ Builder Downloads
         Also, since we will be working on a GUI next, you will need
to download the Borland C++ Builder 6.0 Enterprise Trial, available
from the same webpage. However, this can wait, since our example
program just requires the BC++ 5.5 compiler for now.

    - STEP 2: Installing and configuring the Borland C++ 5.5 compiler
         Just run the downloaded exe and the compiler will install
itself. By default it installs in the 'C:\Borland\BCC55\' folder.
         Once the installation is complete, we will need to add the
BIN subfolder in the installation directory to the system PATH, so
that we can run the compiler just by specifying its name at the
command-line, with out worrying about the installation path.
         To add the compiler BIN folder to the system path:
          - Right click on the My Computer icon and select 'Properties'
          - In the Window that pops up, click on the 'Advanced' tab
          - On the 'Advanced' tab, click on the 'Environment Variables' button
          - In the dialog that pops up, go down the 'System Variables'
list till you see the 'Path' variable
          - Select the 'Path' variable and click on the 'Edit' button
          - In the window that pops up, goto the 'Variable Value'
field, and add the path to the BIN directory at the beginning of the
text there, followed by a semicolon. So if the field was earlier:
              Variable Value: %SystemRoot%\system32;%SystemRoot
            it should become
              Variable Value:
            where 'C:\Borland\BCC55\BIN' is the path to the BC++ 5.5
compiler BIN folder.
          - Now click on Ok and dismiss all the dialogs.

    - STEP 3: The compiler options
         To keep things simple, copy the example C++ program I have
provided, the K8055D.h and the K8055D.dll files into one folder. I
copied all the files into a 'C:\Example\' folder. You may use any
folder you want. Just change the command line options appropriately.
         Now when we compile this program, we have to provide the
compiler with the following information:
         - The list of folders it should search to find the required
header (.h) files. In this case, we want it to look in it's standard
headers files folder, which will be the 'Include' subfolder in the
installation directory (by default 'C:\Borland\BCC55\Include\')
            We also want it to look in the folder which contains the
'K8055D.h' header file. For me, this value is 'C:\Example\'. You will
have to put the appropriate folder name for yourself.
           The above information is provided to the compiler using the
-I option. The multiple folder names are separated by a semicolon.
         - We also need to provide the compiler with the path to the
standard library (.lib) folder. We provide this information using the
'-L' option. This folder will be 'C:\Borland\BCC55\LIB\' by default.
         - Now, since we are using a custom library file for the dll
(K8055D.lib), we will need to provide the full path to it at the
command line also. In the example, this path is given as
'C:\Example\K8055D.lib'. You will need to modify this path to reflect
your settings.
         - Finally, we need to provide the compiler with the name of
the C++ file that needs to be compiled (example.cpp in this case).

    - STEP 4: Compiling the program
          - To compile the program, we must first start the command
prompt. Go to 'Start Menu'> Run, type 'cmd' in the Run Dialog box and
press 'Enter'. The command prompt should pop up.
          - Now switch to the folder in which the example.cpp file and
the dll reside.
             cd C:\Example
          - Once you are in this folder, compile the cpp file with the
following command line:
               bcc32 -IC:\Example\;C:\Borland\BCC55\Include\
-LC:\Borland\BCC55\Lib C:\Example\k8055d.lib example.cpp
          - If all the settings have been provided correctly, the
program should compile without any error or warning messages.

    - STEP 4: Running the program
          Once the program compiles successfully, an exe file with the
same name (example.exe in this case) will be created in the current
folder. Make sure that the K8055D.dll file lies in the same folder as
the exe.
          Once you run the example program, it will try to open card 0
on the board. If it is successful, it clears the first Analog Channel,
asks the user for an input and writes it to the channel, and then
reads it back.
          Be sure to set the card address to 0 by setting the SK5 and
SK6 jumpers to on before connecting the USB cable or turning on the
PC. See the manual for detailed instructions.


 The example program demonstrates simple reading and writing
functionality as you requested. Its functionality can be extended
further using the other methods documented in the API.
 While I have tested that the program compiles and executes correctly,
I cannot verify the functionality since i do not have access to the
actual board.
 Please try out the example code, and if you encounter any errors,
post the detailed error messages here and we will work through them.
 Once you have confirmed that the given code meets your needs, we can
start work on the GUI. You will need to download and install Borland
C++ Builder 6.0 Enterprise trial for this, if you do not have access
to the full version.


Hope this helps.
If you need any clarifications, just ask! 


Request for Answer Clarification by hyco-ga on 11 Aug 2005 02:55 PDT
Nearly there, but the compiler is complaining about its inability to
find <iospace>.

see for screen shot. 


Clarification of Answer by theta-ga on 12 Aug 2005 00:14 PDT
Hi hyco-ga,
    The problem appears to be because of a missing space before the
'-L' parameter you supplied in the commandline.
The commandline right now is:
bcc32 -IC:\Example\;C:\Borland\BCC55\Include\-LC:\Borland\BCC55\Lib
C:\Example\k8055d.lib example.cpp

You need to leave a space between '\Include\' and '-L', making the commandline:
bcc32 -IC:\Example\;C:\Borland\BCC55\Include\
-LC:\Borland\BCC55\Lib C:\Example\k8055d.lib example.cpp

Unfortunately, Google Answers formats the line such that you can't
explicitly see the space, but trust me, there is one. :)
Once you insert the space before the '-L' option, the compiler will be
able to find the iostream header file, and the code will compile

Please test this out and get back to me if you face any more problems.
Hope this helps!

PS: Nice wallpaper you have there on your desktop. :)

Request for Answer Clarification by hyco-ga on 12 Aug 2005 04:43 PDT
It works perfectly thanks you very much indeed! I'd now like to try
develop a basic GUI.

Regarding the payment (well deserved !) - does making a payment now
close the thread ? If so, it seems we either wait and do the full
payment ($200 USD) after the GUI is done, or we close this thread and
open another one and hope we meet up again !!

I don't mind, so long as we don't lose touch before we're done. The
first options seems easiest to me, but your call.



ps the windows desktop picture was sent from a contact in China. The
location is a few hundred km NW of Peking, up near the border with
Russian Federation.

Clarification of Answer by theta-ga on 12 Aug 2005 06:34 PDT
Hi hyco-ga,
  Glad the console app worked out.
  We can continue the work on the GUI app here itself, and you can add
the payment as a tip when we are finished.
  So the next step is to determine what you want in the GUI. I am
assuming we will be developing it in BC++ Builder?

Request for Answer Clarification by hyco-ga on 12 Aug 2005 10:27 PDT
GUI would be great please. I have BC++ already and have got the
example.cpp to run as a project (not sure I could do it again though,
it sort of just happened).

As I mentioned, I'm trying to build a tool that lets me test
algorithms for the electronic controller of a water boiler. The
controller can "see" (via an analogue thermistor) how hot the water
is, and (via a binary level sensor) if the tank is full or not. It can
then decide if it should heat the water (via a binary electric element
switch) and if it should add some more cold water or not (via solnoid
valve). It is trying to maximise availability of hot water, without
wasting too much energy. Its entire knowledge of the world is derived
from the state of these parameters.

The program will basically run an infinite loop, where at each iteration it will:

- update external environment variables, plus any under user input control
- determine what needs to happen to the outputs (heat and/or fill)
basedon current inputs
- display its current view of the world, along with parameter
settings, in a simple GUI screen

I will write the decison rules in the middle bit. 

The program could update a slowly as once a second. 

The variables would be:

Outputs (ie displayed but not updated)

Name   Type    Description 
TempC  Float   C++ variable derived from TempV
TempV  Float   Thermistor reading Analogue input 1
Heat   Y/n

Request for Answer Clarification by hyco-ga on 12 Aug 2005 10:50 PDT
Name Type   Description
Heat y/n    State of digital output 1 (linked to element)
Fill y/n    State of digital output 2 (linked to solenoid valve)

Desc text   Free format description of what the program is doing, for info

Inputs (read from external sensor, or user input)

Name  Type Description
Tempf1   float Temp conversion factor 1 (analogue to deg C
Tempf2   float   "     "        "     2
Tdelta   float heat on/off factor - avoid "chatter" close to set point
AutoC    y/n   run autocalibrate routine ?
Psave    y/n   power setting manual or auto ?
Pred     y/n   run predictive routine ?
PST1-4   float power saver time parameters 1-4 (4 variables)
PSD1-4   float power saver temp reduction parameters 1-4
PSS1-4   y/n   chosen power saver option (4 exclusive options)

I don't need pop ups, really just a smple form.

Hope this makes sense, sorry about the broken Clarification - didn't
mean to hit "post" when I did, part way through.

I have little feel for what is hard or not in this area, so don;t be
afraid to say if I am hoping for too much !

Have a good weekend.


Clarification of Answer by theta-ga on 19 Aug 2005 11:53 PDT
Hi hyco-ga,
   As per the specs you listed above, I have created the required GUI
interface. You can download a zip file containing the project from:
         - RapidShare.De:
   To keep things simple, I have included the .lib, .h and the .dll
files for the USB board API in the same folder as the project files.
The exe will require the dll to be in the same folder to run properly.
   The code contains three main units(.h/.cpp):
   1. ControllerGUI: This contains the code to setup a Windows
application. This file is created and maintained by the Borland C++
IDE, and you will not need to modify it yourself.
   2. frmMain: This contains all the code for the actual form that we
use. It  contains all the code for reading in the user input from the
form to the relevant data structure. It also contains the code
required to display the outputs to the user. You will need to modify
this if you want to change the GUI or the event handling code.
   3. Controller: This class contains all the code that reads and
writes data to and from the USB board. It also contains a method
called Process() which is supposed to contain the code to process the
data as per your requirements, and then store the user outputs in the
relevant data structure. This is the method where you will need to add
the code for the processing you need to do.

Control Flow:
  - You start the app by running the .exe
  - You select the card to open by checking and unchecking the
relevant jumpers, as specified in the manual. By default, the selected
card address is 0.
  - Click on the 'Open' button to open the link to the USB Board. Once
the link is opened, this button becomes the 'Close' button. If you
click on it again, it will close the link to the USB board.
  - Once you open the connection with the board, the GUI for providing
user inputs and displaying user outputs is displayed.
  - By default, all input variables are set to 0. You can modify them
as per your needs, and then press the 'Set' button to store them in
the relevant data structure for use in further calculations.
  - I have made the polling interval for the board configurable. By
default, it is set to 1000 milliseconds. You can set it to any
required value by entering it in the textbox at the bottom right of
the screen.
  - Press the 'Start Polling' button to start polling data from the
board. The app will read in the data, preform the required processing
(as per the code you add), and display the output data on the screen.
It will continue doing so until  you click the 'Stop Polling' button.

Again, since I do not have access to the actual hardware, i was only
able to perform limited testing on the code. Please try it out, and if
you find any issues, we can work through them together.
The code is reasonably well documented, and you will be mainly adding
code to the Controller class to perform the processing you require.
Look at the Process() method of that class. Also you will need to
provide the code for calculating the TempC output variable. Right now
I just set it to 0.

Just try out the code, and if you need any clarifications, I'll be right here!
Hope this helps. 
hyco-ga rated this answer:5 out of 5 stars and gave an additional tip of: $100.00
Outstanding answer ! all I expected was some advice but I was supplied
with a documented program that works perfectly, even though it was
written without access to the hardware it controls. It'll take a while
for me to work through the code, but I could never have done this

Subject: Re: Calling DLL procedures from a simple C++ program
From: theta-ga on 16 Aug 2005 12:29 PDT
Hi Hyco-ga, 
 I've been busy with some personal work the last few days. Just wanted
to let you know that I willstart work on the GUI part tomorrow.
 Sorry for the delay.
Subject: Re: Calling DLL procedures from a simple C++ program
From: theta-ga on 22 Aug 2005 20:40 PDT
Hi Hyco-ga,
  Have you had time to test out the GUI app?
  Let me know if it needs any modifications.
Subject: Re: Calling DLL procedures from a simple C++ program
From: hyco-ga on 23 Aug 2005 00:05 PDT
Sorry  - will get back to you later today (meeting all yesterday and
this morning too). Have downloaded and it runs, so very promising.
Need a spare half hour to study, will do before leave tonight (UK


Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  

Google Home - Answers FAQ - Terms of Service - Privacy Policy