From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating DLL under MS-Visual Studio 2010SP1 (MSVS2010SP1) for LabView2011 (LV2011)

Hi,

 

in the net I found a description how to build a VS-Studio-CPP-DLL and I found an example in the LabView-Installation Directory:

C:\Program Files\National Instruments\LabVIEW 2011\examples\dll\hostname

 

But both where not sufficient to compile a DLL.

 

Here is some information, for beginners like me:

  1. I had to install SP1 for MSVS
  2. Define a environment variable "CINTOOLS_DIR" on OS-Level to tell MSVS where the "CINTOOL" folder is located
    (I hope there is a more clever solution, but I have not figured out, how to define a environment variable/macro inside MSVS)
  3. Add a linker directive inside the *.cpp-file
    (I find this is not the best way to do it, but I do not know where to define it elsewhere)
    It is the linker directive:
    #pragma comment(lib, "user32.lib")
    It is necessary to avo8id the error: "LNK2001: unresolved external symbol __imp__MessageBoxA@16"

I also tried to implement a dynamic array (with variable array size).

I failed 😞 I tried to utilize the variable "ul_reason_for_call" of the function "DllMain", but I have not figured out

to implement it properly and I also failed to figure out, how to transfer the array size to the command:

variable = new variable type[array_size].

 

I also tried to compile my example with the current VS (MSVS2013), but that does not work,

is this maybe an incompatibility between CINTOOL-LV2011 and MSVS2013?

 

The attached ZIP-File includes a whole MSVS-Project & a LV2011-VI to test the DLL.

I hope it is helpful for others.

 

If someone has figured out how to compile my example with MSVS2013 I'm interested to know what needs

to be done.

 

Kind regards,

 

Stefan

 

 

 

0 Kudos
Message 1 of 5
(3,414 Views)

I was able to rebuild the project under MSVS2013 and export a project template.

But works only, if MSVS2010SP1 is installed as well on the machine,

MSVS2013 detects that is is a MSVS2010SP1 project and treats is in a compatibility mode.

In the "Solution Explorer" it is visible as MSVS2010-project.

 

Don't klick "Upgrade C++ Compiler and Libraries".

 

MSVS2013 is not compatible with the "CINTOOL"-Libraries shipped along with LV2011.

 

The attached ZIP-file includes a much reduced example-cpp and it includes a more simple VI.

The problem I observed between my former project and the project exported as template was:

"This application has failed to start because MSVCR100D.dll was not found.

Re-Installing the application may fix this problem."

 

I found the following:

http://forums.ni.com/t5/LabVIEW/MSVCR100D-dll-was-not-found/td-p/1225960

http://stackoverflow.com/questions/7731850/cant-switch-from-release-to-debug-configuration-in-visual...

 

To change the Build-Configuration, go to the main menu -> "BUILD" -> "Configuration Manager"

2015_11_30_09_36_22_Configuration_Manager.png

 

After this step I exported a second time a template and in the new template the build configuration was again set back to "Debug":

To me it seems that the configuration, if it is a "debug" or a "release" version, is lost through the process of exporting as template.

 

Stefan

 

 

 

 

 

0 Kudos
Message 2 of 5
(3,374 Views)

The correct Visual C configuration is always a bit tricky and the various configuration dialogs are sometimes rather involved and the settings not necessarily in the place one might look for them first.

 

All the things you have done are a possible solution but have their own issues.

 

1) #pragma comment(lib, "user32.lib"): I personally add additional library dependencies always to the according list inside the linker settings in the configuration dialog. #pragmas are seldom very portable across compilers and sometimes even not across compiler versions.

 

2) as to adding additional directories for header files and libraries it's usually better to add them to the according lists in the compiler and linker settings for your project or if you happen to develop a lot of LabVIEW external shared libraries, to add them to the Visual C settings under Tools->Options->Project and Solutions->VC++ Directories.

 

The NI examples are not meant to teach you how to use a particular C compiler. They really can't as Visual C is notorious for changing many of its configuration dialogs and their location between every version. Other C compiler toolchains have their own way of setting them up with gcc being probably the most low level way where everything is done through the cmmand line and/or the make tool of your choice. The examples assume you know your C compiler toolchain sufficiently to configure it for creation of DLLs and to know where to add the necessary configuration settings yourself.

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 5
(3,360 Views)

Hi Rolf,

 

thanks for your reply. I am happy that you confirm: the MSVS-environment is a jungle.

And suggestions one may find in the net are sometimes not useful, if one uses MSVS.XXzz instead of MSVSXXyz.

You wrote where I can add a environment variable for an Include-Directory, but I fail to find the right

place to do so in MSVS2013, I still relay on the environment variable specified on operating system level.

With your hint I was able to remove the linker directive in the C-code, thanks!

In MSVS2013 you can find it under:

Project -> Properties -> Linker -> Input -> Additonal Dependencies

There you have to options:

a.) add an aditional library (Seperator char is a semicolon ";")

b.) switch on the option: "Inherit from parent or project defaults"

Additional Dependencies MSVS C++

 

Now comes the task to fill the DLL with some content, for this I will start a seperate topic.

 

Stefan

0 Kudos
Message 4 of 5
(3,327 Views)

It's not an tnvironment variable at all in MSVC. Instead it is in the IDE settings. I still use MSVC2005 for most of my Windows C work so I can't tell you where exactly to look in your version. For me it is in the Tools->Options menu. In there is a section "Projects and Solutions" and there is a "VC Directories" selection. In this dialog you can set the various paths Visual C should use for binary executable files, include files and library search paths etc. Add as many paths to it that you commonly use in your MSVC development. I have added my LabVIEW cintools directory to both the Include and Library paths.

 

MSVC2005 Options.png

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 5
(3,292 Views)