Link to home
Start Free TrialLog in
Avatar of JOKER
JOKER

asked on

return SAFEARRAY to VB

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 :)
Avatar of jkr
jkr
Flag of Germany image

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;  
    }
}
Avatar of JOKER
JOKER

ASKER

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
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
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial