LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

LabWindows 2017 DLL project - can it generate a .h header file of the functions?

Solved!
Go to solution

Is it possible to make a DLL project build a .h header file of all the functions included in the DLL? This document says there is a "Build -> Generate Prototypes" capbility, and maybe that's as good as it gets -- going by file by, generating and copying them out?

 

How Do I Create Import Libraries for a DLL in LabWindows™/CVI™ - NI

0 Kudos
Message 1 of 9
(1,582 Views)

Some details:

 

I have created two DLLs - one handles I2C communications and could be used at the lowest level for manually building message payloads and writing/reading them to devices.  The second DLL is higher level messaging functions. It provides functions to write/read specific messages and uses the I2C DLL to do the actual transmission.

 

Right now, I am exposing "everything" in the DLL using:

 

Build -> Target Settings: Exports

LabWindows-DLLExportAll.png

 

This seems lazy and sloppy since it publishes all kinds of internal helper functions that the end-user should not use. I have not learned how to mark specific functions to include, yet, but need to.

 

I wrote my source code to be very modular, with messaging split up in to many different C/H files for just their specific parts. For the DLL, I read "best practices" prefer there to be a DLL and one "kitchen sink" header file that gives the user everything they need to use anything in the DLL.

 

I did this by copy/pasting all needed sections from my dozens of original header files in to one header for the DLL.

 

Surely there is a better way, since keeping two files in sync most certainly will lead to a problem at some point down the line.

 

Is there some kind of tool that could look at all "exported" functions in a DLL project and create a header file with prototypes and any structures, defines, etc. they need?

0 Kudos
Message 2 of 9
(1,533 Views)
Solution
Accepted by topic author AllenInIowa

Short answer is: no.  It's up to you to create that header file.  For my own DLLs, I've typically segregated the prototypes into backend library functions, and then customer-facing functions in the shippable header file.

0 Kudos
Message 3 of 9
(1,490 Views)

I ended up writing (actually, ChatGPT did most of it) a PowerShell script to scan all my files, look for EXPORT tags, and put them (and structures, and defines) in a mega .h file.  It will contain alot of things that don't really need to be there, but better too much than not enough to build with.

 

It would be nice if there was a way to use the export macro and place it on/around structures, defines, enums, etc. and have LabWindows export all of that in to the file that goes with the DLL. I wonder if any tool does that (Visual Studio, maybe?)  Doing it all by hand in 2023 sure seems surprising to me.

0 Kudos
Message 4 of 9
(1,457 Views)

@AllenInIowa wrote:

 

It would be nice if there was a way to use the export macro and place it on/around structures, defines, enums, etc. and have LabWindows export all of that in to the file that goes with the DLL. I wonder if any tool does that (Visual Studio, maybe?)  Doing it all by hand in 2023 sure seems surprising to me.


Not really to me. Generally someone has to design the library and part of the design is to define what is user accessible exported functionality and what should be library internal implementation details. Doing a simple parser that can go through all your source code to find custom tags to use for an export table, similar to document help tags would not be that difficult to do. The problem is however that everybody has very specific ideas how that should work (well everybody but those who would like to depend on ChatGPT and friends and take whatever is recommended by them at face value). 😀

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 9
(1,407 Views)

Since DLLs already have a standard of saying which functions to 'export' and make available in the DLL, it seems very logical that a similar mechanism could be used to specify what gets 'exported' in to a header file, as well.

 

I am an embedded programmer, so the only Windows programs I have ever made have been GCC command line stuff, and my work project using LabWindows. Maybe coming at it from a complete outsider explains my difference in perspective.

 

Of course, none of this applies to "kitchen sink programmers" who have massive header files with everything in them. If I had done that, it wouldn't be an issue 🙂

0 Kudos
Message 6 of 9
(1,391 Views)

@AllenInIowa wrote:

Since DLLs already have a standard of saying which functions to 'export' and make available in the DLL, it seems very logical that a similar mechanism could be used to specify what gets 'exported' in to a header file, as well.


Well, for DLLs there are at least two "standards" how to specify what functions should be exported. The old Windows 3.x way of using a specific *.def that lists all the functions that need to be added to the export table. You as programmer are responsible for creating that!

 

Or the later Microsoft proprietary way of using a __declspec(dllexport) attribute for the functions that should be exported. Compilers wanting to be compatible with MSC usually support that too, including Windows ports of GCC such as MingW. You should however not forget to change all these to __declspec(dllimport) when wanting to use the header to compile a project that needs to link to that DLL. It all can be solved with pre-processor magic but it is not exactly pretty.

 

And yes you can of course create a tool that will scan for symbols with these attributes and make some sort of amalgated header file. But each programmer has again their own ideas how that header file should be formatted, so it is easier to let that programmer do this themselves if they feel so strong about needing that. 😁

 

The programmer of a library should provide a public (set of) header file(s) and he will know how he wants that formatted. If he didn't do that, it should not be the compilers tools task to try to guess what should have been done by the library developer.

 

A public set of header files belongs to any sort of library as an according manual that documents each public accessible function, with the parameters and some explanation what each parameter means. Without these a library is generally almost worthless, no matter how advanced its inner workings are.

Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 9
(1,386 Views)

@rolfk wrote:

A public set of header files belongs to any sort of library as an according manual that documents each public accessible function, with the parameters and some explanation what each parameter means. Without these a library is generally almost worthless, no matter how advanced its inner workings are.


Can you please tell that to a vendor of mine?!  I won't mention names, but I recently bought a product from them, which was advertised to come with a DLL for serial control.  I got the DLL, and no header.  Got a PDF with all the functions and description.  It's up to me to create my own header, apparently.  

0 Kudos
Message 8 of 9
(1,376 Views)

@ElectroLund wrote:

@rolfk wrote:

A public set of header files belongs to any sort of library as an according manual that documents each public accessible function, with the parameters and some explanation what each parameter means. Without these a library is generally almost worthless, no matter how advanced its inner workings are.


Can you please tell that to a vendor of mine?!  I won't mention names, but I recently bought a product from them, which was advertised to come with a DLL for serial control.  I got the DLL, and no header.  Got a PDF with all the functions and description.  It's up to me to create my own header, apparently.  


I can't command vendors. If they really only do as you say, they are of course not worth the money you paid for the device, but such is life. Now, unless it is a really complex device like DAQmx for instance would be, there should be maybe one or two dozen functions at most that you need to call. Copy pasting that from the PDF into a header file is almost certainly the least of your problems. Understanding the API and figuring out how to call it will be a lot more work and that is unavoidable even if you had the header file.

Rolf Kalbermatter
My Blog
0 Kudos
Message 9 of 9
(1,359 Views)