LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

DLL for LabWindows/CVI 8.0 with bool data type

Solved!
Go to solution

Hello,

 

I want to use a new SWIR camera in LabWindows/CVI 8.0 (WinXP 32bit).

 

The company delivered with the camera a 32 bit dll produced using Microsoft Visual C++ 2010. The .dll, .lib and .h files comprise a working SDK/API (some functions with bool data type)

 

Compiling => Syntax error,   boolean variable is not a data type in LabWindows/CVI 8.0

Generate DLL Import Library => Syntax error

 

I tried to convert bool to char (typedef  unsigned char  bool;) => no more syntax error but the functions does not work.

What can I do ?

 

Martin

0 Kudos
Message 1 of 6
(6,466 Views)

Is the system complaining about BOOL or bool? BOOL is defined in cvidef.h but not always. Try inclunding windows.h befor all other includes: this should enable defining BOOL in your code.

AFAIK 'bool' is not part or C systems: is pertains to C++ instead. Otherwise, it should be defined inside the camera SDK: does it ask you to include some file in the IDE?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 6
(6,446 Views)

Hello Naumann,

 

From your typedef type definition, I understand that the problem is with the 'bool' type not being recognized. The bool type doesn't apply to C, as it was introduced in C++, and can have either the values true or false. Are the functions from the library you are using declared using C++? In C++, the size of bool depends on the compiler implementation you are using.

 

I'm assuming that if the functions are not behaving correctly at run time, the cause for this is the fact that your redefined the bool type to the size of a char, whereas the library that you are using was build with a compiler which represented bool of another size.

 

Your claim that "the functions does not work" is ambiguous. What is the exact symptom of the functions that are not behaving as expected?

Does your problem occur at compile time or at run time?

 

Best regards!

- Johannes

Message 3 of 6
(6,414 Views)

Hello Johannes,

thanks for yoor help. The incompatibility of bool data types seems not resolved with new definition of bool type in my code.

 

Here are additional informations to the problem:

we adapt the bool type in header file to unsigned char in my C-Code:

typedef unsigned char bool;
#define true 1
#define false 0

 

The functions from the library are  declared using C++ ( 32 bit dll produced using Microsoft Visual C++ 2010)

 

Yes, the errors occured  at run time. There are some errors in Debug Output of LabW/indows/ CVI.

 

My test code seems to go wrong when I call PSL_VHR_enable_high_gain_mode(bEnabled), which is the first attempt to pass a ‘bool’ as a parameter. The following statements deliver not right answers of the camera. May be the communication with camera via Ethernet is disturbed ??

(Communication and all functions work well with the Viewer software of producer)

 

Have you an idea ?

In my opinion, the best way would be to change bool to int in the source code of the DLL, but the company don't want to do this up to now.

 

Best regards         Martin

0 Kudos
Message 4 of 6
(6,319 Views)
Solution
Accepted by Naumann

Hello again, Naumann!

 

Microsoft Visual C++ 2010 represents bool using 1 byte, as stated by MSDN: https://msdn.microsoft.com/en-us/library/tf4dy80a(v=vs.100).aspx

I assume that you are importing the C++ functions using extern "C" syntax. Otherwise, because of C++ name mangling you wouldn't be able to link the C++ library against your CVI code.

 

Can you also specify how you are importing the C++ functions?

Also, since you haven't described the problem to be a stack corruption or run-time error, I assume that the C++ library function is called correctly from CVI. Having said this, I tend to believe that the problem isn't actually in the C/C++ interaction mechanism, but in the C++ library. If you would start calling a simple dummy C++ function returning an integer from a simple CVI application that should work, because redefining bool in CVI to 1 byte should ensure that the parameters are passed correctly on the stack.

If you would create a C++ wrapper function that doesn't use bool and calls the intended C++ function, I expect it to return the same result.

 

Maybe you are missing some prior initialization steps required? Does the camera provider also ship any sample code?

 

Best regards!

- Johannes

Message 5 of 6
(6,312 Views)

Hello Johannes,

many thanks for help. Now I'm able to snap an image and save it as tiff. That means the DLL works. The key were your hints and an easy sample code from the company which avoids having to use BOOL parameters. Now I have to proof what statements are wrong and why. There were to much errors from syntax, from camera parameters that are not used in my camera and also from Labwindows/CVI development system. This gives some confusion.

 

Thanks an d best regards    Martin

0 Kudos
Message 6 of 6
(6,237 Views)