关于LabVIEW产生的DLL被C调用的问题1 LabVIEW的工作1.1 工程项目从LV8.0开始,想要生成exe、安装程序或DLL就必须首先创建1个工程,然后把所有有关的VI全部添加到工程中,如图1:图1 LV项目为了使目录结构清晰,最好把最后需要输出的VI放置在一起,把子VI放置在一起,如图1中,虚拟目录Top Level Vis用来存放3个输出的VI(可以把它想像成DLL中的函数)、虚拟目录Dynamic Vis存放子VI、虚拟目录Support Files存放支持文件(位图、光标等)。
1.2 VI设置如同在LV中一样,有些VI完全是作为计算模块使用的(调用时不会弹出界面,如图1中的acquire.vi、analyze.vi),而有些是用来显示界面的(调用时弹出对话框,如图1中的present.vi)。
那么如何设置1个输出VI是否显示界面呢?想要产生界面调用的函数,请配置Window Appearance(如图2),然后确保红线圈住的地方必须被选中:图2 VI界面设置1.3 输出配置(Build Specification)右击Build Specification选择New->DLL,弹出DLL输出配置对话框,其有以下对话框需要配置:1.3.1 基本信息(Information)图3∙Build specification name—指定唯一的生成模板名称(出现在项目管理页面中),用以和其他模板相区别∙Target filename—指定输出的DLL名称∙Destination directory—指定生成文件的输出路径∙Build specification description—描述该生成模板的相关信息。
1.3.2 输出源指定(Source Files)图4∙Project Files窗口—显示项目窗口My Computer下列举的项目(如图1),使用图4中的左/右箭头可将My Computer下列举的项目移入/移出Exported VIs和Always Included窗口。
∙Exported Vis窗口—指定DLL的输出函数(VI),至少要指定1个输出VI。
选定移入的VI,Define VI Prototype按钮可使用,并且在点击后弹出如图5所示对话框:图5 接口原型定义对话框该对话框可用于调整对应VI的C++接口。
∙Define Prototype按钮—在选择了输出VI后被激活,该按钮用于启动接口原型定义对话框,用于修改输出VI的接口定义。
∙Always Included—指定DLL中所必需的动态VI和支持文件。
o动态VI:通过VI Server调用的VIo支持文件:非VI文件,比如驱动、文本文件、帮助文件、.NET组件等DLL 使用的文件注意下列对象不可移入Exported VIs窗口、Always Included窗口:Exported VIs∙多态VI(Polymorphic Vis)∙控件(Controls)∙私有数据控件(Private data controls)∙非VI文件(Files that are not VIs, such as text, image, or .mnu files)∙库文件(LabVIEW类、XControls)∙全局变量(Global variables)Always Included∙私有数据控件(Private data controls)若将库文件(LabVIEW类)移入Always Included窗口,LabVIEW将标记库内所有项目。
可将库内的任意一项指定为输出VI。
但是若将XControls移入Always Included窗口,LabVIEW将在生成过程中包含所有与XControls相关联的项目,这些项目都不能成为输出VI。
1.3.3 目标(Destination)图6∙Destinations窗口—指定生成文件存放目录,列表中的第一项就是Information窗口(图3)里的Target filename项目。
∙Add Destination(+按钮)—在Destinations窗口中添加1个自定义目录∙Remove Destination(X按钮)—在Destinations窗口中删除1个选定的项目∙Destination label—指定Destinations窗口所选项目的名称。
在Source File Settings窗口中,这些项目作为Destination下拉菜单的项目。
∙Destination path—Destinations窗口所选项目的指定目录或LLB。
若更改了基本信息里Target Filename对应的路径(图1),则所有子目录都将相应发生改变。
注意:为了避免出错,需保证路径最长不超过255字符∙Destination type—指定目标类型,对于目标项和支持目录,其设置不可修改o Directory—指定目标为路径Preserve disk hierarchy—保存定位到该目标路径的所有文件之前的目录结构o LLB—指定目标为LLB.∙Add files to new project library—是否指定想要添加文件形成新的库文件o Library name—包含指定文件的新库文件1.3.4 源文件设置(Source File Settings)图7∙Project Files—显示项目窗口My Computer下列举的项目(如图1)∙Inclusion Type—显示LabVIEW在生成过程中如何包含所选项目。
这个选项与Source Files窗口中项目所指定的类型有关,比如在Always Included窗口内的项目,其选项= Always Included。
如果选择了1个目录,则目录内所有项目的Inclusion Type属性为:o Service VI—包含项目作为service VIo Always Included—生成时包含项目o Include if referenced—当其他项目引用它是,被包含∙Destination—设置选择项目的目标。
LabVIEW在用户未指定启动VI时开启此功能。
Destination下拉菜单中的项目= Destinations窗口中的Destination label。
默认目标= Same as caller,LabVIEW作为调用者将这些项目放置于相同的目标中∙Sets the destination for the selected item. LabVIEW enables this option if you have not designated the item as a startup VI. The names in the Destination pull-down menu correspond to the options in the Destination label text box on the Destinations page. The default destination is Same as caller and LabVIEW places the item in the same destination as the caller.o Make top level in LLB—Appears when you select a destination that is an LLB.Place a checkmark in the Make top level in LLB checkbox if you wantthe selected VI to be the top level item in the LLB.∙Customize VI Properties—Displays the VI Properties dialog box. Use the dialog box to specify the properties for the selected VI. By default, LabVIEW uses the property settings configured in the VI. Any settings you configure in the VI Properties dialog box override any settings you configured in the Customize Window Appearance dialog box. LabVIEW dims this option for items other than VIs.∙Use default save settings—Saves the VIs using default save settings. The default save setting for the VIs you add to the Exported VIs and Always Included listboxes on the Source Files page is to remove the block diagram.The default for all other VIs is to remove the block diagram and the front panel. Remove the checkmark from this checkbox to change the default settings for each item you select in the Project Files tree.o Remove front panel—Removes the front panel from a VI in the build.Removing the front panel reduces the size of the application or sharedlibrary. If you select yes, LabVIEW removes the front panel, butProperty Nodes or Invoke Nodes that refer to the front panel mightreturn errors that affect the behavior of the source distribution.LabVIEW enables this option if you remove the checkmark from the Usedefault save settings checkbox.o Remove block diagram—Removes the block diagram from a VI in the build.LabVIEW enables this option if you remove the checkmark from theRemove front panel checkbox. If you remove the front panel, you alsoremove the block diagram. As a result, if you place a checkmark inthe Remove front panel checkbox, a checkmark automatically appearsin the Remove block diagram checkbox.∙No password change—Specifies for LabVIEW to not prompt for a password if you use the VI in a build. LabVIEW also does not modify or apply a password you previously applied to the VI.∙Remove password—Removes the password you previously applied to a VI or library. Prior to removing the password, LabVIEW prompts you to enter the current password during the build.∙Apply new password—Applies the password you supply in the text box to a VI or library. Prior to applying the new password, LabVIEW prompts you to enter the current password during the build. Enter the password in the text box below the Apply new password option.∙Rename this file in the build—Appears when you select a file in the Project Files list. Renames the selected file. Enter the new name of the file in the text box.∙Set destination for all contained items—Appears when you select a folder in the Project Files tree. Place a checkmark in the checkbox if you want to set the destination directory for the items in the selected folder.Note LabVIEW places an item set to Same as caller in the directoryof the caller. If you set an item to Same as caller and two differentcallers are in different directories, LabVIEW places the item in thesame directory as the build.∙Set VI properties for all contained items—Appears when you select a folder in the Project Files tree. Place a checkmark in the checkbox if you want to set the VI properties for the items in the selected folder. When you placea checkmark in the checkbox,LabVIEW enables the Customize VI Propertiesbutton.∙Set save settings for all contained items—Appears when you select a folder in the Project Files tree. Place a checkmark in the checkbox if you want to set the save settings for the items in the selected folder.∙Set password for all contained items—Appears when you select a folder in the Project Files tree. Place a checkmark in the checkbox if you want to configure the password for the items in the selected folder.∙Apply prefix to all contained items—Appears when you select a folder in the Project Files tree. Place a checkmark in the checkbox to enter a prefix in the text box and rename all items in the folder by applying the prefix to the existing names.。