Solved

How to pass array of strings in VB to OCX control

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 42
VB.NET how to use the Vertical ScrollBar 5 103
iSeries DB2 Query 2 95
Excel file not created as expected 7 70
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 …
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

786 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