Solved

How to pass array of strings in VB to OCX control

Posted on 1998-05-14
3
306 Views
Last Modified: 2013-11-20
I have a problem of passing array of string to methods of OLE controls. The only option I have is  VARIANT (from the MFC CLASS WIZARD), however, the array pass is of vt 0x2008, i.e. array, string, but NOT byref (no 0x4000), and if I use that for the safearray, it is locked and I cannot release it at the exit of the control. From the example I got from Microsoft (mfcsafearray), it uses ByRef|Array|BSTR (0x4000,0x2000,0x008), it works well in DLL's, but not in OLE controls (ocx), the array of strings I passed is passed NOT as ByRef, what can I do?
0
Comment
Question by:hshliang
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
Norbert earned 100 total points
ID: 1311347
First a question do you wish to change the strings for VB or are they only used as input ?
if they are only used for input copy them
and don't care about release VB will do it
if you want to change for VB
try to encapulate them into a variant:
VB Code:
Dim Holder as variant
Holder=MyStringArray
result=MyControl.MyMethod(Holder)
now your Method gets a VT_BYREF|VT_VARIANT variant
and you can access it if your function is named as
SomeMethod(const VARIANT FAR& SomeVariant)
SomeVariant.pvarVal where you should can do everything

Note:
You should never store an safearray delivered by OLE for later use. You should better copy it

Hope that helps
Regards
    Norbert
PS:Greetings from germany
0
 

Author Comment

by:hshliang
ID: 1311348
Thanks a miilion, your advice is useful, but I don't seems to ge ByRef when I do your second trick, like:
Dim v as variant
Dim s() as string

v=s
MyControl.MyMethod v
or
MyControl.MyMethod s()

Both example give a Variant in C++ as I said ARRAY|BSTR

I am using VB 4, is that a problem?

Somehow, I got a way around it, I create a subroutine:

Sub AddString(ByRef v as variant)
     MyControl.MyMethod v
End Sub

then in my application I do:

AddString s()

That trick VB to supply a ByRef variable to the method

Is that the only way?

Any better ideas?

Well, at least I got my program to work (albeit a bit crumblesome)!

Thank you again, I am sure you know how frustrating when you are stuck with some problem that no body can help. I really appreciate your help.

Henry
0
 
LVL 3

Expert Comment

by:Norbert
ID: 1311349
I am happy that I could help
about the ByRef I am not sure
but perhaps it is possible to change the TypeLib
to say that the method always should take a parameter
ByRef but I am not familar with that

Norbert
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

749 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