?
Solved

return SAFEARRAY to VB

Posted on 2003-03-13
4
Medium Priority
?
840 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
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

621 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