omroepbrabant
asked on
How to declare an Array to send as ref
There is a DLL I use that had a Method that looks like this:
AskJobPages(ref Array Pages)
So I should declare an Array and send it as a ref. The method will fill the array with pagenumbers (int).
I tried this:
But this is not the way. I get the errormessage:
Any suggestions?
AskJobPages(ref Array Pages)
So I should declare an Array and send it as a ref. The method will fill the array with pagenumbers (int).
I tried this:
Array pages = new int[999];
clarity.AskJobPages(ref pages);
But this is not the way. I get the errormessage:
Value does not fall within the expected range.on the second line.
Any suggestions?
Yes, that is the correct way to pass variables so they will be directly modified within the called method (since the method is defined with a ref parameter). Is it possible to see the definition of AskJobPages?
ASKER
No, I don't have the source and the documentation is not program language speciffic.
I wonder if the message "Value does not fall within the expected range" indicates that the array is of the wrong length.
I don't know the length of the resulting array.
I wonder if the message "Value does not fall within the expected range" indicates that the array is of the wrong length.
I don't know the length of the resulting array.
I wonder if the message "Value does not fall within the expected range" indicates that the array is of the wrong length.Which is what I thought as well. I wondered if the target function was expecting a smaller array than 999.
ASKER
I've tried a smaler array,
100, 10, even 1.
100, 10, even 1.
Out of curiosity, what is the type of the exception being raised?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@fromer
"ref" parameters imply that the variable is initialized prior to the function call containing the "ref" param. "out" params are ones that can be null before being passed to a function that accepts such a parameter.
"ref" parameters imply that the variable is initialized prior to the function call containing the "ref" param. "out" params are ones that can be null before being passed to a function that accepts such a parameter.
Yes you are right...
What is the purpose of passing a Reference Type as ref parameter?...function implies that, if the size of the array is not enough, i may ReConstruct it (ReAllocate, ReCreate, Grow)....
i don't think that, the exception occurs due to the size of the Array...It comes from the internal structure of the method...
What is the purpose of passing a Reference Type as ref parameter?...function implies that, if the size of the array is not enough, i may ReConstruct it (ReAllocate, ReCreate, Grow)....
i don't think that, the exception occurs due to the size of the Array...It comes from the internal structure of the method...
The purpose of my suggestion was to learn if the method ReConstructs (ReAllocate, ReCreate, Grow) the array parameter..if you we send null as parameter, and the method does not reconstructs it, then the exception should turn to be an Access Violation exception...
ASKER
Passing an empty Array worked like fromer sugested, it fills the array for me... Thank you!