Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
CComVariant platformOutVar;
.....
hr = (pDSPEngine->foo(LibraryName,SpecialFunctionName,inVar,&platformOutVar));


STDMETHODIMP CDSPEnginePC_PI::foo(/*[in]*/ BSTR LibraryName, /*[in]*/ BSTR SpecialFunctionName, /*[in,optional]*/ VARIANT paramIn, /*[out, optional]*/ VARIANT * paramOut)
{			
    
    for (auto it = m_vectorCommBuff.begin(); it != m_vectorCommBuff.end(); it++)
    {
        HRESULT hr = it->get()->foo1(LibraryName,SpecialFunctionName,paramIn,paramOut);       

    }    
}


C++
HRESULT CDSPEngPCCommBuff::foo1(/*[in]*/ BSTR LibraryName, /*[in]*/ BSTR SpecialFunctionName, /*[in,optional]*/ VARIANT paramIn, /*[out, optional]*/ VARIANT * paramOut)
{
    CommBufEntry buf(SYNC, AAA);
    
    //local parameters used for assignments
    CComVariant inVar(paramIn);
    CComBSTR libName(LibraryName);
    CComBSTR sfuncName(SpecialFunctionName);

    buf.bstrData1 = libName.Detach();
    buf.bstrData2 = sfuncName.Detach();
    inVar.Detach(&buf.varData1);
    buf.pVarPtr1 = paramOut;

    AddCommand(buf);

    //releasing BSTRs to avoid memory leak
    SysFreeString(buf.bstrData1);
    SysFreeString(buf.bstrData2);

    LogHResultError(buf.err, __FUNCTION__" LibraryName=%S, SpecialFunctionName=%S", LibraryName, SpecialFunctionName);

    return buf.err;
}


The method CDSPEnginePC_PI::foo has output parameter as type Variant *. I need to convert this Variant * to Safearray *.

But the ouput param of function foo1 should be Varaint *. So I need to create a local variant pointer and pass it to foo1 instead of paramOut.

I need to create a safearray and pass this output variant of foo1 to that safearray and return it. Please help in achieving that.

What I have tried:

I tried to change the function signature from variant to safearray and got the error while compiling, cannot initiate abstract class. I modified in header file too. still get that error.
Posted
Updated 8-Mar-17 7:31am
v3
Comments
Jochen Arndt 8-Mar-17 12:35pm    
What is the type of the output parameter of foo1 (it is variant, but what is in there)?

I would expect some basic type that must be appended to a list while iterating.

So you would have to get the number of iterations first, allocate a safe array, fill it within the loop with the values returned by foo1, and return that array.
Rayner Nirmal 8-Mar-17 13:21pm    
HRESULT CDSPEngPCCommBuff::foo1(/*[in]*/ BSTR LibraryName, /*[in]*/ BSTR SpecialFunctionName, /*[in,optional]*/ VARIANT paramIn, /*[out, optional]*/ VARIANT * paramOut)
{
CommBufEntry buf(SYNC, AAA);

CComVariant inVar(paramIn);
CComBSTR libName(LibraryName);
CComBSTR sfuncName(SpecialFunctionName);

buf.bstrData1 = libName.Detach();
buf.bstrData2 = sfuncName.Detach();
inVar.Detach(&buf.varData1);
buf.pVarPtr1 = paramOut;

AddCommand(buf);

//releasing BSTRs to avoid memory leak
SysFreeString(buf.bstrData1);
SysFreeString(buf.bstrData2);

LogHResultError(buf.err, __FUNCTION__" LibraryName=%S, SpecialFunctionName=%S", LibraryName, SpecialFunctionName);

return buf.err;
}
[no name] 8-Mar-17 13:27pm    
How is about LPSAFEARRAY* vs. your LPSAFEARRAY?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900