05-10-2005 12:48 PM
05-10-2005
02:50 PM
- last edited on
03-19-2026
11:41 AM
by
Content Cleaner
Mim,
(To go easy on the NI server and allow for faster downloading, you should save any future images as PNG or GIF files; it will result in images that are orders of magnitude smaller)
The reason for the crash is almost certainly that the DLL is attempting to write memory space beyond what LabVIEW has allocated. Right up front, I urge you to download and examine the Passing a Variety of Data Types from DLL to LabVIEW [link removed; example no longer available] example available on the NI site. You'll see how to successfully pass strings to a DLL and modify them there.
With that example in mind, I'd say the problem lies with the string members of the Bed List array not being preallocated with enough characters to hold the values that the DLL is attempting to write into them. Without exploring the front panel, I can't tell if you've set those string members with non-empty default values, but that's what you'll need to do to make the call work. Alternatively, you can create sufficiently long U8 arrays on the block diagram and cast them to strings, then build the Bed List array using those elements.
My two cents,
John
05-10-2005 03:35 PM
05-10-2005 04:03 PM
05-10-2005
10:18 PM
- last edited on
03-19-2026
11:41 AM
by
Content Cleaner
Mim,
I'm afraid my suggestions so far are absolutely no good, for a number of reasons. For one, the U8 arrays in the cluster will be "mangled" by LabVIEW in exactly the same way that the strings are when they are passed to the DLL. Furthermore, at a higher level, the array of structs itself will get the exact same treatment.
For a good discussion of the problem, refer to the thread here entitled How do I pass a pointer to an array of structs to a DLL function?
I don't really think the solution there is tenable for you, since you have the added problem of strings inside the structs that you want to pass as an array. However, since you do seem to be working with an upper limit of 256 elements in the array, I think you might be able to get this to work in a messy way that would involve reformatting the string data once it got back to LabVIEW.
The better solution (assuming the DLL can't be rewritten or implemented directly in LabVIEW) probably lies in a CIN or some sort of wrapper DLL that accepts simpler data structures and calls the target DLL inside itself.
Sorry for the bum steer,
John
05-11-2005 08:05 AM
05-11-2005
11:10 PM
- last edited on
03-19-2026
11:41 AM
by
Content Cleaner
Mim,
In the second thread that you opened up, it would be a good idea to link back over here to provide more background to anyone who wants to help.
I won't touch that second thread so that other people are more inclined to take a crack at it. However, now that I've more thoroughly thought this over and reviewed some similar discussion threads involving other experts here, I think I understand the situation:
I really think you are going to have to create a wrapper DLL. Since you'll be making this new DLL, you can include extcode.h (see the example above and refer to the Using External Code In LabVIEW manual) and make use of LabVIEW's native data type definitions and memory manager functions. This wrapper DLL would accept your cluster array exactly as you originally programmed it, with no need to prepopulate the array or the strings inside the clusters. The DLL would create a temporary C-style pBedList data structure and feed that to the original WvListBeds DLL function. Then, it would take the results and copy those pieces of data into the cluster array that LabVIEW passed into the wrapper DLL, using memory manager functions to resize the array and populate the strings inside each cluster to match the data found in the temporary pBedList object.
Maybe I'm still mistaken and someone else will have a better idea, but given your data structure, I think you'll have to use a wrapper-style approach.
--John
05-12-2005 06:00 AM
@Mim wrote:
I am writing a LabView application to obtain data from the network using a DLL written in C.
DLL Function:
IMPORT_FUNCTION int WINAPI WvListBeds(const TCHAR *pServerName, const TCHAR *pUserName, const TCHAR *pPassword, WV_BED_LIST *pBedList, int *pNumberOfBeds) ;
typedef struct {
TCHAR PatientName [WV_PATIENT_NAME_SIZE] ;
TCHAR PatientID [WV_PATIENT_ID_SIZE] ;
TCHAR BedLabel [WV_BED_LABEL_SIZE];
TCHAR CareUnit [WV_CARE_UNIT_SIZE];
TCHAR FileName [WV_FILE_NAME_SIZE];
TCHAR IPAddress [WV_IP_ADDRESS_SIZE];
TCHAR MulticastIP [WV_MULTICAST_IP_SIZE];
TCHAR DeviceType [WV_DEVICE_TYPE_SIZE];
WV_OPERATING_MODE DeviceStatus ;
WV_CONNECT_ID ConnectID ; // 0 if not connected
} WV_BED_DESCRIPTION ;
typedef struct {
WV_BED_DESCRIPTION WvBeds[256] ;
} WV_BED_LIST ;
When I call the above function from LabView, it executes successfully but when I call any function after calling this function, LabView crashes. I have attached screen shot of the block diagram.
Any ideas on why this is happenning???
Many Thanks for your help.
Mim
05-12-2005 06:48 AM
@Mim wrote:
John,
Thanks for your response.
This was my first posting on the Forum and I didn't realize the download issue with bmp files. Thanks for the tip.
Regarding my vi, the string members of the array of clusters were empty. I implemented your suggestion of casting U8 data type to string of desired length. I am attaching my VI (APITestApp1.vi) for your review. The zip file contains other vis that this vi is linked to.
The problem definitely is with the data type for the Bed List array. But I am not being able to resolve it.
Please help!
Many Thanks,
Mim
05-12-2005 07:56 AM