LAnnotation::GetUserData

#include "ltwrappr.h"

virtual L_INT LAnnotation::GetUserData(pUserData, puUserDataSize)

L_UCHAR * pUserData;

/* address of binary data to write */

L_UINT *puUserDataSize;

/* address of variable to updated with length of user data*/

Gets the user-defined data of one or more annotation objects.

Parameter

Description

pUserData

Address into which the binary data is read. Can be NULL.

puUserDataSize

Address of variable to be updated with the length (in bytes) of the user data.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

Use this function to get the associated user-defined data of an annotation object.

When getting the user-defined data, call this function twice: one time with pUserData set to NULL to get the length of the data, and another time to get the actual data.

LAnnotation lObject; 

L_UCHAR *pUserData; 

L_UINT uUserDataSize; 

 

// Assume lObject is a valid annotation object 

lObject.GetUserData(NULL, &uUserDataSize); 

pUserData = (L_UCHAR *)malloc(uUserDataSize); 

lObject.GetUserData(pUserData, &uUserDataSize); 

User data can be binary or text data, and can be any length. When the annotion object is copied, and user data is also copied. When saving the annotation (LAnnContainer::Save, LAnnContainer::SaveMemory, LAnnContainer::SaveOffset), the user data is saved

Required DLLs and Libraries

LTANN

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

See Also

Functions:

LAnnAutomation::SetAutoCursor, LAnnAutomation::GetAutoCursor, Class Members, LAnnotation::SetAutoSnapCursor, LAnnotation::GetAutoSnapCursor

Topics:

Automated User Interface for Annotations

 

Implementing Annotations

Example

//// This sample loads/saves the contents of a BITMAPHANDLE from/to user data of an annotation object

// Call the sample once with bSave set to TRUE, then call it again with bSave set to FALSE to

// load the saved user data as a LMemoryFile

// plObject -- the annotation object

// plBitmap -- the bitmap object is loaded/saved

// bLoad -- TRUE means load from the annotation object, FALSE

L_INT LAnnotation_GetUserDataExample(LAnnotation *plObject, LMemoryFile *plBitmap, L_BOOL bSave) 
{
   L_INT nRet;
   HGLOBAL hGlobal = NULL; 
   L_SIZE_T uUserDataSize; 
   L_UCHAR *pUserData; 
   if (!plBitmap->IsValid()  || !plObject->IsValid())
      return FAILURE; 
   if (bSave) // saving
   {
      LBuffer LMemoryBuffer; 
      nRet = plBitmap->Save(&LMemoryBuffer, FILE_BMP, 24, 0, NULL); 
      if(nRet != SUCCESS)
         return nRet;
      pUserData = (L_UCHAR *)GlobalLock(LMemoryBuffer.GetHandle());
      uUserDataSize = LMemoryBuffer.GetSize();
      nRet = plObject->SetUserData( pUserData ,(L_UINT ) uUserDataSize, ANNFLAG_NOINVALIDATE ); 
      if(nRet != SUCCESS)
         return nRet;
      GlobalUnlock(hGlobal); 
      GlobalFree(hGlobal); 
   }
   else // loading
   {
      // Load 
      LBuffer LMemoryBuffer; 
      nRet = plObject->GetUserData(NULL,(L_UINT  *) &uUserDataSize); 
      if(nRet != SUCCESS)
         return nRet;
      pUserData = (L_UCHAR *)malloc(uUserDataSize); 
      nRet = plObject->GetUserData(pUserData,(L_UINT  *)&uUserDataSize); 
      if(nRet != SUCCESS)
         return nRet;
      LMemoryBuffer= (L_TCHAR *)pUserData; 
      LMemoryBuffer.Reallocate(uUserDataSize); 
      nRet = plBitmap->Load(LMemoryBuffer,  0, ORDER_BGRORGRAY, NULL, NULL); 
      if(nRet != SUCCESS)
         return nRet;
   }
   return SUCCESS;
}