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

cancel
Showing results for 
Search instead for 
Did you mean: 

Fatal insanity issue after using DSSetHandleSize in a C Dll

Hi,

 

I encounter a problem unsing the function DSSet handle size in a DLL.

 

I have to make a wrapper for an API that will return strings of various size. Since I can only know the length of the string in my C wrapper I figured out that I should use the provided DSSetHandleSize func in order to resize the labview handle to hold the string i'm trying to retrieve from the API.

 

At first sight it seems to work and I retrieve a string of the right size. However, if I then try to save or touch something on the FP of my VI, labview crashes sending me this error :

" e:\builds\penguin\labview\branches\2017\dev\source\panel\fpsane.cpp(548) : DAbort 0x1A7102DF: Fatal insanities(0x00000400) exist in ReportInsanities, "

 

My C code is for now fairly simple (test purpose only) and is basicaly a simplified copy of the example given by Ni in the " Libraries and exectutable " example project.

 

void Test_Func (LStrHandle x, LStrHandle y){
          if ((*y)->cnt < (*x)->cnt )
           {
           /* Adjust the handle size to hold everything we want to put in it */
          DSSetHandleSize((void *)y, (*x)->cnt );
             }
       for(int i =0; i <(*x)->cnt; i++)
         {
            (*y)->str[i] = (*x)->str[i];
         }
        (*y)->cnt = (*x)->cnt;

}

 

and here is the corresponding labview diagram :

DSSetHandle crashes LV code.png

 

the parameters of the library call are both set to string, string handle.

 

I use Labview 2017 32bits and the library is compiled using CVI 2019

 

What I found the most intriguing is that if I modify the VI given by NI in the " Libraries and exectutable " example project in order to triger the condition to pass throught that DSSetHandleSize, I have no crashes but it does not work, the string I retrieve is of the size of the string I feed in. Does the provided C example really are what's complied int the example DLL ?

0 Kudos
Message 1 of 4
(2,042 Views)

Hello IMArcale,

 

What exactly example you have used?

__________________________________________
The best way to thank, is to give KUDOS
0 Kudos
Message 2 of 4
(1,883 Views)

The "LVLStrHandle" example that is found in the "Libraries and Executables.lvproj" that is found in the "\examples\Connectivity\Libraries and Executables\" folder of my LabVIEW installation directory which uses the CLF_Example.dll that is found under the "DLL Calling VIs" sub-directory whom is supposed to have inside of it the compiled result of the C code that is in the "LVLStrHandle.c" found in the "Source C Files" sub-directory.

 

In other term I used the "LVLStrHandle" example delivered by NI in the installation directory of LabVIEW.

 

But 3 month ago when I faced the problem i just rewrote all my code to avoid having to use that DSSetHandleSize  function.

 

And in the mean time I uninstalled all version of LabVIEW installed on my computer and reinstalled only LabVIEW 2019 and with a quick try it now seems to work.

 

So thanks but I guess the subject is outdated and no longer relevant.

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

What is the exact parameter configuration? "String, String Handle" or "String, String Handle Pointer"?

 

Also the parameter in DSSetHandleSize() is the number of total bytes to resize to, not the number of data bytes in the String handle. That is a difference since the string handle contains as first element the number of characters in the byte as an int32.

 

So your code should be similar to this (assuming you pass in String Handles and not String Handle Pointers):

 

 

void Test_Func (LStrHandle x, LStrHandle y)
{
    if ((*y)->cnt < (*x)->cnt)
    {
        /* Adjust the handle size to hold everything we want to put in it */
        DSSetHandleSize((void *)y, (*x)->cnt + sizeof(int32));
    }
    for (int i = 0; i <(*x)->cnt; i++)
    {
       (*y)->str[i] = (*x)->str[i];
    }
    (*y)->cnt = (*x)->cnt;
}

 

 

If you would pass in String Handle Pointers instead you would also have to protect your code from the possibility that LabVIEW passes in NULL handles, as that is the LabVIEW canonical way of an empty string or array. If you configure the parameters as String Handles, LabVIEW will not do this as there would be no way of passing back the handle created in the function and it will make sure to allocate a handle that contains only 4 bytes for the (*handle)->cnt value and initialize it to 0.

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 4
(1,809 Views)