LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use CVI to create a wrapper DLL for a MATLAB DLL?

I am trying to figure out if it would be possible to use LabWindows/CVI to create a wrapper DLL for a MATLAB DLL to be called by LabVIEW.  I have MATLAB functions compiled to a DLL, and reading on the forums I need to create a wrapper in C / C++ to allow LabVIEW to be able to call the DLL.  This is to bridge the differences between LabVIEW data types and MATLAB data types (e.g. mxArray).  This is in reference to the following post:
 
"dll, matlab an LadVIEW" [sic]
 
When trying to reference the MATLAB generated files, I get errors such as "Read error." and "Aborted load of library 'c:\temp\dlltest.lib' "
 
I am going the MATLAB DLL route since I will be distributing my application to computers that will not have MATLAB installed.  I am also expecting this to be faster than using ActiveX (with the MATLAB run-time libraries) or through file sharing with a MATLAB EXE, which coincidentally runs fine as a standalone.  Since I am performing on-the-fly analysis, writing the data to disk and then reading it from disk through the EXE is not the desired approach.
 
Any assistance or suggestions would be appreciated!
 
Thanks,
Wilbur
0 Kudos
Message 1 of 7
(4,636 Views)

Or, does CVI need the .LIB file generated in a certain format?  The errors I am getting seem to suggest that CVI does not like the MATLAB .LIB file.  I do have some flexibility with how MATLAB generates files, but MATLAB technical support indicates it is a CVI issue.

Thanks in advance for assistance in this matter. 

0 Kudos
Message 2 of 7
(4,618 Views)
Hi, Wilbur.

Yes, you can definitely load an external DLL in CVI and then build a DLL for use in LabVIEW as long as you know what sort of data types to use in CVI. (Matlab probably has a header file somewhere that defines the data types for you.) To load the Matlab DLL, just use the LoadExternalModule method.

Good luck!
Sarah K.
Search PME
National Instruments
0 Kudos
Message 3 of 7
(4,617 Views)
Hi Sarah,
 
Thanks for your assistance with my issue.  When I try to build a DLL from CVI and include a MATLAB generated .LIB file, I have the following build error:
 
2 Project lnk errors
 --Read error.
 --Aborted load of library "c:\path to file\simple_dll.lib".
 
Do you think this is because the MATLAB .LIB file is unreadable to CVI?  If so, is there a format that it needs to be in to be compatible?  Alternatively, I am not able to create the import library using the Options >> Generate DLL Import Library because various symbols were not found.  Since the LIB file is provided, I am thinking I can use that instead of creating my own, as referenced in KB 1ZQDQPY5.  I do have the header files that define the datatypes, but I am not certain if I have all of them (the only error I see right now is the read error issue).
Thanks,
Wilbur
0 Kudos
Message 4 of 7
(4,611 Views)

Have you tried changing the compiler compatability mode? Don't have access to my CVI at the moment but from memory (often dangerous!) you can set the mode to be either MS or Borland - I think this also affects how CVI interprets the .lib file. Try changing it and see if CVI is happier with the MATLAB .lib file.

JR

0 Kudos
Message 5 of 7
(4,593 Views)
Hello wilbur,

I would check out the comments on the following discussion forum post: Linking Matlab generated .lib files

It includes various suggestions on how to work around this issue.

Thanks.
Wendy L
LabWindows/CVI Developer Newsletter
Message 6 of 7
(4,587 Views)
Hi Wendy,
 
Thanks for the link!  That sounds to be my exact issue.  I'm not sure how I missed that on my various searches, but I will follow up on that for my quest to call MATLAB DLLs with LabVIEW.
 
Thanks to JR also for the suggestion to try the compatibility mode.
 
Thanks,
Wilbur
0 Kudos
Message 7 of 7
(4,580 Views)