Jump to content

Vi with DLL work incorrectly


Recommended Posts

In the attached file there is a project on VC ++ 5 and the project on LabView 6.0 (I have got used to these versions). In DLL 2 functions actually for check of working capacity DLL (Summa, Multi) and working function readdata which is intended for reading a file with data double, definitions of its size (filesize), creations of a file double for a data storage bufdat and transfers of this file in LabView. I have created on disk directory c: \LabViewDLL\ also has written down there DLL, VI, has created in this directory subdirectory VC ++ and has written down there the project on VC ++. I have checked up, Summa and Multi work normally, the size of a file also is defined correctly so probably DLL works. I very much would like to learn to transfer files from DLL on C/C ++ in LabView, in the further it to be necessary for me. Probably, I incorrectly initialize a array. Help, please.

Link to comment

QUOTE(tumanovalex @ Nov 23 2007, 01:58 PM)

In the attached file there is a project on VC ++ 5 and the project on LabView 6.0 (I have got used to these versions). In DLL 2 functions actually for check of working capacity DLL (Summa, Multi) and working function readdata which is intended for reading a file with data double, definitions of its size (filesize), creations of a file double for a data storage bufdat and transfers of this file in LabView. I have created on disk directory c: \LabViewDLL\ also has written down there DLL, VI, has created in this directory subdirectory VC ++ and has written down there the project on VC ++. I have checked up, Summa and Multi work normally, the size of a file also is defined correctly so probably DLL works. I very much would like to learn to transfer files from DLL on C/C ++ in LabView, in the further it to be necessary for me. Probably, I incorrectly initialize a array. Help, please.

Well, you obviously need to read a C text book about data pointers. The way you try to return the data pointer simply can't work. Allocating the buffer inside the function and assigning it to the array pointer does absolutely nothing in terms of allowing the caller to ever see that buffer. You would need a reference to an array pointer and not just an array pointer alone but because of memory management it is a very bad idea in general (and especially bad for use in LabVIEW) to allocate a memory buffer inside a function and return that to the caller. The way this is normally handled is by providing a possibility to either of the two possibilities:

1) Provide a way to retireve the necessary buffer size first, allocating the buffer in the caller (here LabVIEW) and then retrive the actual data. You could do this by providing first a NULL pointer as buffer parameter and in that case only return the file size. Then calculate the necessary buffer size in LabVIEW allocate that buffer as an array of the elements you require (double) and pass that a C array data pointer this time.

2) Allocate a reasonably sized buffer in LabVIEW first, pass the size of it together with the buffer itself to the function and then inside the function check if the size is big enough. If it is read the data into the buffer, returning the actual size filled in and return a success indication as function return value.

If it is to small, return the actually needed size together with an error indication that the buffer was to small and then in LabVIEW reallocate the buffer with the necessary size and call the function again with the resized buffer.

These two methods are not only the standard method for just about any C library but also the only reasonably compatible ones that will allow your code to be called from many different environments including LabVIEW.

Rolf Kalbermatter

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.