?
Solved

C#, C++   -----   A question regarding Variant arrays in C#

Posted on 2005-03-05
16
Medium Priority
?
2,825 Views
Last Modified: 2011-09-20
Hi everyone,

I have a question regarding Vairiant arrays, what they are and how they are used in C#

I am looking at some software API documentation where is has this callable function listed in the document....

long CopyRetrievedDataToArray(short Period, VARIANT *DateArray, VARIANT *DowArray, VARIANT *DydmArray, VARIANT *OpenArray, VARIANT *HighArray,...etc)

My question is

1)  What is a VARIANT array?  Is it VARIANT in size?  Size meaning elements or dimentions?

2)  What can I do to call this function in C#?  How do I declare and initialize a Variant array in C# or will any type of array do?  Am I passing an array by reference in this situation?

3)  Can someone show me some example code that can do what I need so I can emulate.


Please allow me to express my gratitude in advance.

Thanks once again.

Regards,

Dynotoe
0
Comment
Question by:Dynotoe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
16 Comments
 
LVL 18

Expert Comment

by:testn
ID: 13468993
1. VARIANT means variant in size and the object itself can indicate its size
2. The interface looks more like COM interface. If so, it might be easier to create .NET RCW dll using tlbimp
3. Need .dll so that I can take a look.
0
 

Author Comment

by:Dynotoe
ID: 13469168

:)  Hi again Testn.


I'm not sure about the COM stuff it's over my head.  However I will say that all the other functions/Properties work when called using the dll I brought into my C# project.  Yes you are right there is a dll for the API.  This is how I have access to the exposed methods of the API.

I just want to know how this passing an Array by reference works and if there is anything special I have to do because of this VARIANT thing.

If I create and declare 1 dimentional arrays without allocating memory/size will this method/function I pass them to size them?  Or do I have to create this specialized "Variant array" and pass in that?  Come to think of it it doesn't specify what type of array, i.e int[] or string[] etc.

Now is passing the in my arrays just passing by reference?  This way they can be chaneged by the method or something?  Is it also just passing the memory reference like a pointer to my arrays?  Sorry just trying to understand it better.

I don't see how I could give you the dll to look at exactly?  I can get info on it if you instruct me how to do that.


Anyway I appreciate you help once again.

Best,

Dynotoe
0
 
LVL 18

Expert Comment

by:testn
ID: 13470156
Okay.... I think you are using Unfair Advantage COM API I would think. If so, all you have is first go to your project and then add reference.... go to COM tab and search for CSIData Unfair Advantage Type Library. Then click at "select " and then click "OK". After that you will have a reference to that API automatically. You can browse detail of each API from object browser (View... Object Browser (CTRL+ALT+J))
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Dynotoe
ID: 13470243
Hi Testn,

That's exactly what I'm working with  :)  Very good, how did you know that?  Do you use UA or work with financial data?

Well all that is done already... Now what do you want me to do once I'm in the Object Browser?

Best,

Dynotoe
0
 
LVL 18

Expert Comment

by:testn
ID: 13470529
Nah... nothing....

You can start using the API.

I don't have that install but check out the namespace listed in object browser.
then include that namespace using "using" statement after that create the API2 object and start to rock and roll
0
 

Author Comment

by:Dynotoe
ID: 13470734
Hi Testn,

Nah...nothing??  What do you mean?


I think you misunderstand my question.  I am already using the API in my project, meaning I have it up and running and have accessed methods from the dll already.  What I am trying to do is understand this exposed function I haven't used yet that takes aguments (by reference) that are "Variant Arrays".

I assume I have to declare these "Variant array's before I pass them into the function.  Since I have never passed an array by reference or used, declared or initialized a "Variant" array before, I need some guidance with doing this in C#.  etc.

Do you understand what I mean?


Best,

Dynotoe


0
 
LVL 18

Expert Comment

by:testn
ID: 13470797
Once you have add the reference, you got the api declaration in there already. So all you have to do is just refer to the document as you see in the object browser and start using it like that.
0
 

Author Comment

by:Dynotoe
ID: 13471151
yeah I know...

the function I wan to use looks like this...

long CopyRetrievedDataToArray(short Period, VARIANT *DateArray, VARIANT *DowArray, VARIANT *DydmArray, VARIANT *OpenArray, VARIANT *HighArray,...etc);


How do I use this Variant array in C#?  I never passed an array by reference especially a "Variant" Array.  How do I do this?

Dynotoe
0
 
LVL 18

Expert Comment

by:testn
ID: 13471193
Nooo..... look in the object browser for that API, you will see exactly how it 's implemented in C#
0
 
LVL 18

Expert Comment

by:testn
ID: 13471200
i think it should look something like

int CopyRetrievedDataToArray(byte Period, object[] DateArray, object[] DowArray, object[] DydmArray, object[] OpenArray, object[] HighArray,...etc);
0
 

Author Comment

by:Dynotoe
ID: 13471794
oh I....See.....let me take a look.

Dynotoe
0
 

Author Comment

by:Dynotoe
ID: 13471957

In the object browser, in the pane to the right I see...

CopyRetrievedDataToArray(short, out object, out object, out object, out object,...etc);

and when I highlight it this is shown below...

public abstract new System.Int32 CopyRetrievedDataToArray ( System.Int16 Period , System.Object DateArray , System.Object DOWArray , System.Object DydmArray , System.Object OpenArray , System.Object HighArray , System.Object LowArray , System.Object CloseArray , System.Object ClosingBidArray , System.Object ClosingAskArray , System.Object VolumeArray , System.Object OIArray , System.Object TotalVolumeArray , System.Object TotalOIArray , System.Object CashArray )

So...

What do I have to declare and initialize before passing it into the function?  You used for example "object[] DateArray" before passing this into the function I must declare it and initialize it first right????  What would that look like?  I've declared int[] and string[] but never an object[] before.  Can you guide me a little?

Thanks for your patience.

Where are you located?  I'm from Boston.

Best,

Dynotoe

0
 
LVL 18

Expert Comment

by:testn
ID: 13473466
if it says CopyRetrievedDataToArray(short, out object, out object, out object, out object,...etc); it means that you don't have to allocate anything..... you would do something like this

int period = 3;
DateTime[] DateArray;
int[] DOWArray;
...

UA.API2 obj = new UA.API2();
...

obj.CopyRetrievedDataToArray(period, out DateArray, out DOWArray,....);
0
 
LVL 18

Accepted Solution

by:
testn earned 2000 total points
ID: 13473618
ignore the previous comment, i think it would cause invalidcastexception....


int period = 3;
object DateArrayTmp;
object DOWArrayTmp;
...

UA.API2 obj = new UA.API2();
...

obj.CopyRetrievedDataToArray(period, out DateArrayTmp, out DOWArrayTmp,....);
object[] DateArray = (object[]) DateArrayTmp; // you might need to unwrap each object like this....
foreach(object date in DateArray)
   Console.WriteLine(date);
0
 

Author Comment

by:Dynotoe
ID: 13479557

Testn,

Great job once again.  Thank you very very much.

I'd love to know what experience you have with ua?  I never even told you it was API2 or IAPI2.  You knew it already.  Anyway I'd love to talk to you about it if your interested.  I have Skype and here is an eeeee mhail if you want to give me a quick shout.  Ishtomar (no space) Farza ate com(no space)cast shot nezt with d for sh and a silent z  :)

Thanks once again.  You're very patient.

Best,

Dynotoe
0
 
LVL 18

Expert Comment

by:testn
ID: 13480926
Again... I've never used it.... Just a guess :D
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question