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.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

passing a structure by reference into a dll (cvi) get's an error -17502; System Level Exception.

Solved!
Go to solution

Created a container that matches parameter in cvi dll.  I set-up the container by checking the C struct passing using 8-byte packing.  Using the cvi adapter created an action.  When the step is executed, I get this error (17502; System Level Exception). 

0 Kudos
Message 1 of 7
(4,120 Views)
Solution
Accepted by topic author JamesSid

Did you create a custom data type to represent the struct (you say you created a container)? Did you specify the structure field's type for each variable in the custom data type? You must configure each field to tell TestStand what data type to use, for example, a number could be a double, int, short, or char and TestStand needs to know which in order to create the corresponding structure correctly. Did you create an instance of that type to pass into the dll function? Please post the structure definition you are using in C if possible, also please describe exactly how you configured each variable in the type definition (custom data type) you created. If you are able to provide more information we can try to see if there is a misconfiguration of the custom data type.

 

Also you might want to take a look at what your function is doing, the code in the function might be causing an access violation or other system level exception. You can launch the sequence editor from CVI as the process to debug in order to debug your code module, or change the adapter configuration setting for the CVI adapter to run the code an an external instance of CVI.

 

Hope this helps,

-Doug

Message 2 of 7
(4,101 Views)

Yes, I created a data type...  I attached the data type I created.  I assigned a type to each member in the c struct passing dialog.  Created an instance of it in the locals area...

According to the prototype from the dll and the test stand module definitions matched... 

 

I've did the debug within CVI and it is working within CVI, but when the dll returns to test stand it shows the error dialog box.  I've tested it via cvi created exe that calls the same dll and it works great.....

 

Thanks for your help so far.... 

 

Download All
0 Kudos
Message 3 of 7
(4,094 Views)

Hi James,

 

Looks like Doug provided some good information.  You mentioned you debugged the DLL in CVI, but was that when you were running it in TestStand?  By that, I mean, you were debugging your code in TestStand and had CVI launch at that step?

Message Edited by Eric B. on 03-23-2009 11:24 AM
Eric B.
National Instruments
0 Kudos
Message 4 of 7
(4,092 Views)
I used two methods of debugging.  I wanted to make sure my dll was working properly, so I created a cvi exe to call the dll.  This worked fine.  The other method was via Test Stand.  I changed the cvi adapter to start an cvi and go into the dll for debugging.  When I executed the step, it went into cvi and I stepped through the function within the dll to insure the parameters were functioning properly which they were.  Once the function completed it's function and returned, I get the error....
0 Kudos
Message 5 of 7
(4,085 Views)

I fixed the problem......

In my data type, one member was defined as a string type.  In the C Struct passing definitions, I defined this string as a C String Buffer and assigned an array size to it.  This would not work and continued giving me errors in Test Stand.  I used the preexpression and assigned the string to a "hello World" and passed it into the dll.  In the debug (using the adapter), the string contents was not being passed into the dll.

Anyway, I changed the definition from c String buffer to inline string and assign it's size.  this definition worked. 

 

James 

0 Kudos
Message 6 of 7
(4,072 Views)

Hi James,

 

Glad you found the problem. Specifying the correct string type for the custom data type is very important and can be a bit tricky. Here are some guidelines to help. Please take a look to make sure you have this correct as things can appear to work even when it's wrong however memory might be getting corrupted (causing crashes) or the data might not be getting transfered between TestStand and the function call:

If your structure definition looks like this:

struct
{
char *mystring;
const char *myconststring;
};
 
Then you should use the structure field Type setting of  "Pointer to String" for both of these fields and the String Type should be "C String Buffer" for the first field and "C String (const)" for the second.

 

If your structure definition looks like this:

struct
{
char stringbuf[260];
const char conststringbuf[1024];
}
 
Then you should use the structure field Type setting of "Inline String" for both of these fields and the String Type should be "C String Buffer" for the first field and "C String (const)" for the second and you must be sure to set the buffer size to the exact size specified by the structure definition (i.e. 260 and 1024 in this case).

 

Also, I just wanted to add that in most cases you should leave the Packing setting for the data type's struct settings as "Default Adapter Packing" as this allows the adapter to control this setting. The adapter setting can be changed in the Adapter Configuration dialog box which you can view using the Configure->Adapters... menu item.

 

Glad you got things working, let us know if you have any additional questions related to this.
-Doug

0 Kudos
Message 7 of 7
(4,044 Views)