ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Call DLL function with pointer to complex structure

Solved!
Go to solution

Hello,

I try to call a function using CLFN. My problem is the parameters of the function I try to access.

Here is the function and his parameters:

typedef struct _BAR_INFO
{
    ULONG              dwSize;    
    ULONG              dwFlag;
}BAR_INFO, PBAR_INFO;

typedef struct _DEVICE_INFO
{
    ULONG              dwBarNum;
    BAR_INFO           BarInfo[6];
}DEVICE_INFO, *PDEVICE_INFO;

DLLIMPORT int GetDeviceInfo(
    unsigned int      devID,
    PDEVICE_INFO      pdevinfo
)
{
    ULONG             i;
  
    if(devID >= DevNum)
        return PCICORE_DEVICE_NO_FOUND;
    
    if(DevTable[devID].DevHandle == NULL)
        return PCICORE_DEVICE_NO_INITIALIZE;

    if(pdevinfo == NULL)
        return PCICORE_INVALID_PARAMETER;
   
    pdevinfo->dwBarNum = DevTable[devID].DevInfo.dwBarNum;
    for(i = 0; i < pdevinfo->dwBarNum; i++)
    {
        pdevinfo->BarInfo[i].dwFlag = 
            DevTable[devID].DevInfo.BarInfo[i].dwFlag;
        pdevinfo->BarInfo[i].dwSize = 
            DevTable[devID].DevInfo.BarInfo[i].dwSize;
    }

    return PCICORE_SUCCESS;
}

 In attached file there is the Get Device Info.vi that try to access this function. The code crashes when the function is called.

I probably don't pass the data parameters correctly to the CLFN.

 

Thanks for your lights §Smiley Happy

0 Kudos
Message 1 of 4
(3,660 Views)

The VI attached

0 Kudos
Message 2 of 4
(3,659 Views)
Solution
Accepted by topic author NewCLAD

A fixed-size array in C is equivalent to a LabVIEW cluster containing  the same number of identical elements, so you need to replace the array with a cluster. Also, structs are always passed by reference and the C function expects a pointer to a struct, so you don't need to unbundle. Pass the cluster directly to the function as a single parameter. Try the attached revised version of your VI.

0 Kudos
Message 3 of 4
(3,637 Views)

Thanks Nathan. Its working fine.

0 Kudos
Message 4 of 4
(3,612 Views)