Path: utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!hoptoad!tim From: tim@hoptoad.uucp (Tim Maroney) Newsgroups: comp.sys.mac.programmer Subject: Re: Integer Size problem Message-ID: <8362@hoptoad.uucp> Date: 22 Aug 89 08:38:42 GMT References: <15141@dartvax.Dartmouth.EDU> Reply-To: tim@hoptoad.UUCP (Tim Maroney) Organization: Eclectic Software, San Francisco Lines: 70 In article <15141@dartvax.Dartmouth.EDU> xxiaoye@eleazar.dartmouth.edu (Xiaoxia Ye) writes: >the WIND resource' first 8 bytes are its positions on the screen: top, >left, bottom and right. I tried to save the window postions and so to >write to the first 8 bytes of the WIND resource. A perfectly legitimate tactic -- this is how the system desk accessories save their changed positions and sizes. Doesn't work too well if you have multiple windows originating from the same window template, though, and that's probably the more common case. >I have my rectange declared as (it's in THINK C): >Rect myRect; >and I get a handle to the WIND resource: >myHandle=GetResource('WIND',MY_WIND_RES_ID); > >after I lock the Handle and do the following to assignment to the >resource: >**myHandle=myRect.top; **myHandle is a character, not an integer. Problem 1. >**myHandle+=2; If I've got my precedences sorted right, this will add two to the first character stored in the handle. Rather pointless. Probably what you meant was *myHandle += 2. However, this is evil, because you are changing the master pointer for a handle. You need to use your own pointer to do this sort of thing; don't mess with the master pointer which the handle indicates. Problem 2. >**myHandle=myRect.left >... blah blah and did this for all four coordinates. >and do a ChangedResource, and UpdateResFile, etc ... > >What happened was: >say that I have the following eight bytes in my WIND resource (in Hex): >0044 0043 0056 0098 >and say that myRect.top = 0x60, myRect.left=0x60, myRect.bottom=0x80 and >myRect.right=0x80. > >and when I examined what was written to the resource, I found out that >first 8 bytes of WIND resource became: >6044 6043 8056 8098 >in another words, if I just do an integer assignment, I don't get 00 >padding and have the proper alignment. Why?? Hmm. Looks like your pointer incrementing is working after all. I don't know why -- perhaps the version above is not what you have in your code. But the point is moot, as Rev. Jackson would say. You are only assigning to character-width fields because a Handle is a char **. >Well, eventually, I gave up and wrote a little routine to copy the bytes >myself (actually the THINK C inline assembly would do the job). If I were doing this, what I'd do would be a lot simpler: BlockMove(&myRect, *myHandle, sizeof(Rect)); To do your approach right, you need to declare an integer pointer like short *iPtr = (short *)*myHandle; iPtr[0] = myRect.top; iPtr[1] = myRect.left; and so on. I think the BlockMove is better. Better still, you can always declare the handle to be a Rect ** and just use the C assignment operator: Rect **myHandle; myHandle = (Rect **) GetResource('WIND', MY_WIND_RES_ID); **myHandle = myRect; -- Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com "Don't talk to me about disclaimers! I invented disclaimers!" - The Censored Hacker