Board index » cppbuilder » Import an Interface to a Variant

Import an Interface to a Variant

I would like to pack an interface to a variant in order to communicate with
an
existing COM Dll ( implemented using DELPHI ).

SAFEARRAY   *pSafeArray;                     // Declaring a SafeArray
Variant StoreParamsVar;                             // Declaring a Variant
SAFEARRAYBOUND abound[1];            // Declaring the bounds and elements of
the array

IDispatch *pdisp = NULL;                         // Dispatch Type

abound[0].lLbound = 0;                              // Array Bounds &
Elements
abound[0].cElements = 1;

IitPMtoOWStoreFromProdParams  *spProdParams;                        // This
is the COM Interface
spProdParams = CoitPMtoOWStoreFromProdParams::Create();      // Instatiation
of the COM Object

pSafeArray =::SafeArrayCreate(VT_DISPATCH, 1, abound);
// An Array of Type Dispatch
pSafeArray->fFeatures = FADF_AUTO | FADF_DISPATCH | 0x0040;

for (long i = ZERO_VALUE; i < ONE_VALUE; i++)

{
// filling the interface with Values
        spProdParams->nRequestSeries  = CStrInf.ReqSeries;
        spProdParams->nRequestID      = CStrInf.ReqID;
        spProdParams->dQtyS{*word*99}ped    = ZERO_VALUE;
        spProdParams->dQtyShipped     = ZERO_VALUE;

        spProdParams->nCostCenter     = (*dbwrhouse)->WRHID;
        spProdParams->nProdMType      = (*dbobjects)->OBProdMType;
        spProdParams->nProductID      = (*dbobjects)->OBProduct;

        spProdParams->QueryInterface(IID_IDispatch, (void**)&pdisp);
// Querying Interface
        spProdParams->AddRef();
        SafeArrayPutElement(pSafeArray, &i, &spProdParams);
// Inserting Interface to SafeArray
    }

StoreParamsVar.vt = VT_DISPATCH | VT_ARRAY;
StoreParamsVar.parray = pSafeArray;

When the program reaches the QueryInterface line produces an access
violation error.
What I am really interesting is to find HOW CAN I INSERT AN INTERFACE OR A
STRUCTURE TO A VARIANT using C++ Builder.
Any suggestions are welcome.

Thanks in Advance.

 

Re:Import an Interface to a Variant


Unless the DLL is explitically expecting an array, you don't need  a
SAFEARRAY just to pass an interface, VARIANT supports both IUnknown and
IDispatch directly.

    Variant StoreParamsVar;
    IitPMtoOWStoreFromProdParams  *spProdParams;
    IDispatch *pdisp = NULL;

    // fill spProdParams ...

    spProdParams->QueryInterface(IID_IDispatch, (LPVOID*)&pdisp);
    StoreParamsVar = pdisp;

Gambit

Quote
"George Adamopoulos" <cosmi...@teledomenet.gr> wrote in message

news:3e3d455e@newsgroups.borland.com...
Quote
> I would like to pack an interface to a variant in order to
> communicate with an existing COM Dll ( implemented
> using DELPHI ).

Other Threads