LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to call labview DLL from visual C++?

Hi,

I'm trying to call a LV DLL from a VC++ application
by using the LoadLibrary and GetProcAddress functions.

The DLL contains a simple sum function. The Library is
loaded correctly, but the result is always 0.0000.

I have loaded a VC++ DLL in a similar way and it works
correctly. Also, I have tested the DLL by loading it in LV,
and it works correctly. The calling convention is defined
to be stdcall in LV Application Builder.

I have also tried this solution, but I will get a compiler error
from one the header files that are created by the LV when
the DLL is made. The error comes from this line

typedef char                int8;

and the error states that

..\fundtypes.h(107) : error C2371: 'int8' : redefinition; different basic types

If someone knows of newer tutorial(for LV 8.2) or knows how to use those
LoadLibrary and GetProcAddress function for LV DLLs, I will appreciate the
information greatly.

Below is the code that I'm using for loading the LV DLL.

Thanks

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <map>
#include <windows.h>

int _tmain(int argc, _TCHAR* argv[])
{
    HINSTANCE LVLib = LoadLibrary(TEXT("Testdll"));
    typedef double (__stdcall *MYPROC)(double, double);

    if (LVLib != NULL)
    {
        MYPROC ProcAdd = (MYPROC) GetProcAddress(LVLib, "Add");
        if (ProcAdd != NULL)
        {   
            double d = (ProcAdd)(5.5, 6.6);
            printf("sum = %f\n", d);
        }
        else
            printf("Invalid function pointer\n");
    }
    else
        printf("Failed to load the library\n");

    return 0;
}


0 Kudos
Message 1 of 2
(2,795 Views)
I was just about to post the header file of the DLL, when
I noticed that there's a function called LVDLLStatus.
This little thingie turned out to be a rather handy tool.
With that function I found that in the DLL I had a problem
with another function that prevented the DLL to be correctly
loaded.

This other function in the DLL is for generating digital output
and it worked as it should, when tested from LV.

Anyway if someone is interested, I got it working by using
the LoadLibrary and GetProcAddress function, as in the
source code thatI posted earlier.

I will investigate what is wrong with that digital output, and
post into a another thread if I have problems with that.
0 Kudos
Message 2 of 2
(2,786 Views)