-
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
-
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks