Building a Function Prototype

To build a shared library from a text-based programming language, you can build a function prototype in LabVIEW and then fill in all the details of the code. When you allow LabVIEW to generate this function prototype, you help ensure that the basic syntax of the code in the shared library is valid. The prototype source file you create is a .c file and contains C declarations for the parameters you want to pass.

Complete the following steps to build a prototype source file, myshared.c.

  1. Open a new, blank VI and save the VI as Array Average. This function will calculate the average of an array of values.
  2. Add a Call Library Function Node to the block diagram.

     Add  Find
  3. Right-click the Call Library Function Node and select Configure from the shortcut menu to open the Call Library Function dialog box.
  4. Leave the Library name or path control empty.
Note  Use the Library name or path control to specify the shared library the Call Library Function Node calls.
  1. Enter the following general specifications:
    1. Type avg_num in the Function name field.
    2. Select the C control from the Calling convention field.
  2. Define the return value using the following specifications:
    1. Navigate to the Parameters tab of the Call Library Function dialog box.
    2. Change the default name in the Name control from return type to the more descriptive name error.
    3. Select Numeric from the Type pull-down menu.
    4. Select Signed 32-bit Integer from the Data type pull-down menu.
  3. Define the a parameter using the following specifications:
    1. Click the Add a parameter button to the right of the parameter list.
    2. Replace the default name arg1 in the Name field with the name, a.
    3. Select Array from the Type pull-down menu.
    4. Select 4-byte Single from the Data type pull-down menu.
    5. Select Array Data Pointer from the Array format pull-down menu.
  4. Define the size parameter using the following specifications:
    1. Click the Add a parameter button to the right of the parameter list.
    2. Replace the default name arg2 in the Name field with the name, size.
    3. Select Numeric from the Type pull-down menu.
    4. Select Signed 32-bit Integer from the Data type pull-down menu.
    5. Select Value from the Pass pull-down menu.
  5. Define the avg parameter using the following specifications:
    1. Click the Add a parameter button to the right of the parameter list.
    2. Replace the default name arg3 in the Parameter field with the name, avg.
    3. Select Numeric from the Type pull-down menu.
    4. Select 4-byte Single from the Data type pull-down menu.
    5. Select Pointer to Value from the Pass pull-down menu.
  6. Check that the Function prototype field displays the return value and three parameters in the correct order, as follows:

    int32_t avg_num(float *a, int32_t size, float *avg);
Note  The syntax you see in the Function Prototype field is technically correct. However, the .c file that the Call Library Function Node generates is more precise because the first parameter appears as float a[].
  1. Click the OK button to save your settings and close the dialog box.
  2. Notice that the Call Library Function Node icon updates to reflect your settings.
  3. Right-click the Call Library Function Node and select Create C File from the shortcut menu.
  4. Save the file as myshared.c.
Note  In this example, you use a .c source file. When you work with C++ libraries, change the extension of the source file to .cpp.

Preventing C++ Name Decoration

Keep the C++ compiler from introducing platform dependence in exported function names through a process called name mangling by using the C++ compiler function export directive, extern "C"{}, in your header file, as shown in the following example code:

extern "C" {
int32_t MyDLLFunction(int32_t nInput, uint32_t nOutput, void *arg1);
}

int32_t MyDLLFunction(int32_t nInput, uint32_t nOutput, void *arg1)

{

/* Insert Code Here */

}

Note  If you disable C++ decoration of a function, the compiler cannot create polymorphic versions of the function.

After you build the function prototype, complete the .c file.