Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to pass array of strings in VB to OCX control

Posted on 1998-05-14
3
Medium Priority
?
334 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
[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
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
Norbert earned 400 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

721 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