DLL import in MinGW

A

André Hänsel

Hi,

I am trying to use the vendor-supplied DLL for a K8055 interface board
in my application. The vendor provides the DLL (in a Visual Basic and
a C flavour), a .lib file and an .h-file that looks like this:
#ifdef __cplusplus
extern "C" {
#endif

#define FUNCTION __declspec(dllexport)

FUNCTION long __stdcall OpenDevice(long CardAddress);
FUNCTION __stdcall CloseDevice();
FUNCTION long __stdcall ReadAnalogChannel(long Channel);
....

Those files are available here: http://www.velleman.be/ot/en/download/files/#24

Here's what I've done:
I changed the __declspec(dllexport) to __declspec(dllimport). There
was a function defined as bool, I changed it to int.

Then I included the .h-file and called the funtion.
#include "K8055D_C.h"

main()
{
long retval = OpenDevice(0);
return 0;
}

I used the following command line to build the program:
d:\MinGW\bin\gcc -c test.c
d:\MinGW\bin\gcc -o test.exe test.c K8055D_C.DLL

I get this error:
ccCG0kpK.o:test.c:(.text+0x32): undefined reference to
`_imp__OpenDevice'
collect2: ld returned 1 exit status

What was my mistake?

Regards,
André
 
I

Ian Collins

André Hänsel said:
Hi,

I am trying to use the vendor-supplied DLL for a K8055 interface board
in my application. The vendor provides the DLL (in a Visual Basic and
a C flavour), a .lib file and an .h-file that looks like this:

Your best bet is to ask on a windows programming group.
 
J

jacob navia

André Hänsel said:
Hi,

I am trying to use the vendor-supplied DLL for a K8055 interface board
in my application. The vendor provides the DLL (in a Visual Basic and
a C flavour), a .lib file and an .h-file that looks like this:
#ifdef __cplusplus
extern "C" {
#endif

#define FUNCTION __declspec(dllexport)

FUNCTION long __stdcall OpenDevice(long CardAddress);
FUNCTION __stdcall CloseDevice();
FUNCTION long __stdcall ReadAnalogChannel(long Channel);
...

Those files are available here: http://www.velleman.be/ot/en/download/files/#24

Here's what I've done:
I changed the __declspec(dllexport) to __declspec(dllimport). There
was a function defined as bool, I changed it to int.

Then I included the .h-file and called the funtion.
#include "K8055D_C.h"

main()
{
long retval = OpenDevice(0);
return 0;
}

I used the following command line to build the program:
d:\MinGW\bin\gcc -c test.c
d:\MinGW\bin\gcc -o test.exe test.c K8055D_C.DLL

I get this error:
ccCG0kpK.o:test.c:(.text+0x32): undefined reference to
`_imp__OpenDevice'
collect2: ld returned 1 exit status

What was my mistake?

Regards,
André

The function is declared stdcall but the name of it is assumed as
not stdcall.

Stdcall functions will be decorated with an @ and the byte size of the
stack arguments.

For your specific case the compiler should generate a call to
__imp__OpenDevice@4

but it is actually generating a call to just OpenDevice.

This means that probably you do not included the header file
in your compilation.
 
R

Rafael

André Hänsel escreveu:
Hi,

I am trying to use the vendor-supplied DLL for a K8055 interface board
in my application. The vendor provides the DLL (in a Visual Basic and
a C flavour), a .lib file and an .h-file that looks like this:
#ifdef __cplusplus
extern "C" {
#endif

#define FUNCTION __declspec(dllexport)

FUNCTION long __stdcall OpenDevice(long CardAddress);
FUNCTION __stdcall CloseDevice();
FUNCTION long __stdcall ReadAnalogChannel(long Channel);
....

Those files are available here: http://www.velleman.be/ot/en/download/files/#24

Here's what I've done:
I changed the __declspec(dllexport) to __declspec(dllimport). There
was a function defined as bool, I changed it to int.

Then I included the .h-file and called the funtion.
#include "K8055D_C.h"

main()
{
long retval = OpenDevice(0);
return 0;
}

I used the following command line to build the program:
d:\MinGW\bin\gcc -c test.c
d:\MinGW\bin\gcc -o test.exe test.c K8055D_C.DLL

I get this error:
ccCG0kpK.o:test.c:(.text+0x32): undefined reference to
`_imp__OpenDevice'
collect2: ld returned 1 exit status

What was my mistake?

Regards,
André

Have you linked the lib with the project?

Why change bool to int? Cant you typedef or enum something, somehow?

If the library was intended to work with c, why there is a boolean type
on sources anyway? Go call the software vendor.

Let the declspec to another round.

Regards
Rafael
 
A

André Hänsel

The function is declared stdcall but the name of it is assumed as
not stdcall.

Stdcall functions will be decorated with an @ and the byte size of the
stack arguments.

For your specific case the compiler should generate a call to
__imp__OpenDevice@4

but it is actually generating a call to just OpenDevice.

Sorry, sorry, I think I pasted the wrong snippet. The error I pasted
was from the try in which I removed the __stdcall. Anyway I get the
same error with and without __stdcall, in the one case mentioning
__imp__OpenDevice and in the other case mentioning
__imp__OpenDevice@4.
 
A

André Hänsel

André Hänsel escreveu:















Have you linked the lib with the project?

Why change bool to int? Cant you typedef or enum something, somehow?

If the library was intended to work with c, why there is a boolean type
on sources anyway? Go call the software vendor.

I think it was made for C++ but that should be no problem with a DLL,
should it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top