'OBJECTHEADER : Contains relevant information about object
'
Type OBJECTHEADER
Signature As Integer 'Type signiture (0x1c15)
HeaderSize As Integer 'Size of header (sizeof(struct OBJECTHEADER) + cchName + cchClass)
ObjectType As Long 'OLE Object type code (OT_STATIC, OT_LINKED, OT_EMBEDDED)
NameLen As Integer 'Count of characters in object name (CchSz(szName) + 1)
ClassLen As Integer 'Count of characters in class name (CchSz(szClass) + 1)
NameOffset As Integer 'Offset of object name in structure (sizeof(OBJECTHEADER))
ClassOffset As Integer 'Offset of class name in structure (ibName + cchName)
ObjectSize As PT 'Original size of object (see code below for value)
NameAndClass As String * 255 'Name and class of object
End Type
'Windows kernel function for unique temporary filename
Declare Function GetTempFileName Lib "Kernel" (ByVal cDriveLetter As Integer, ByVal lpPrefixString As String, ByVal wUnique As Integer, ByVal lpTempFileName As String) As Integer
'This DANGEROUS function allows copying data between different variable types
Declare Sub hmemcpy Lib "Kernel" (dest As Any, source As Any, ByVal bytes As Long)
'Checksum function put in DLL for speed
Declare Sub ComputeCheckSum Lib "OLECS.DLL" (CheckSum As Integer, ByVal s As String, ByVal Length As Long)
'Ole declarations
'Comment out if declared elsewhere
Global Const OLE_SAVE_TO_FILE = 11
Global Const OLE_READ_FROM_FILE = 12
Global Const OLE_SAVE_TO_OLE1FILE = 18
Sub CopyAccess1xOleToField (OleObject As Control, FieldObject As Field)
'
' Copies Ole object to Field Control
' writing Access 1.x ole storage format.
' Useful for cross compatibility with
' Access 1.x, but saves object as Ole1.
'
' OleObject : Ole2 control to save
' FieldObject : Database field control to write
'
Dim FileNumber As Integer
Dim FileName As String * 255
Dim OleHeaderString As String
Dim oh As OBJECTHEADER
Dim FileBuffer As String
Dim CheckSum As Integer
Dim FileLength As Long
Dim FileOffset As Long
Dim BufferLength As Integer
Dim HeaderLength As Integer
Dim DocumentClass As String
Dim DocumentName As String
Dim CheckSumString As String
Dim CheckSumCompare As String
Dim Result%
BufferLength = 5128
DocumentClass = OleObject.Class
DocumentName = OleObject.HostName
'Write ole object to temporary file
'We do this first in case it fails
Result% = GetTempFileName(0, "OLE", -1, FileName)
FileNumber = FreeFile
Open FileName For Binary As FileNumber
OleObject.FileNumber = FileNumber
OleObject.Action = OLE_SAVE_TO_OLE1FILE
Close FileNumber
'Create object header
'The extra 2 for Headersize are the null characters