Help with Macintosh programming

macintosh programming, mac programming, mac os programming, mac os x programming, mac programming language, mac programing

Archive for June, 2012

a bundle of troubles

Hi,

I create a bundled shared library that should work in Mac OS 9
and Mac OS X. I want to use the CFBundleOpenBundleResourceFiles
API to open proper localized resource file.
CFBundleOpenBundleResourceFiles requires bundleRef. As far as
I understand, the bundle is not open for me, thus I have to open
it myself (presumably with CFBundleCreate). CFBundleCreate
required bundle URL. Bundle URL could be obtained if bundle
FSRef/FSSpec is known. But I don’t know it. On Mac OS 9 the init
proc of shared library is called with FSSpec parameter that
specifies the library executable itself, not the bundle folder.
Hence my question: given the FSSpec of the main file in bundle,
how to get the FSSpec for the bundle itself? Currently I take
the great-grandparent of the main file and consider it to be a
bundle. This is not very good, because it depends upon
particular bundle structure: Lib.cfm/Contents/MacOSClassic/Lib.
Is there better way?


Mike Kluev.

PS. Remove "-DELETE-." part of my e-mail address to reply.

.
posted by admin in Uncategorized and have Comments (5)

Displaying Help files

Hi,

following Apple’s instructions I managed to create a Help Book folder and
created all the necessary items in the info.plist file of my Carbon
application to make the files display in Apple’s Help Viewer.

In OSX everything works fine. In OS9 I only see a plain HelpViewer window
when choosing the Help menu item of my app. What can be wrong here?
—————-
Sebastian Wegner

http://www.mcsebi.com/

posted by admin in Uncategorized and have No Comments

OS X: How to catch exceptions of App Kit's "NSImage.initWithContentsOfFile"

I hope somebody can help me:

I’m developing a digital image recovery software and cannot
catch an exception (SIGINT 2) caused by the Application Kit
method "NSImage.initWithContentsOfFile".

I added exception handling (see below), modified the exception
handling mask and overwrote the NSApplication.reportException
but no of them is called upon the exception.
The reason of the exception is an invalid JPGEG image stored
on disk (in fact an Exif header without following JPEG data).

The type of exception (SIGINT 2) is only shown when debugging
the app, not in build run. After the exception occured, the
application is not terminated and the process is hanging in
the NSImage.initWithContentsOfFile and this is never left.

How can I catch the exception of this NSImage method?

Any help would be very much appreciated.

Thanks in advance!

Sincerely,

Alexander Grau

——————————————————–
I did exception handling on the NSImage.initWithContentsOfFile…

  NS_DURING

    // all exceptions I raise here are catched – but not the following
method call…
    img = [[NSImage alloc]initWithContentsOfFile: aPath];  

  NS_HANDLER
    NSLog(@"Error creating thumbnail for: %@", aPath);
    img = nil;
  NS_ENDHANDLER

——————————————————–
I have set the expcetion handling mask…

int main(int argc, const char *argv[])
{
    // this catches also system exceptions, but does not work for
    // NSImage.initWithContentsOfFile… (also tried a value of 255
and 65535)

    [[NSExceptionHandler defaultExceptionHandler]
setExceptionHandlingMask: 63];

}

——————————————————–
I have overwritten the NSApplication.reportException,
but nothing is called in NSImage.initWithContentsOfFile …

@interface MyApp : NSApplication {

}

-(void)reportException:(NSException*)anException;
@end

-(void)reportException:(NSException*)anException{

  NSLog(@"Exception: %@ Reason: %@", [anException name], [anException
reason]);

- — -

}

posted by admin in Uncategorized and have Comments (3)

jikes doesn't like \\

I’m trying to get jikes on os x to compile source that compiles fine
with jikes on windows, and with javac on os x. Most files complile
fine, but any files containing regex double backslashed escape
sequences die with a unicodish sounding error message:

[reinhard@mac14182 ui]$ jikes TranscriptEditPanel.java

Found 2 lexical errors in "TranscriptEditPanel.java":

   402.             return locationString.replaceAll("\\\s","\n");
                                                        ^^
*** Lexical Error: Invalid escape sequence.

   531. \u0000
        ^—-^
*** Lexical Error: Illegal token.

Found 1 syntax error in "TranscriptEditPanel.java":

   531. \u0000
        ^—-^
*** Syntax: } expected instead of this token
[reinhard@mac14182 ui]$

A few comments on this error message:

1) it reports inaccurate information. The cited line in the source
reads:

            return locationString.replaceAll("\\s","\n");

Which as far as I can see is OK by the spec and compiles fine with
javac and jikes on windows. I use the same version of jikes on windows
(1.1.7).

2) line 531 is the end of the program. There is no funny character
there. This message goes away when I remove the double backslash from
line 402. It seems like the double backslash on 402 so discombobulates
the compiler that it starts seeing ghost errors on other lines.

It seems I can get around this by replacing the double backslashes
with  the unicode escape sequence: "\u005c." At least, it compiles. I
get other even more mysterious messages on other files that prevent me
from running the whole application and testing (but I’ll worry about
that seperately).

Double backslashes were bad enough, but this unicode gibberish is just
crazy. It makes perl look positively beautiful. Please tell me I’m
being an idiot and there’s some compiler/env setting I can tweak to
have double backslashes work again…

But don’t tell me to stick with javac. After having used lightning
fast jikes for two years on windows, I can’t go back to the slowness
of javac… I’d rather go back to windows.

Here is my jikes/java/os x info (nothing funny here, just most recent
software updates/developer tools/java developer tools):

[reinhard@mac14182 ui]$ jikes -version
Jikes Compiler – Version 1.17 – 27 September 2002
(C) Copyright IBM Corp. 1997, 1998, 1999, 2000, 2001, 2002.
– Licensed Materials – Program Property of IBM – All Rights Reserved.
Originally written by Philippe Charles and David Shields of IBM
Research,
Jikes is now maintained and refined by the Jikes Project at:
<http://ibm.com/developerworks/opensource/jikes>
Please consult this URL for more information and for reporting
problems.

[reinhard@mac14182 ui]$ java -version
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-39)
Java HotSpot(TM) Client VM (build 1.4.1_01-14, mixed mode)
[reinhard@mac14182 ui]$

reinhard@mac14182 ui]$ echo $CLASSPATH
/System/Library/Frameworks/JavaVM.framework/Versions/1.4.1/Classes/classes. jar:/System/Library/Frameworks/Java\
VM.framework/Versions/1.4.1/Classes/ui.jar:/System/Library/Frameworks/JavaV M.framework/Versions/1.4.1/Classes/\
dt.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.1/Classes/c harsets.jar:/System/Library/Framewo\
rks/JavaVM.framework/Versions/1.4.1/Classes/jce.jar:/System/Library/Framewo rks/JavaVM.framework/Versions/1.4.1\
/Classes/jsse.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4. 1/Classes/laf.jar:/Users/reinhard/c\
alhoun:/Users/reinhard/calhoun/external/alignment.jar:/Users/reinhard/calho un/external/biojava.jar:/Users/rein\
hard/calhoun/external/bytecode.jar:/Users/reinhard/calhoun/external/netscap e.jar:/Users/reinhard/calhoun/exter\
nal/oracle.jar:/Users/reinhard/calhoun/external/xerces.jar

I have a similarly configured ibook at home which gives me the same
errors.

Thanks in advance to anyone who takes the time to give this a look.
Even if you have no idea what my problem is, I’d be interested to hear
from anyone who has gotten jikes to work on os x and uses it
regularly, just to rekindle my hope. Otherwise I don’t know if I’ll be
able to resist going back to the beige side…

Reinhard

posted by admin in Uncategorized and have Comment (1)

pthread_cancel on OS X

Hi All,

I’m working on porting some code over to OS X (10.2.5). It is my
understanding that while pthread_cancel exists its currently broken
and that the work around would be to add pthread_testcancel() to
create a cancellation point around where I need the cancellation to
occur. My actually problem is that I think the program needs to cancel
during a select (I’m still a little new to the code I’m porting) and
it never gets to the pthread_testcancel. From a message posted about a
year ago a gentleman seemed to have a similar problem and he said he
was going to attempt to "weave in sending a signal that causes the
select() to return an ‘interrupted system call’". I was wondering how
this would be done. Or if anyone had any other ideas how to get past
this problem.

Any suggestions you have would be greatly appreciated. Thanks a lot.

-joe

posted by admin in Uncategorized and have Comment (1)

Re: learning applescript from a c/java perspective

In article <no-C2432F.01095823042…@netnews.upenn.edu>,
 Mark Haase <n…@spam.please> wrote:

> I’m curious in learning how to use AppleScript, but I can’t find any
> good tutorials on the internet that aren’t aimed at complete newbies.
> Basically I just want something that explains AppleScript in a way that
> somebody who can already program proficiently in C or java would benefit
> from.

Are you interested in learning how to write C and Java apps that are
appleScriptable and recordable?

You might take a look at the chapter on appleScript in the Advanced
PowerPlant book, a .pdf on the Metwerks Codewarrior documentation
CD. Also, Apple has a web page on appleScript for application
developers.

<http://www.google.com/search?q=appleScript+developer+site%3Aapple.com>

posted by admin in Uncategorized and have Comments (3)

How to trap Mach exception "EXC_BAD_ACCESS"

As the OS X Application Kit class "NSImage.initWithContentsOfFile"
causes a Mach exception "EXC_BAD_ACCESS" on damaged JPEG image files I
need to trap this. (I write a data recovery tool and these type of
images are usual).

So is it possible to trap a mach exception (of another process?) and
how to do this? I tried using UNIX signal(SIGSEGV) function, but no
success… So what can I do?

Thanks in advance for any hint!

Alexander

http://groups.google.de/groups?q=%22Alexander+Grau%22&hl=de&lr=&ie=UT…

posted by admin in Uncategorized and have Comments (7)

DrawString in OS X

Hi,

when I use:

moveto(-50, 100);
DrawString(myString);

the string is written correctly on my window. It starts 50 pt off-screen and
the end of the string reaches into the window.

But when I use:
mypicture = OpenPicture(&theRect);
moveto(-50, 100);
DrawString(myString);
ClosePicture();
DrawPicture(mypicture,&theRect);

the minus sign is ignored and the string starts at +50 pt.

This only happens in OS X (10.2), not in OS 9!
And when I use LineTo instead of DrawString everything is fine.

Is this a bug in OS X or have I done something wrong?
And is there a way around this?
(I use CodeWarrior 7)

Any help is highly appreciated! Thanks.

J. Waters

posted by admin in Uncategorized and have Comments (5)

ECLIPSE IDE Platform on Mac OS X

I am trying to test the Pac os x version, it’s quite ok until I try to
Run and Launch a Java apps…
The Launch configuration panel appears
I can select ‘Java application’ and hit the ‘New’ button … but
nothing happen…

where I am wrong ? the installation is automatic… no specific warning
during installation
no specific configuration statements for mac os x…

posted by admin in Uncategorized and have No Comments

Link error

I am getting a link error in refernece to LStr255 when trying to convert to a
double. the error message is; undefined ‘dec2num’(code) Referenced from
‘LString::operator double() const’ in LString.cp

I am also getting the same link error with ‘str2dec’

Adfl…@aol.com

posted by admin in Uncategorized and have No Comments