Solved

How to pass array of strings in VB to OCX control

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Separate into files by filename 12 92
matchUp  challenge 9 134
noX challenge 17 144
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 1,689
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

738 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