Passing strucs in OLE
Tad Dutch -- tadutch@fedex.com
Tuesday, May 14, 1996
Config: NT 3.5 & Win95, MFC/VisC++ 4.0
I'm having trouble passing strucs (classes) w/ OLE. I want an OA server to
return a SAFEARRAY, that SAFEARRAY should contain a serialized CObject.
(Would this be the best way to do this?)
There's very little that I can find on the subject and nothing on combining
both serialization and SAFEARRAYs.
It would help me a lot if someone had a code snippet that serialized a
simple class
and then put it in a SAFEARRAY on the server side and then reconstituded it
on the
client end. I've been trying for a week and I still can't get it to work
Thanks
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
| Tad Dutch
| tadutch@fedex.com
| (901) 922-4099
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rob Gue -- rob.gue@gtri.gatech.edu
Wednesday, May 15, 1996
[Mini-digest: 2 responses]
>Config: NT 3.5 & Win95, MFC/VisC++ 4.0
>
>I'm having trouble passing strucs (classes) w/ OLE. I want an OA server to
>return a SAFEARRAY, that SAFEARRAY should contain a serialized CObject.
>(Would this be the best way to do this?)
>There's very little that I can find on the subject and nothing on combining
>both serialization and SAFEARRAYs.
>
>It would help me a lot if someone had a code snippet that serialized a
>simple class
>and then put it in a SAFEARRAY on the server side and then reconstituded it
>on the
>client end. I've been trying for a week and I still can't get it to work
>
>
>Thanks
>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>| Tad Dutch
>| tadutch@fedex.com
>| (901) 922-4099
>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
>
The following Knowledge Base article doesn't address serialization of
objects, but it gives a pointer to a sample program that passes structures
using SAFEARRAYs of unsigned chars.
rob.gue@gtri.gatech.edu
================================
PSS ID Number: Q131046
Article last modified on 02-15-1996
2.03 4.00 | 3.50
WINDOWS | WINDOWS NT
----------------------------------------------------------------------
The information in this article applies to:
- Microsoft OLE Libraries for Windows and Win32s, version 2.03
- Microsoft OLE libraries included with:
- Microsoft Windows NT version 3.5
- Microsoft Windows 95
----------------------------------------------------------------------
BINARY is an OLE Automation server that you can obtain from the Microsoft
Software Library. It demonstrates how to transfer binary data using a
SAFEARRAY of unsigned char. The CTRL directory in this sample contains an
automation controller that will obtain the binary data from the server.
Binary data can be transferred with OLE Automation by using a SAFEARRAY of
unsigned char (VT_ARRAY|VT_UI1). Binary data can also be transferred by
passing the IUnknown of a data trasfer object that supports IDataObject.
This sample uses the first approach, not the second.
Standard controllers like Visual Basic cannot access binary data
transferred through automation. For more information about this, please see
the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q122289
TITLE : Passing Structures in OLE Automation
See the README.TXT in the sample for details on how to compile and run the
sample. After you download BINARY.EXE, use the following command to run it:
BINARY.EXE -d
This builds the directory structure for you.
Download BINARY.EXE, a self-extracting file, from the Microsoft Software
Library (MSL) on the following services:
- Microsoft Download Service (MSDL)
Dial (206) 936-6735 to connect to MSDL
Download BINARY.EXE
- Internet (anonymous FTP)
ftp ftp.microsoft.com
Change to the \SOFTLIB\MSLFILES directory
Get BINARY.EXE
Additional reference words: 3.50 4.00
KBCategory: kbole kbprg kbcode kbfile
KBSubcategory: LeTwoAt
=============================================================================
Copyright Microsoft Corporation 1996.
-----From: CraigTT_at_USNELMIS@ccmail01.PE-Nelson.COM
I actually haven't done this but here is how I'd try it.
On the server side:
1. Create a CMemFile.
2. Create a CArchive using the memfile and store mode.
3. Call the Serialize method on the object passing the archive.
4. Use CFile::GetLength to see how big the serialized object is.
5. Create a SAFEARRAY of bytes to hold the object.
6. Detach the memory from the CMemFile and copy to the SAFEARRAY.
On the client side:
1. Create a CMemFile.
2. Attach the memory from the SAFEARRAY to the memfile.
3. Create a CArchive with the memfile and load mode.
4. Create an instance of the object and call Serialize using the
archive.
5. Detach the SAFEARRAY memory from the memfile.
This can only work on simple classes without embedded pointers.
Embedded actual instances should work however. There is also a
discussion of using SAFEARRAYs to pass structures in the June MSJ.
Tim Craig
PE-Nelson
| Вернуться в корень Архива
|