ACC: Finding the OLE ClassKey of an Embedded Object (1.x/2.0)

Last reviewed: May 8, 1997
Article ID: Q99319
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0

SUMMARY

Advanced: Requires expert coding, interoperability, and multiuser skills.

Microsoft Access places a wrapper of information around an OLE object before it stores the object in a table. The Name and ClassKey of the object start at byte count 21 and are stored from there as two zero-terminating strings. By reading the field as a text field, you can parse out the ClassKey.

This article describes how to use Access Basic to find the ClassKey of an embedded object with an OLE-Object data type.

NOTE: This technique does not work if the OLE object is larger than 64K. In this case you'll see the error:

   Object has no value

MORE INFORMATION

When an OLE object is stored in a table, the ClassKey is the second null-terminated string after the 20th byte in the object. It can be read as text with the following Access Basic code:

NOTE: In the following sample code, an underscore (_) is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.

   Function GetObjectClass$ ()
      If IsNull(screen.activeform!Photo) Then
         GetObjectClass$ = "n/a"
      Else
         MyChunk$ = Mid(screen.activeform!Photo, 21, 40)
         NullOne% = InStr(1, MyChunk$, Chr$(0))
         NullTwo% = InStr(NullOne% + 1, MyChunk$, Chr$(0))
         GetObjectClass$ = Mid(MyChunk$, NullOne% + 1, _
                               NullTwo% - NullOne% - 1)
      End If
   End Function

The GetObjectClass$() function first checks to see if the object is null and returns the value "n/a" if it is. If the object is not null, it assigns bytes 21 through 40 of the OLE object to the string MyChunk$ and then searches for the first null character, the next null character, and so forth. Finally, it sets the GetObjectClass$() function equal to the string between the two null characters.

Using the function provided above, a control on the Employees form of the sample database NWIND.MDB, with the properties below, displays the ClassKey for the Photo control:

   ControlName: ObjClassKey
   ControlSource: =GetObjectClass()

This example returns "PBRUSH" for the first photo in the Employees table.

There are several different ways to use this information. RegQueryValue(), a function contained in the Microsoft Windows SHELL.DLL file, uses the ClassKey to obtain information about that class from the REG.DAT file.

REFERENCES

For more information about calling the RegQueryValue() function to get the Class Name of an OLE object, please see the following article here in the Microsoft Knowledge Base.

    ARTICLE-ID: Q99322
    TITLE:      ACC: Calling RegQueryValue() to get an OLE Object Class
                Name

Microsoft Windows "Programmer's Reference," version 3.1, Volume 2, page 282


Additional query words: dll classname class key
Keywords : IntpOle
Technology : kbole
Version : 1.0 1.1 2.0
Platform : WINDOWS
Hardware : X86
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 8, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.