11-16-2018 10:38 AM
Hey,
thats a great topic. I have also a similar problem and can not get to a working solution. Maybe someone can help?
I have a coplex structure, consisting of one double and one fix-sized array (1000 elements). This structure is received from a c++ dll function. Testing with C# works fine, however I can not get it in my desired case to run with LabVIEW (2009).
The structure itself is this one:
typedef struct teststruct { double singval; double multval[1000]; }VAL;
I can get the LabVIEW code running with a function which returns the struct as a return value,....
__declspec(dllexport) VAL* WINAPI DotheTest();
The LabVIEW example is not the whole code, but it reads correctly the "singval" value and then the array.
However, I have to transmit the structure as a reference by a parameter, since I'll have to pass it later to an other function by a reference by parameter. So the dll-function I have to use is the following:
__declspec(dllexport) unsigned char WINAPI DotheTest(VAL *MyTestStruct);
So I tried these LabVIEW codes without success:
When I run, this code, I'll get Error 1097.
My second try was with this code:
This VI crashes LabVIEW. The size is 1000*8 + 8. The Parameter's Type and Data Format are "Adapt to Type" and "Handles by Value".
Has someone suggestions, how to receive (and on a later step pass) the mentioned structure correctly?
Thanks!
11-16-2018 03:50 PM - edited 11-16-2018 03:58 PM
All totally wrong.
Your structure:
typedef struct teststruct { double singval; double multval[1000]; }VAL;
really is equivalent in C to this:
typedef struct teststruct { double multval[1001]; }VAL;
in terms of memory layout.
Do you think you can work it out from this?
Of course this will probably work too without pointer mathematics:
11-19-2018 10:25 AM
Hi Rolf!
Thats great! Thank you for the idea and solution.
Running the VI with the parameter defined as Type: "Adapt to Type" and Data Format: "Handles by Value" in the Call Library Function, crashes LabVIEW (however without generating a log-file).
However running the VI with the parameter set to Type: "Array" with Array Data Pointer works fine without a crash. Thats the solution.
Maybe I can ask a further question:
The arraysize of 1000 is the max. size I can generate within my function, howere typically the necessery size will be quite smaller.
So I was thinking to use SAFEARRAY in C++ for the array without specifying its size.
Is there a possibility to read a SAFEARRAY in the actual example?
Greetings
11-19-2018 10:45 AM - edited 11-19-2018 10:46 AM
@plamka00 wrote:
Hi Rolf!
Running the VI with the parameter defined as Type: "Adapt to Type" and Data Format: "Handles by Value" in the Call Library Function, crashes LabVIEW (however without generating a log-file).
Of course! A LabVIEW array handle is a pointer to a pointer to a memory block with one int32 for each dimension directly followed by the data in a single block of memory. That is not what your C function expects! Unless a C function has been very specifically developed to work with LabVIEW data types, which requires you to include extcode.h from the cintools directory and use the according LabVIEW memory manager functions to allocate, resize and deallocate those handles it will never be able to understand LabVIEW handle data.
However running the VI with the parameter set to Type: "Array" with Array Data Pointer works fine without a crash. Thats the solution.
You seem not to have noticed but the image I included and attached is a LabVIEW snippet. If you download it to your computer and then place it on a diagram it will expand to the actual LabVIEW code. In there I did specifically set the parameters to be Array Data Pointer. And this is what your DLL expects.
Maybe I can ask a further question:
The arraysize of 1000 is the max. size I can generate within my function, howere typically the necessery size will be quite smaller.
So I was thinking to use SAFEARRAY in C++ for the array without specifying its size.
Is there a possibility to read a SAFEARRAY in the actual example?
Not really! Well it would be theoretically possible but SAFEARRAY is a fairly complicated data structure with various elements in a way similar to a LabVIEW array handle but also supporting various COM types as array elements, so trying to do that all inside LabVIEW is simply going to be a major pita and requiring you to be the C compiler that arranges and interpretes everything in memory PERFECTLY correct. There are much more interesting and productive ways to spend your time!
11-19-2018 11:04 AM
Thank you!!
09-24-2021 01:40 PM
I wanted to use DSNewPtr and MoveBlock. I see that they're in vi.lib. But I can not access them from the Palette. Even the search does not return the VIs.
How do I get access to the VIs contained in vi.lib via the Palette?
09-25-2021 09:42 AM
I simply drag them from Windows File Explorer into the diagram or select them through the Select a VI .. file dialog in the palette. You can make your own palettes if you really want to by going into Tools->Advanced->Edit Palette Set but that is cumbersome and you need to redo that for every new LabVIEW installation or find the according mnu files and correctly copy them to the correct place in the new installation. Just to much to bother for my taste.
Also have to admit that I usually don't use those functions but simply recreate them with a new Call Library Node whenever I need them, simply because especially the MoveBlock function needs different configuration each time because of the data types it has to operate on. The GetValuePointer.xnode can do a few things but by long not all I usually need and there is no premade function to do the opposite except for simple strings.
There might be a palette set out there that contains these functions and can be installed with VIPM but I never bothered to look for that and even less to take the time to create that.