From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.



如何传递一个布尔类型的数据到LabVIEW 6.0生成的DLL文件中?



主要软件: LabVIEW Development Systems>>Full Development System
主要软件版本: N/A
主要软件修正版本: N/A
次要软件: N/A

问题: 如何传递一个布尔类型的数据到LabVIEW 6.0生成的DLL文件中?在C语言中没有对应的布尔数据类型,而DLL却需要一个指向LabVIEW布尔量的指针。

解答: 要这样做的话,可以向DLL传递一个指向整型数据类型的指针,用0代表假,1(或者其他任何非0的数)代表真。编译器也许会返回一个数据类型不匹配的警告,但这不会影响程序的正常工作。下面的例子是调用在LabVIEW 6.0中生成的LVbool.dll文件的C代码。如果传递的值是假,该DLL文件返回0,反之返回1。程序会提示用户输入一个数字,0代表的是假,其他数字则代表真。
#include <stdio.h>
#include "LVbool.h"

// This code shows how to pass a LVBoolean to a DLL built with LabVIEW 6.0. To do this,
// pass an int to the DLL using a 0 for false and 1 (or anything but 0) for a true.


int main(void)
{
int var1, var2;
scanf("%d", &var1);
var2 = LVbool(&var1);
printf("%d", var2);
return(0);
}
如上所述,用户如果输入的是0,则DLL返回0,当用户输入55,(一个非0数),DLL则返回1。
C:\TEMP\LVBOOL\DEBUG>bool
0
0
C:\TEMP\LVBOOL\DEBUG>bool
55
1
Note: 上面的程序是在Visual C++中编译的,但你必须把位于<labview>cintools路径中的下列文件添加到你的工程中:


相关链接:

附件:





报告日期: 11/16/2006
最近更新: 11/21/2006
文档编号: 28O9PNQC