LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I use a dll file written in Visual C++ using LabWindows?

I have a dll file that contains an ActiveX Interface to communicate with a camera in the parallel port, written in Visual C++. I have succesfully written a program in Visual C++ that takes pictures, by importing the dll (using the #import directive), and creating an Active X object. Now i want to use the camera in the LabWindows environment. A simple enveloping with
extern "C" {...} in the *.cpp file doesn't work. error messages like "templates cannot be declared to have 'C' linkage", and "C linkage function cannot return C++ class '_bstr_t'" appear when compiling in Visual C++.
Do you have any suggestion?
0 Kudos
Message 1 of 3
(3,866 Views)
CVI uses ANSI C ,if you want to use the dll made in vc ,you must do like this.

1:#include at the first line in your c file of cvi.
2:in your h file, define HINSTANCE yourdll and typedef (*yourfunc)(...) and yourfunc yourcvifunc;
3:yourdll = LoadLibrary(yourc++dll);
yourcvifunc = (yourfunc)GetProcAddress(yourc++dll,"yourc++func");
4:FreeLibrary(yourdll);

notes:your lib must include in your cvi project, and the dll must in the same dir.
0 Kudos
Message 2 of 3
(3,866 Views)
LabWindows/CVI is an ANSI C development environment only and does not support the C++ programming language. Neither of the methods you mention, #import (which is a C++ specific preprocessor for creating classes out of type libraries) or extern "C" {...} (which merely allows you to specify a calling convention for another module's function implementations and doesn't really give you access to a dlls functions anyway) are suitable for accessing the supposed ActiveX Interface residing in your dll from within CVI or a C compiler in general. The dll will have to act as a "registered" ActiveX Automation Server and define the implementation of a COM object that can be referenced through its 'clsid' and 'iid's via the underlying COM system in Windows. Another option you could investigate is creating C style function wrappers for the objects defined in the dll, but this would require alot of work on your part and there is actually a feature in CVI that can help you get around this assuming the dll is a valid automation server.

CVI has an Activex Automation library that basically allows you to do COM object access/manipulation in C fairly easily, and it also has an ActiveX Automation Controller Wizard that allows you to select a registered Automation Server on your system and can automatically create a set of functions that specifically access objects unique to that server.

As far as COM specific programming issues go though, we do not provide technical support for this and if you require more information on this topic you can go to the following website for definitive information:

Link -> http://msdn.microsoft.com/library/

Just search for the Windows SDK information on COM, OLE, ActiveX, and OLE/ActiveX Automation.

For information on how to use the ActiveX Automation Controller Wizard you can look through the documentation of the LabWindows/CVI User Manual around page 3-48, and the ActiveX Automation Library is covered in the LabWindows/CVI Standard Libraries Reference Manual. We also have several online documents/tutorials for CVI that include additional information about this topic at the following link:

Link -> http://digital.ni.com/public.nsf/web/lastweek/D984CF1CA889B809862565FC0078E964?OpenDocument

You can also look at some of the examples in your cvi\samples\activex directory to see how this is implemented with some common applications such as Word, Excel, and Internet Explorer (this is automation involving an .exe, but it can also be done with a dll).

So in short you should look at all of the above references to determine what your dll is actually capable of in terms of use in CVI.

Jason F.
Applications Engineer
National Instruments
www.ni.com/ask
0 Kudos
Message 3 of 3
(3,866 Views)