• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
MFC Porting Issues
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

MFC Porting Issues


  • Subject: MFC Porting Issues
  • From: Kevin Wojniak <email@hidden>
  • Date: Fri, 20 Jan 2006 15:43:27 -0500

I am trying to port an MFC app to Cocoa, and am having some issues.

Here is where the problem starts:

DWORD i;
PWXPicture *pic = nil;
for (i = 0; i < m_BufferSize; i+= 4)
{
	if (pic = [PWXPicture pictureWithData:&m_Buffer[i]])
	{
		[m_Pictures addObject:pic];
		i += 4;
	}
}

This method goes through some data (m_Buffer is of type LPBYTE, unsigned char) and determines if the current part of the data is valid and if so, puts it into an NSMutableArray (m_Pictures).

Here's the class/code that analyzes the data:

+ (id)pictureWithData:(LPBYTE)lpBuffer
{
	PWXPicture *pic = [[PWXPicture alloc] init];
	if ([pic read:lpBuffer])
		return [pic autorelease];
	[pic release];
	return nil;
}

- (BOOL)read:(LPBYTE)lpBuffer scan:(BOOL)bScan
{
m_pHeader = (IPOD_PICTURE_HEADER *)lpBuffer; // <---- problematic, I think

// swap bytes
m_pHeader->height = CFSwapInt32LittleToHost(m_pHeader->height);
m_pHeader->width = CFSwapInt32LittleToHost(m_pHeader->width);
m_pHeader->w1 = CFSwapInt16LittleToHost(m_pHeader->w1);
m_pHeader->bitDepth = CFSwapInt16LittleToHost(m_pHeader->bitDepth);
m_pHeader->d2 = CFSwapInt32LittleToHost(m_pHeader->d2);
m_pHeader->blockLen = CFSwapInt32LittleToHost(m_pHeader->blockLen);

// blah blah check the data...
}



Here's the structure:

typedef struct
{
	BYTE b1[8];
	DWORD height;
	DWORD width;
	WORD w1;
	WORD bitDepth;
	DWORD d2;
	DWORD blockLen;
} IPOD_PICTURE_HEADER;


BYTE = unsigned char DWORD = unsigned long WORD = unsigned char

For each iteration of the loop, I examined the contents of the m_pHeader structure on my Mac (after the bytes were swapped) and PC using the debugger (Xcode and Visual Studio). The first time through the loop, the data is exactly the same on both computers. On the second time, some are the same, and some aren't. Thus, the code doesn't work on the Mac (with the equivalent MFC code on the PC).

Is there something I'm missing with that type casting into a DATA_STRUCT struct from an unsigned char? Some kind of endian issue I'm not seeing?

Any help would be much appreciated. I attempted to change the code to use NSData and getBytes:range: method, which did partially improve it, but that is horribly slow, and I want to keep the code as similar to the original as possible.

Thanks,
Kevin
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: MFC Porting Issues
      • From: Shawn Erickson <email@hidden>
  • Prev by Date: Re: NSApplication terminate: behavior
  • Next by Date: Re: MFC Porting Issues
  • Previous by thread: NSSearchField Predicate Failure: Unable to use '<attribute name> == $value' for scalers
  • Next by thread: Re: MFC Porting Issues
  • Index(es):
    • Date
    • Thread