DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    bas6421 Guest

    passing SAFARRAY of UDTs


    Hello,
    I am trying to understand how I can return a SAFEARRAY of UDTs from the C++
    client back to the VB COM dll.
    Here is a layout:
    UDT (udtVB)is being defined in an ActiveX dll created with VB. C++ code #imports
    that dll, attempts to allocate a SAFEARRAY of those UDTs and put it back
    to that VB dll.

    Here are some snippets of code:
    ...

    #import "C:\\vb.dll" rename_namespace("VBData")
    using namespace VBData;

    ...
    SAFEARRAY *pSA;
    HRESULT hresult;

    VBData::udtVB *pVBdata;


    hresult = CLSIDFromProgID(OLESTR("VBObject.CData"),&clsid);
    _CData *pD;
    hresult=CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,__uuidof(_CData),(LPVOID
    *) &pD);
    if(FAILED(hresult))
    {
    return 0;
    }

    SAFEARRAYBOUND rgsabound = {2, 0};
    // crash here:
    pSA = ::SafeArrayCreateEx(VT_RECORD, 1, &rgsabound, pVBdata );


    According to MSDN docs :
    "...If the UDT is not stored in a VARIANT you can pass a pointer to the UDT
    (last parameter in SafeArrayCreateEx ) because an IRecordInfo pointer can
    be retrieved from the UDT type description..."

    Is this correct? Or I have to use GetRecordInfoFromGuids(...,IRecordInfo)
    and get IRecordInfo from there? The ploblem is that I don't have an IDL
    for that dll. How can I get IRecordInfo?

    Any help?

    Thanks

  2. #2
    ralph Guest

    Re: passing SAFARRAY of UDTs


    "bas6421" <cplus.@127.0.0.1> wrote:
    >
    >Hello,
    >I am trying to understand how I can return a SAFEARRAY of UDTs from the

    C++
    >client back to the VB COM dll.
    >Here is a layout:
    >UDT (udtVB)is being defined in an ActiveX dll created with VB. C++ code

    #imports
    >that dll, attempts to allocate a SAFEARRAY of those UDTs and put it back
    >to that VB dll.
    >
    >Here are some snippets of code:
    >...
    >
    >#import "C:\\vb.dll" rename_namespace("VBData")
    >using namespace VBData;
    >
    >...
    >SAFEARRAY *pSA;
    >HRESULT hresult;
    >
    >VBData::udtVB *pVBdata;
    >
    >
    >hresult = CLSIDFromProgID(OLESTR("VBObject.CData"),&clsid);
    >_CData *pD;
    >hresult=CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,__uuidof(_CData),(LPVOID
    >*) &pD);
    >if(FAILED(hresult))
    >{
    > return 0;
    >}
    >
    >SAFEARRAYBOUND rgsabound = {2, 0};
    >// crash here:
    >pSA = ::SafeArrayCreateEx(VT_RECORD, 1, &rgsabound, pVBdata );
    >
    >
    >According to MSDN docs :
    >"...If the UDT is not stored in a VARIANT you can pass a pointer to the

    UDT
    >(last parameter in SafeArrayCreateEx ) because an IRecordInfo pointer can
    >be retrieved from the UDT type description..."
    >
    >Is this correct? Or I have to use GetRecordInfoFromGuids(...,IRecordInfo)
    >and get IRecordInfo from there? The ploblem is that I don't have an IDL
    >for that dll. How can I get IRecordInfo?
    >
    >Any help?
    >
    >Thanks


    UDT's can be treated like structs in that the layout is similar - just remember
    that VB's integer is 16-bit and the UDTs are always padded to 4 bytes.

    But more useful to you, is that you likely do have an "IDL" for the DLL.
    Open the VB COM DLL with OLE View, then open the typelib. Cut'n Paste the
    typelib into a text file, name the file myVBCom.idl, then compile with the
    midl compiler - you have a typelib. (You might have to do some minor massaging.)
    If the UDT isn't defined completely, just add it yourself.

    -ralph

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links