vm blocks, structs, and pointers

Edward Di Geronimo Jr. (edwdig@bergen.org)
Mon, 30 Dec 1996 19:40:57 -0500

Hi everyone,

This question is more a C question than GEOS. Here's what I have:

typedef struct {
char name[33];
char moniker[129];
char reserved[64];
} GenObjectData;

#define CLASS_DATA_SIZE 512 - ((3 * sizeof(VMBlockHandle)) +
sizeof(GenObjectData) + 64) /* all on one line in source file */
#define CLASS_DATA_OFFSET 512 - CLASS_DATA_SIZE

typedef struct {
VMBlockHandle VM_comp;
VMBlockHandle VM_link;
VMBlockHandle VM_lastchild;
word objType;
GenObjectData objData;
char reserved[64];
char classdata[CLASS_DATA_SIZE];
} VMObject;

(The structs are shortened a little to make it easier)

/* inside MSG_GEN_DOCUMENT_INITIALIZE_DOCUMENT_FILE */

VMBlockHandle mapBlock, primaryVMBlock;
MemHandle maphandle, appHandle, appLMemHandle;
MemHandle primaryHandle, primaryLMemHandle;
appBlock *app;
optr newitem;
VMObject *objBlock;

VMFileHandle file = pself->GDI_fileHandle;
EC(ECVMCheckVMFile(file));

mapBlock = VMAlloc(file, sizeof(mapblock), 0);
EC(ECVMCheckVMBlockHandle(file, mapBlock));
VMSetMapBlock(file, mapBlock);

map = VMLock(file, mapBlock, &maphandle);

primaryVMBlock = VMAlloc(file, sizeof(VMObject), 0);
EC(ECVMCheckVMBlockHandle(file, primaryVMBlock));
objBlock = VMLock(file, primaryVMBlock, &primaryHandle);
map->primaryVMH = primaryVMBlock;

/* removed initializing of other variables in the struct */
strcpy(objBlock->objData.name, "Window");
strcpy(objBlock->objData.moniker, "Main Window");

VMDirty(primaryHandle);
VMUnlock(primaryHandle);

/* ... */

/* Inside MSG_GEN_DOCUMENT_ATTACH_UI_TO_DOCUMENT */

mapBlock = VMGetMapBlock(file);
map = VMLock(file, mapBlock, &maphandle);
primaryVMHandle = map->primaryVMH;
VMUnlock(maphandle);

char name[33];

primaryVM = VMLock(file, primaryVMHandle, &objHandle);
strcpy(name, objBlock->objData.name);
@call newitem::MSG_GEN_REPLACE_VIS_MONIKER_TEXT(name, VUM_NOW);
VMUnlock(objHandle);
/* also tried directly using the string from the vm file instead of copying */

Basically, any time I try to get at the name or moniker it crashes. But if I
use a hex editor on the vmfile created, I can see that it did copy the
strings into the file. So what's the correct way to get pointers to the
strings I'm using?

(Couldn't find an answer in a C book)

------------------------------------------------------------------------
| I've always been afraid to die, but I think I'm more afraid to live. |
| -Billy Corgan, Smashing Pumpkins, The Aeroplane Flys High |
------------------------------------------------------------------------
| Edward Di Geronimo Jr. edwdig@bergen.org |
------------------------------------------------------------------------