LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Some very basic questions about calling a DLL in C[VI] code.

Hello everyone!

 

I'm sorry if this a really simple concept. I've come from a background of embedded systems, so DLLs are something I haven't really played around with much. Regardless. I'm developing an application in CVI for a project, and I generated a DLL that I want to use in Visual Studio 2013. I was able to compile it and it output the expected *.dll file. My question however is how do I properly import that *.dll into the CVI IDE? I did google and search the forums and I didn't find what I needed exactly.... I did find however this link: <http://www.ni.com/white-paper/8503/en/>. I did read through it all, and I think I'm going to try and use Implicit Linking. In the link it does detail 3 steps: 

 

  1. Include the import library (.lib) in your LabWindows/CVI project
  2. Include the header file that contains the function prototype in your code using #include
  3. Call the function in your code like any other function

I was able to easily complete step 1.. Now I'm on step 2. The headerfile that contains the function prototype of my code...I was looking at examples, do I just call the dll file as a .h file now? It seemed that way from what I saw. Do I need to output a header file for the DLL some how? Does the CVI compiler automatically reference that .h file with the lib that was imported? 

 

Then in step 3...do I call the functions like they're in another file in the project? Just call the function as usual with the type and then feed the variables into the function and so on?

 

 

Sorry if this is a really rudimentary question.

 

 

Thanks in advance!

 

~Andrew

0 Kudos
Message 1 of 5
(4,908 Views)

The header file definitely isn't the .dll renamed! While creating the .dll, your development environment (don't know which one you've used) should create both a .lib file and a .h file that you must use in your project if you want to go the static linking way. I see you've found the .lib file: the .h file should be available as well, possibly in the same path. The include file lists all the definitions for variables and functions exposed by the dll.

 

As per step #3 the answer is yes: you simply call .DLL functions like any other function in your program. At the bottom of the tutorial you've linked there is a link to a Developer Zone Example that is a complete CVI project that uses a .DLL: you may take this as a sample framework to study.



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 5
(4,881 Views)

RobertoBozzolo,

 

Thanks for the reply. I created the DLL file in Visual Studio 2013. I did look thorugh and I did not see any output .h files related to that.

 

I then went and changed the output type to .lib for a static library. Still no .h files.

 

Is it something I'm doing in the configuration? I keep searching the internet and this forum, and I didn't see anything pertaining to my issue in this regard.

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

No, the .h file is not created automagically by the IDE when building a DLL. When creating the DLL, you have to think about which function declarations and other stuff  like type definitions  should be visible to the DLL user.  Put that stuff into a header file.  That header file is usually also included into the source code for the DLL to ensure that the dll uses the same defintions as  the user. 

When using Visual C++ for  creating the DLL, there are some addtional things to think about:

Make sure that you don't create "managed code". And make sure that you create a C compatible  DLL  because Visual C++ is also a C++ compiler. If you are using C++ features like i.e function overloading  in the interface header file for your DLL, it will not be C compatible.  But don't ask me for more details. I'am not a Visual C++ user.

0 Kudos
Message 4 of 5
(4,835 Views)

Also, if you're building a 32-bit dll, make sure that the function prototypes in your header file specify the calling convention of each function (cdecl or stdcall). If you don't specify it, you run the risk of different compilers picking different defaults with you then ending up with some hard-to-debug crashes.

 

 

0 Kudos
Message 5 of 5
(4,811 Views)