Help with Macintosh programming

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

Archive for January, 2011

Carbon Scrap Manager routines return processStateIncorrectErr

I am trying to get a copy command working in a Carbon app, however
ClearCurrentScrap() and GetCurrentScrap() return
processStateIncorrectErr (-4991). I am running under OS9.2, CarbonLib
1.4, and my app is the front process at the time of copying.

Any ideas?

posted by admin in Uncategorized and have Comment (1)

Simple event handling in Carbon?

Hi all

I am in the process of converting my code to be Carbon compatible for
use under OS X.1.  All my code is console stuff for the processing of
data files, but I use two GUI features:

1) A file dialogue box to allow me to find & open files.

2) A ‘user interrupt check’ that lets the application know if a certain
keystroke has been hit.  This is usually used inside a loop in the
program so I can tell the running program to fall out of the loop from
the OS.  As you can see – it is a function that returns a boolean if the
keystroke has been hit and the function is used inside a loop as

main {

        for( i=1 to BIG ) {
        do process[i];
        if( user_interrupt(35) ) goto clean_up;

        tidy up;

I have solved (1) & I now need to solve (2) as the old Mac method (code
given below) slows down the app to a crawl under Carbon.  I believe the
old polling method is to blame.

/* Return true if Command+` has been hit – good value for ticks 6-30 */
#define SLEEP 35                                    /* by experiment */

Bool    user_interrupt( Card ticks_between )            
Bool got_one = false, SIOUXidEvent;
EventRecord the_event;

static  Bool init = false;
static  LCard last_check;    /* Last time WaitNextEvent was called */

if ( !init ) {                /* Call this first time through to set*/
        last_check = TickCount();
        init = true;

/* If enough time elapsed then poll… */
if ( (Card)( TickCount()-last_check ) > ticks_between ) {                    
        got_one = WaitNextEvent( everyEvent, &the_event, SLEEP, nil );
        last_check = TickCount();                       /* & reset timer */

        if( got_one ) {                      /* if an event was detected */

                /* Let SIOUX know… */
                SIOUXidEvent = SIOUXHandleOneEvent( &the_event );  

/* ..and if Command-` pressed then return true */
                if ( (the_event.what==keyDown) &&
                      (((the_event.modifiers & cmdKey) &&
                       ((the_event.message & charCodeMask) == ‘`’)))) {                                                    

                        ACS_PRINT("\nUser interrupt polled… \n");  
                        return true;

return false;



I have heard that I need to investigate Event Manager but I want to keep
this SIMPLE – is there any sample code that refers to a simple case like
the one I need to address?

The other option would appear to be the use of standard UNIX system
calls – is there any STRAIGHTFORWARD way of checking from inside a
running process to see if a signal of some kind has been sent to it by
the system?  That would be nicer, as it would make the code more
platform-independent for the future.  I guess I would have to start
developing with Project Builder & the UNIX dev tools to take advantage
of that approach.

Many thanks in advance for any thoughts, tips or URLs & please CC
replies to my email.  



     _/_/_/   _/_/_/   _/_/_/              ACS Consultancy
   _/    _/ _/       _/            
  _/_/_/_/ _/         _/_/_/       Information Sciences for Industry
 _/    _/  _/              _/          
_/    _/    _/_/_/   _/_/_/     Tel: 01732~463519   Mobile: 0781~3467381


      `All models are wrong, but some are useful’ – George Box

posted by admin in Uncategorized and have No Comments

Audio with Carbon?


I’m developing an audio application on Mac which uses Carbon. I want to
implement an audio driver. I have downloaded the sdk and I have created my
Carbon test project for this driver. I have obtained some errors in a file
which comes with the sdk. Some functions used in this file, like
SetVol(0L,defVol) and OpenResFile(filename) seems not to be defined in
Carbon. If some functions used in Classic are not defined in Carbon for the
audio, how can I implement the audio on Carbon?

Micheline Ledoux, led…
Software Engineer
Applied Acoustics Systems DVM Inc.

posted by admin in Uncategorized and have Comments (4)

audio driver bugs

I’m writing a game with about 8 parallel asyncronous sound channels.
Everything works fine, but once in a while when it tries to play a sound
it produces wretched screeching static.  I believe the problem
correlates to the program trying to produce several sounds at almost the
same time.  This shouldn’t matter since each time a sound it produced
the 8 channels are scanned for an empty channel and if no channels are
available the sound is dismissed.

Any ideas?


Keith Wiley                                kwi…       

"Yet mark his perfect self-contentment, and hence learn his lesson,
that to be self-contented is to be vile and ignorant, and that to
aspire is better than to be blindly and impotently happy."
                                           –  Edwin A. Abbott, Flatland

posted by admin in Uncategorized and have Comments (4)

OS-X / OS-9 API's for video/TV cards

Are there standard API’s to OS-9 / OS-X for interfacing to
TV/Videocards, like DirectShow on Windows?

posted by admin in Uncategorized and have Comment (1)

Color Palettes under OSX

I have been successful in calling Core Grahics routines to
draw images (aircraft and satellite images) in windows in
a carbon application. (One thing that I haven’t figured out
is how to turn antialliasing off. It seems to always be on
not matter what CGImageCreate – shouldInterpolate is set to or
what the setting is in CGContextSetShouldAntialias.)

My major question though is how does one use palettes or
the equivalent in OSX Core Graphics to blink colors on or off
as one can do with the animate feature in the classic palette
manager? Does anyone have any pointers or example code to

Thanks for any help.

Larry Biehl

posted by admin in Uncategorized and have No Comments

Hex addition

I was just wondering… I’m fairly new to Mac and I’m trying to develop this
cross-platform app…

My main issue is this:

    #define SLUGOS 0×00534943
    #define SLUGOS ‘CIS\0′

Now, I know these two by themselves are equal but when I try to add to them,
they’re no longer equal…

now will the statement:  SLUGOS + i * (0×1 << 24) be equal on the different
platforms?  It seems to work independently on each platform, but the other
platform gives a different #.

Any idea how I would make these 2 equal on the platforms?


Chris Page

posted by admin in Uncategorized and have Comment (1)

MacOS X – Getting Lanhuage Setting

Does anyone know how to get the current language settings as
set in the System Preferences, International – Language panel?


posted by admin in Uncategorized and have No Comments

MacOS X – Getting language settings

Does anyone know how to get the current language settings as
set in the System Preferences, International – Language panel?


posted by admin in Uncategorized and have No Comments


I’m having a trouble in Cocoa-Java foundation NSTimeZone with Apprication
Builder. I want to know if daylight saving time is in use or not for a
given time & date. As I found in Apple’s cocoa document at NSGregorianDate
section(Java) :

  The following code fragment shows a Gregorian date created for 4
  July 1994, 9 PM, Eastern Standard Time:

  NSGregorianDate fireworks = new NSGregorianDate(1994, 7, 4, 21, 0, 0,
                                          new NSTimeZone("EST", true));

But this gives (under 10.04 as well as 10.1)
 Stack Trace:
        java.lang.NullPointerException: alloc or init returned nil
        at Method)

As matter of fact, this
  NSTimeZone  b = new NSTimeZone(1);
gives the same error.

I filed bug report at Apple 5 month ago, no response at all in bug report

Any idea? Or it’s cocoa bug?

posted by admin in Uncategorized and have No Comments