IDesignerRegistration::GetRegistrationInfo

Returns an array of bytes that the host later passes to DllRegisterDesigner and DllUnregisterDesigner.

HRESULT GetRegistrationInfo(
   BYTE **ppbRegInfo,
   ULONG *pcbRegInfo
);

Parameters

ppbRegInfo

[out] Indirect pointer to a string of bytes.

pcbRegInfo

[out] Pointer to the number of bytes in ppbRegInfo.

Return Values

The designer returns one of the following values:

Return Value Meaning
S_OK Success.
Other statuses Errors.

Comments

The visual designer implements this method. The designer also must set the DESIGNERFEATURE_REGISTRATION and DESIGNERFEATURE_CANBEPUBLIC flags in the registry.

The GetRegistrationInfo method allows a designer to pass registration data to the host at design time; in turn, the host passes the same data to DllRegisterDesigner and DllUnregisterDesigner at run time. Designers use this method to register information specific to an authored object. For example, an object might need to register a component category so its class is visible to certain tools.

The format of ppbRegInfo is designer-specific. You must decide on a format for the array and ensure that GetRegistrationInfo, DllRegisterDesigner, and DllUnregisterDesigner all use it.

The designer must allocate the array with CoTaskMemAlloc; the host calls CoTaskMemFree to free it. The host passes the array in the rgbRegInfo member of the DESIGNERREGINFO structure passed to DllRegisterDesigner and DllUnregisterDesigner.

Example

The following code fragment implements GetRegistrationInfo. It determines how much memory is required for the registration information, allocates sufficient space to store the information, and writes the information into the allocated space, keeping track of the number of bytes of data written. Before returning, it sets ppbRegInfo and pcbRegInfo to point to the data and byte count.

STDMETHODIMP CAddinDesigner::GetRegistrationInfo
(
   BYTE** ppbRegInfo, 
   ULONG* pcbRegInfo
)
{
   BYTE *pRegInfo;
   int nInfoSize, nCurSize, nDataSize;
   int nNameSize = 0, nDescSize = 0, nRegLocSize = 0;

   //First check to make sure we have the initial string.
   if (!m_AddinInfo.pszRegLocation)
        return E_FAIL;
 
   //If so, get string lengths. We need to save data, so get it all.
   nRegLocSize = strlen(m_AddinInfo.pszRegLocation) + 1;
   if (m_AddinInfo.pszDisplayName)
      nNameSize = strlen(m_AddinInfo.pszDisplayName) + 1;
   if (m_AddinInfo.pszDescription)
      nDescSize = strlen(m_AddinInfo.pszDescription) + 1;
   nDataSize = GetDataSize();

   // Allocate space. 
   // The information includes textual labels for the entries, 
   // the length of each label, and the entry itself.
   nInfoSize = sizeof(int) + nRegLocSize + sizeof(int) + nNameSize + 
      sizeof(int) + nDescSize + sizeof(int) + nDataSize;
   pRegInfo = (BYTE *)CoTaskMemAlloc(nInfoSize);

   // Write out all the data.
   // The first item is a string indicating the registry location, 
   // followed by the length of that string. 
   memcpy(pRegInfo, (BYTE *)&(nRegLocSize), sizeof(int));
   nCurSize = (sizeof(int));
   if (m_AddinInfo.pszRegLocation)
   {
      memcpy(pRegInfo + nCurSize, (BYTE *)m_AddinInfo.pszRegLocation, 
         (nRegLocSize));
      nCurSize += (nRegLocSize);
   }
   //  Now copy the other items. Remember to update the current size
   //  each time we copy.
   //.
   //.  Deleted for brevity
   //.

   // Store our info
   //
   *ppbRegInfo = pRegInfo;
   *pcbRegInfo = nCurSize;
   return S_OK;
}

See Also

DllRegisterDesigner, DllUnregisterDesigner, DESIGNERFEATURE_REGISTRATION