Jump to content

How do I change an array when all I have is a handle?


Recommended Posts

Hello everyone,

This is my first post, so please bear with me. I'm working with some Activex functions, and one of the invoke nodes returns a variant that is a handle to a 2D array. I need to give this array new values, and then pass a variant containing a handle to the changed array into another invoke node. Can anyone please advise me about how I would go about doing this? I've attached a picture that shows what I'm talking about. Any help whatsoever is much appreciated!

Steve

post-4036-1146190305.png?width=400

Link to comment

Hi Steve,

I'm not fully positive it is possible, but there are two options:

I've done something with Outlook, but you'll need some ActiveX component to get or edit the data.

A have an ActiveX component edit the data, you'll have to convert the variant to the proper type.

B Have an ActiveX componnet extract the data and hand it over to LabVIEW, edit the data and return it with ActiveX.

To typecast the variant to the right reference you could try this (I haven't verified this but here it is:

post-2399-1146201330.png?width=400

Good luck,

Ton

Link to comment

Actually, I realized that I can convert the variant directly (using variant to data) to a 2D array that contains the values. So if I understand correctly, all I need to do is change the array, and then send its values to the location that the handle is associated with? I suppose then I'd need an ActiveX component to take the handle to the array and the new values, and then set the array that is pointed to by the handle to the new values? Thanks so much!

Link to comment
Actually, I realized that I can convert the variant directly (using variant to data) to a 2D array that contains the values. So if I understand correctly, all I need to do is change the array, and then send its values to the location that the handle is associated with? I suppose then I'd need an ActiveX component to take the handle to the array and the new values, and then set the array that is pointed to by the handle to the new values? Thanks so much!

Hi Steve,

You have to make sure WHAT the variant is holding. You could just probe it and the probe would show what data it holds. To get a better feeling, convert the variant to a string if this string is 4 characters width you're having a handle, otherwise you'll have some data. You'll have to dig the ActiveX component to find out what is going on.

Ton

Link to comment
Hi Steve,

You have to make sure WHAT the variant is holding. You could just probe it and the probe would show what data it holds. To get a better feeling, convert the variant to a string if this string is 4 characters width you're having a handle, otherwise you'll have some data. You'll have to dig the ActiveX component to find out what is going on.

Ton

Hi Ton,

I really appreciate your help! Yes, it would be really nice to know what this variant is holding. The probe shows "Value -> Array(Non Displayable)". Flattening it to a string produces a type code that doesn't make sense to me (using the LabVIEW Data Storage Appnote) and a string that is full of whitespace. The type code array has 3 elements. In hex format, they are: 0006, 0084, and 0001.

Trying to convert the variant directly to a string gives me a runtime error and no results.

The literature with the ActiveX component claims that it returns a handle to an array.

So, since I'm not all that comfortable using ActiveX, I thought I'd try and pass the desired array into a DLL function. In the function, I'd make a pointer to a pointer to the array, and then pass that pointer out. I'm not sure how well this will work.

Link to comment
Actually, I realized that I can convert the variant directly (using variant to data) to a 2D array that contains the values. So if I understand correctly, all I need to do is change the array, and then send its values to the location that the handle is associated with? I suppose then I'd need an ActiveX component to take the handle to the array and the new values, and then set the array that is pointed to by the handle to the new values? Thanks so much!

I have a similar situation when a variant is returned from a method I have to convert it to another active x object.

post-584-1146279993.png?width=400

To find the active x reference you can look in the active x browser.

post-584-1146280002.png?width=400

Make sure you have the Show Creatable Object Only box checked.

post-584-1146280013.png?width=400

I Hope this gives you some Ideas

Link to comment
  • 2 weeks later...

Success at last! At first I was trying to write some C code and make a DLL that would handle my variant and change the array values. I found out that what was being passed was not actually a pointer to a pointer, but I still don't really know what it is. There may be a way to make this work with C, but I am not good enough at C to figure it out. Likewise with C++. I realized that the company that provided me with the API used Visual Basic to do all of their example programs, so I made an ActiveX DLL in VB and used that to change my array values. I would strongly recommend using VB if you have to mess with Variants - it is really not picky about what you give it, and the code isn't too hard to write. Here is the function I wrote to take care of things:

Public Function ArrayEdit2D(NewArray As Variant, Cal2DTableData As Object, Rowsize As Integer, Colsize As Integer) As BooleanDim data As ObjectDim matrixData As VariantDim res As BooleanDim row As IntegerDim col As IntegerSet data = Cal2DTableData.GetValue()matrixData = data.GetDoublePhysValue()For row = 0 To (Rowsize - 1)For col = 0 To (Colsize - 1)matrixData(row, col) = NewArray(row, col)Next colNext rowres = data.SetDoublePhysValue(matrixData)res = res And Cal2DTableData.SetValue(data)ArrayEdit2D = resEnd Function

Thanks to everyone who offered their help, and I hope that some day I'll be able to make such useful contributions!

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.