AnnSaveMemory example for Visual J++

Note: This topic is for Document/Medical only.

This example lets you save the current annotations to a file in memory, and lets you load the annotations that were saved.

1. Start with the project that you created in Creating and Using Annotations.

2. Add the following to the private section of your main form:

/** @dll.import("Kernel32") */
private static native int GlobalFree( int hMem );

private int m_hMem;
private int m_iSize;

3. image\btncmd.gif At the top of your main form, add two buttons and name them as follows:

Name

Text

AnnSaveMem

Save In Memory

AnnLoadMem

Load From Memory

4. Code the AnnSaveMem button's Click event as follows:

int nMem[]  = new Variant( new SafeArray( Variant.VariantInt, 1 ) ).toSafeArray().toIntArray();
int nSize[] = new Variant( new SafeArray( Variant.VariantInt, 1 ) ).toSafeArray().toIntArray();
nMem[0] = 0;
if( LEAD1.AnnSaveMemory( nMem, (short) LTOCXU.AnnFormatConstants.ANNFMT_NATIVE, false, nSize  ) != 0 )
   MessageBox.show( "Error calling AnnSaveMemory" );
else
{
   m_hMem = nMem[ 0 ];
   m_iSize = nSize[ 0 ];
}

5. Code the AnnLoadMem button's Click event as follows:

// Load the annotations from the memory-resident file.
if( LEAD1.AnnLoadMemory( m_hMem, m_iSize ) != 0 )
   MessageBox.show( "Error calling AnnLoadMemory" );
else
   MessageBox.show( "AnnLoadMemory succeeded" );

GlobalFree( m_hMem );

6. Run your program to test it.