?
Solved

return SAFEARRAY to VB

Posted on 2003-03-13
4
Medium Priority
?
833 Views
Last Modified: 2007-12-19
Hello

I have a DLL in C++ and a Visual basic (6) client
application.

I need to pass an empty vector of structures from the client
to the DLL, and return it full from the DLL.
I need that the client will declare the vector as "Vector()"
and the DLL function will return the number of
cells in the vector (the DLL function will fill the Vector).

The CLIENT part will look like this :
-------------------------------------
dim Ret as long
dim VecMadadim() as SomeStructure

Ret = RequestFunction(VecRequest(), nRecordCount)
for i=1 to Recordcount
      print VecMadadim(i).Field1
      print VecMadadim(i).Field2
      print VecMadadim(i).Field3
next i

The DLL part will look like this :
-------------------------------------
int __stdcall RequestMadadim(SAFEARRAY** psaRequest, int* nRecordCount)
{
   ...
}

Thank you very much :)
0
Comment
Question by:JOKER
[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
4 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 8130849
Check out the following MSKB sample: http://support.microsoft.com/default.aspx?scid=kb;EN-US;131086 ("SAMPLE: SAFEARAY: Use of Safe Arrays in Automation")

Basically, you would

int __stdcall RequestMadadim(SAFEARRAY** ppsa, int* nRecordCount)
{
    HRESULT hr;
    long lLBound, lUBound;

    // Check dimensions of array                
    if (SafeArrayGetDim(*ppsa) != 1)                
        return ResultFromScode(E_INVALIDARG);

    for ( long l = lLBound; l < lUBound; l++)
    {
         hr = SafeArrayPutElement(*ppsa, &l, SomeStructure);
        if (FAILED(hr))
            // handle error;  
    }
}
0
 

Author Comment

by:JOKER
ID: 8145666
jkr,

Thanks for this but,
this is not what I asked for,
I need that in VB i will decalre the array
like this - > "TheArray() as string"
NOT like this -> "TheArray(10) as string"

I need that the DLL will set the number of cells
in the array .

Thanks
0
 
LVL 9

Expert Comment

by:tinchos
ID: 9491807
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ/Refund

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 9537693
PAQed, with points refunded (500)

Computer101
E-E Admin
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

801 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