Re: vm blocks, structs, and pointers
Edward Di Geronimo Jr. (edwdig@bergen.org)
Tue, 31 Dec 1996 10:49:48 -0500
At 01:58 AM 12/31/96 -0500, you wrote:
>In a message dated 96-12-30 19:48:21 EST, edwdig@bergen.org (Edward Di
>Geronimo Jr.) writes:
>
>> 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 /* <--- TYPO(?) */ ), 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; /*<---- */
>/**** Again, where did this get defined? "primaryVMH" ****/
>>
>> /* 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; /****Not defined ***/
>> 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)
>>
>
>Check out the points above that I marked...I'm surprized that the compiler
>didn't give you complaints about these undefined variable names. You need to
>check your spelling and variable names when you get these errors...and if you
>didn't get them, why not? If you did, why did you ignore them? I am
>presuming that you copied and pasted the above text..so it should be the same
>that is in your code.
Ok, what happened was I just copied and pasted parts of the functions and
didn't copy all my variable declarations. Let's see...
mapblock (lowercase b) is a struct, which contains primaryVMH (and other things)
map is a pointer to a mapblock
MemHandle maphandle, objHandle;
VMBlockHandle mapBlock, primaryVMHandle;
Anything else I forgot?
These are two seperate methods, not one. I put a comment saying which method
they were from. The only compiler warnings I've gotten from these functions
are "suspicious pointer convertion" on some on my attempts to get the
pointers right.
------------------------------------------------------------------------
| 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 |
------------------------------------------------------------------------