Use OptrToChunk and OptrToHandle. They are macros that extract the portion
of the optr that you want, either the ChunkHandle or the MemHandle.
> Next, what's wrong with this? I'm using the GenDocument system with output
> sent to the process object. mapblock (lowercase) is a struct. It crashes
> when I try to lock the lmem block, complaining I have an invalid handle.
Is
> there a way for swat to tell me which handle is the problem?
>
> (And please don't anyone complain about my style of stuff like having
> mapblock and mapBlock. My first concern is always getting it to work, then
> cleaning it up.)
Okay, then let me say that's probably the wrong order. If you write it
right the first time, you'll be less confused with your own code and it will
take less time to develop. Plus it makes it easier for others to understand
your code. You will believe.
> @method MyProcessClass, MSG_META_DOC_OUTPUT_INITIALIZE_DOCUMENT_FILE
> {
> VMBlockHandle mapBlock, objectvm;
> MemHandle maphandle, OBlock;
>
> mapBlock = VMAlloc(file, sizeof(mapblock), 0);
> VMSetMapBlock(file, mapBlock);
>
> map = VMLock(file, mapBlock, &maphandle);
> objectvm = VMAllocLMem(file, LMEM_TYPE_GENERAL, 0);
> map->objblock = objectvm;
> VMLock(file, objectvm, &OBlock);
> .
> .
> .
> return(FALSE);
> }
Here's what I would do:
@method MyProcessClass, MSG_META_DOC_OUTPUT_INITIALIZE_DOCUMENT_FILE
{
/*
* vmhMapBlock - VM file map block as a VMem handle.
* objectvm - ?
* mhMapBlock - VM file map block as a Mem handle.
* OBlock - ?
*/
VMBlockHandle vmhMapBlock;
VMBlockHandle objectvm;
MemHandle mhMapBlock;
MemHandle OBlock;
/*
* First check the validity of the parameters.
* Allocate a block in the VM file and make it
* the map block.
*/
EC( ECVMCheckVMFile( file ); )
vmhMapBlock = VMAlloc( file, sizeof( vmhMapBlock ), 0 );
EC( ECVMCheckVMBlockHandle( file, vmhMapBlock ); )
VMSetMapBlock( file, vmhMapBlock );
/*
* Lock the new map block. Check the return values.
* Allocate an LMem heap inside the map block.
* Check those return values.
*/
map = VMLock( file, vmhMapBlock, &mhMapBlock );
EC( ECCheckMemHandle( mhMapBlock ); )
EC( ECCheckBounds( map ); )
objectvm = VMAllocLMem( file, LMEM_TYPE_GENERAL, 0 );
EC( ECVMCheckVMBlockHandle( file, objectvm ); )
/*
* ?
*/
map->objblock = objectvm;
VMLock( file, objectvm, &OBlock );
.
.
.
/*
* Unlock the two blocks and return.
*/
MemUnlock( mhMapBlock );
MemUnlock( OBlock );
return( FALSE );
} /* MSG_META_DOC_OUTPUT_INITIALIZE_DOCUMENT_FILE */
Adding the EC code will help you catch where the bad handle is.
Nathan