My request isn’t that complicated: All I want to do is write a little console application in C++, that allows me to test the basic functions of the K8055, like SetDigitalChannel();
I’m using Windows XP.
I have some experience in programming in c++ (hello world, cin, cout, calculations, using functions, and that’s about it), but not with DLLs. I downloaded the zip-folders, that are available on velleman.be for the K8055, and tried to use the headers, that are included in there. I tried something like this:
#include <iostream>
#include <windows.h>
#include <Commctrl.h>
#include "resource.h"
#include "K8055D_C.h" //well, I just included everything, that was included in the demo-programm K8055_C.cpp
using namespace std;
int main(void)
{
char c_wait;
OpenDevice(0);
SetDigitalChannel(5); //LED 5 shoud light up
cin >> c_wait; // just to wait until you press a button
CloseDevice;
return 0;
}
Compiling with MinGW 5.1.4 gave me the following:
What am I doing wrong? Could someone please give me a simple example for using DLLs right, including the right headers, etc…
well, talking to myself…
I found the solution (Just in case, someone else tries the same):
The code wasn’t that bad, but all I needed to include was #include and #include “K8055D_C.h”
When compiling with MinGW, I had to tell the compiler/linker, where to find the according K8055D_C.lib file. That worked with
g++ main.cpp -L"C:\test3" -lK8055D_C
(Of course, the lib-file is in my case in the folder C:\test3)
meaning of the syntax:
-L: where to find the lib-file, in which directory
-l: which lib-file tu use
K8055D_C.h is the header file which contains the function declarations for the K8055 dll, eg. it tells (declares to) your compiler which functions are available.
Hence, including K8055D_C.h makes functions available to you and lets you use them, without telling your compiler how they work or where they come from (the compiler doesn’t know yet that those functions are supposed to be coming from K8055D_C.dll).
Next, you need some way to tell the compiler that these functions are not to be implemented by you, but have already been implemented inside a dll. That is where the K8055D_C.lib comes into play, it contains the same list of functions you have in the header file, but it also tells your compiler where to find the implementation of those functions inside the dll.
So, now the compiler knows which functions exist and how to call them.
This is the compiler saying that you declared the function (it’s in the header file), but it can’t find an implementation anywhere (because the .lib file is missing that contains the link to the dll).
Function calls always need paranthesis: CloseDevice();
But I guess it’s just a simple typo
Thank you very much for the very nice explanation! I have a better idea now of what is going on.
The only thing … Why do you need the declaration of the functions twice, once in the header and once in the library? Seems to be redundant. Anyway, thanks again.
The header file is for you and your compiler so you can use the functions: “Function A exists, and this is what it looks like”
The lib file doesn’t really matter to you, but is important for the compiler/linker. It indicates the entry point of each function inside the dll (eg, at which address or byte in the dll can i find this function).
There will always be two parts, one part with declarations (.h), one part with definitions (.cpp, .lib).
Hi,
I am relatively new to C++ and using Visual C++ Express 2008. I have included the .h and .lib within my project and successfully compiled the following code adapted from the project at the beginning of this topic.
You get neither a compile time (linker) Error - nor a runtime error, am I right?
If so - check:
a.) If the board has set the correct addres
b.) If the board is recognized by your PC. (as HID).
For be go to Controlpanel / System.
Choose hardware / Device manager and look for the devices there.
In the treeview have a look for "Input devices (Human Interface Devices).
There may be a lot of – start from the end of the list an look at every USB-HID type.
Double click - and choose Details.
You shall find an entry like USB\VID_10CF\PID_550x…
If you found such an entry you can tell the address of your device by the x value.
0 == Board(0)
1 == Board(1)
and so on.
By the way - on an USB problem (for me) Digital out 8 lights.
Normal state is Power Led lights - all others are off (after plugin).
Release and Debug builds in Visual Studio are compiled/linked in different directories. Make sure your K8055 dll is located next to your executable. A missing dll would cause runtime errors though
hi, can you please tell me what exact program are you usig for the previusly given code.is it borland c++? which version?I thied to use it and it keeps giving me all sorts of errors. i use borland c++ 5.02.
thanks
Here’s the link to download the K8055 software package with examples and with new K8055D.DLL: velleman.eu/downloads/files/ … rsion4.zip
Please see the example in the subfolder \examples\K8055DemoDevC
There is a simple C++ console application for Bloodshed Dev-C++.
I think you may easily modify the source code for Borland C++ compiler.
This example is using the run time (explicit) DLL linking. No need for the .LIB file.
Please check this link how to use GetProcAddress: http://msdn.microsoft.com/en-us/library/64tkc9y5.aspx
Before running the example project, please copy the file K8055D.DLL from the folder \DLL_v4.0.0.0 to the \Windows\System32 folder.
In 64-bit environment copy the file to \Windows\SysWOW64 folder.