Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SafeArray!

Status
Not open for further replies.

amber1111

MIS
May 1, 2001
15
0
0
US
I have this method from an ocx that is expecting safearray object as arguments

ocx.GetData(ref object ySafeArray, ref object xSafeArray, ref int pts, ref double xbeg, ref double xend);

How do I create a SafeArray object in C#? I did something like this...but that does not seem to work

object yArray = new object();
object xArray = new object();

Thanks
 
You have to find out what the structure of their SafeArray is or use the safe array provided by them.

YourOCXNamespace.SafeArray xarray = new YourOCXNamespace.SafeArray();

YourOCXNamespace.SafeArray yarray = new YourOCXNamespace.SafeArray();

int pts = 0;
double xbeg = 0.0;
double xend = 0.0;

ocx.GetData(ref yarray, ref xarray, ref pts, ref xbeg, ref xend);
 
JurMonkey,

I am not sure I understand what you're saying....

pay attention to the first argument of the method ...it expecting a "ref object SafeArray".

Thanks
 
right, but you will have to convert that object to something in order to use it. Find out what kind of class or structure they are asking for in that call.
 
JurkMonkey,

For the sake of argument, let's say I want to convert the object to double or array of double...How do I do that?

Thanks
 
Where did this ocx come from? What are they doing with that object that you are sending in?

Typically, you send in an "object" and the ocx casts it to a specific type - sets some values - and returns it to you.

for example:

//This is the structure called SomeType which is an "object"
public struct SomeType
{
public int quantity;
public double price;
}

//In the ocx file
public void GetData(ref object something)
{
SomeType st = (SomeType)something;

st.quantity = 10;
st.price = 19.99;
}


//and in your code you would have
public double GetPrice()
{
SomeType s = new SomeType();

ocx.GetData((object)s);

return s.price;
}


So you really have to know what it is they are expecting you to pass in because "object" is only a base class.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top