06-20-2007 05:12 PM
06-20-2007 05:47 PM
06-22-2007 08:47 AM
Hi Rene,
After running through some tests in .NET and CVI, I have figured out what is
going on. So first off, you were right about how the GetValues method was supposed to work as I
validated that by creating a C# program that communicated to a database and
used that GetValues
method.
The
GetValues method is
actually quite odd in the sense that it takes an input array and fills it up.
This seems to violate one of Microsoft's own recommendations against API
methods filling up input array parameters.
The significance of that fact is that CVI only marshals arrays back if the
parameter of a function is marked as an output parameter or reference parameter
(i.e. keywords out, ref, ByRef, etc;
For example, check out the System.Array.Resize method). Since this GetValues "values" array parameter was not marked in
this way, the output values returned by the GetValues method inside our wrapper were not
sent back to the caller (your program). Basically the reason that the
array contained NULL values is that the wrapper didn't convert the .NET array
values back to a C array because we think the GetValues array parameter is input only.
So my initial fix was to call the CDotNetGetArrayElements method in the wrapper after the
Invoke call and pass it the array handle (values__)
to copy the elements to the values parameter that was sent in. However, I soon
realized there was a problem with that because that function allocates the
buffer to hold the elements. So instead, you need to use CDotNetGettArrayElement
in a loop and fill up
the values array. For example, you would say:
/* values__ is the array that was returned
by the Invoke call. values is our array we sent into the wrapper
function
for
(i = 0; i < __valuesLength; ++i) // valuesLength was
an input parameter
__errChk(CDotNetGetArrayElement(values__,
CDOTNET_OBJECT, 1, &i, &values[i]));
I have attached what my GetValues function looks like after inserting that
statement and of course declaring the variable i. I tested this out on my side
with the database I created and it worked.
Hope this helps and let me know if you have any trouble.
Best Regards,
06-25-2007 10:44 AM