Solved

How to pass array of strings in VB to OCX control

Posted on 1998-05-14
3
294 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now