Help with Macintosh programming

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

Archive for August, 2012

progress dialog

I’d like to create a progress dialog box while saving a large file
from my application. I have tried to create a modal DB and calling
DoDialog() inside the for loop of my saving routine, however, I can
only see a "blank" dialox, there is no content in it, my code is as
follows:

StDialogHandler theHandler(RESID, …);

for (i=0; i<totalLineNum; i++)
{
    // save data one line at a time      
    saveData(buf, …);

    theHandler.DoDialog();

}

I wonder if it is necessary for me to create a more complicated
progress dialog (for example, using another thread to launch the
dialog)? And if there is any sample code I can use? Thanks!

.
posted by admin in Uncategorized and have Comment (1)

NSOutlineView, calling reloadData during setObjectValue causes crash?

I’ve got two very similar things going on in both an NSOutlineView and an
NSTableView.  If the user edits the text in the leftmost column, this
changes the key in a dictionary, which can cause the data to be reordered.
If this happens in outlineView:setObjectValue:forTableColumn:byItem, I send
a reloadData: to the NSOutlineView instance after the data used by the data
source has been changed.

In an NSTableView, this works fine.  In an NSOutlineView, this causes a
crash sometime after setObjectValue: has returned.  I’ve checked and
re-checked my data source.  Especially since an NSTableView works just fine,
is there a known problem or limitation that isn’t documented about doing
this in an NSOutlineView?  If there’s something else I need to do instead,
what is it?

posted by admin in Uncategorized and have Comments (4)

[Q] IOKit: Inside the bowels of IOHIDSystem

Hi everyone

I try to understand the kernel/userland interface of the IOHIDSystem
driver in MacOS X. I wrote the following test code, strongly inspired
from XDarwin sources. But whatever happens, I never get any event for
moved mouse in the low level queue.

Anyone has an idea why?

#include <mach/mach_types.h>
#include <mach/mach_host.h>
#include <mach/mach_traps.h>
#include <mach/mach_init.h>

#include <IOKitLib.h>
#include <IOLLEvent.h>
#include <IOHIDShared.h>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>

void dump(char *, size_t);

/*
 * cc -Wall -Werror -ansi \
 * -I/System/Library/Frameworks/IOKit.framework/Headers \
 * -I/System/Library/Frameworks/IOKit.framework/Headers/hidsystem \
 * -L/System/Library/Frameworks/IOKit.framework -g
 * -o test -lIOKit test.c
 */
int
main(argc, argv)
        int argc;
        char **argv;
{
        host_name_port_t hs;
        io_master_t iop;
        kern_return_t ret;
        mach_port_t rp;
        CFMutableDictionaryRef classToMatch;
        char *cn = "IOHIDSystem";
        io_iterator_t iterator;
        io_object_t serviceObject;
        io_connect_t    dataport;
        vm_address_t shmem;
        vm_size_t size;
        EvGlobals *evg;
        int i;
        int log;

        if (argc != 2) {
                printf("usage: %s logfile\n", argv[0]);
                return 1;
        }

        log = open(argv[1], O_WRONLY|O_TRUNC|O_CREAT, 0644);
        if (log == -1) {
                perror("cannot open log file");
                return 1;
        }

        rp = mach_reply_port();
        hs = mach_host_self();

        ret = IOMasterPort(MACH_PORT_NULL, &iop);
        printf("ret = 0x%x, rp = 0x%x, hs = 0x%x, iop = 0x%x\n",
            ret, rp, hs, iop);
        if (ret != 0)
                return 1;

        classToMatch = IOServiceMatching(cn);

        ret = IOServiceGetMatchingServices(iop,
            classToMatch, &iterator);
        printf("ret = 0x%x, iterator = 0x%x\n", ret, iterator);
        if (ret != 0)
                return 1;

        serviceObject = IOIteratorNext(iterator);
        printf("serviceObject = 0x%x\n", serviceObject);

        ret = IOServiceOpen(serviceObject, mach_task_self(),
            0, &dataport);
        printf("ret = 0x%x, dataport = 0x%x\n", ret, dataport);
        if (ret != 0)
                return 1;

        ret = IOHIDCreateSharedMemory(dataport,
            kIOHIDCurrentShmemVersion);
        printf("ret = 0x%x\n", ret);
        if (ret != 0)
                return 1;

        ret = IOConnectMapMemory(dataport, kIOHIDGlobalMemory,
            mach_task_self(), &shmem, &size, kIOMapAnywhere);
        printf("ret = 0x%x, shmem = 0x%x, size = 0x%x\n",
            ret, shmem, size);
        if (ret != 0)
                return 1;

        evg = (EvGlobals *)(shmem +
            ((EvOffsets *)shmem)->evGlobalsOffset);
        printf("evg = %p\n", evg);
        if (evg == NULL)
                return 1;

        evg->movedMask = NX_MOUSEMOVEDMASK;

        printf("Perform an action within 3 seconds… \n");
        sleep(3);
        printf("Okay, let’s dump in the logfile…\n");

        (void)close(1);
        (void)dup(log);

        printf("LLEHead = %d\n", evg->LLEHead);
        printf("LLETail = %d\n", evg->LLETail);
        printf("LLELast = %d\n", evg->LLELast);
        for (i = 0; i < LLEQSIZE; i++) {
                printf("item %d\n", i);
                printf("  next = %d, type = %d, flags = %d\n",
                    evg->lleq[i].next,
                    evg->lleq[i].event.type,
                    evg->lleq[i].event.flags);
                printf("  x = %d, y = %d, window = %d\n",
                    evg->lleq[i].event.location.x,
                    evg->lleq[i].event.location.y,
                    evg->lleq[i].event.window);
                dump((char *)&evg->lleq[i].event.data,
                    sizeof(evg->lleq[i].event.data));
        }
        printf("\n\nFull dump of the shared memory\n");
        dump((char *)shmem, size);

        return 0;

}

void
dump(data, len)
        char *data;
        size_t len;
{
        int i, j;

        for (i = 0; i < len; i += 16) {
                printf("%p  ", &data[i]);
                for (j = i; j < i + 16; j += 4)
                        printf("0x%08x ", *((int *)(&data[j])));
                printf("  ");
                for (j = i; j < i + 16; j++)
                        if (isprint(data[j]))
                                printf("%c", data[j]);
                        else
                                printf(".");
                printf("\n");
        }
        return;

}


Emmanuel Dreyfus
m…@netbsd.org

posted by admin in Uncategorized and have Comment (1)

[Carbon] how do i get a list of users and groups??

hey all, i’ve been struggling to figure out how to get a list of users and
groups like the finder’s get info window displays in its ownership &
permissions section.

i’m not too familiar with unix, and i’m using carbon to write this program
(on os x) and haven’t found anything in apple’s documentation (big surprise)
except for the function PBGetUGEntrySync which i can’t get to work for the
life of me (i keep getting -50 errors for every possible variation of the
parameters).

if anyone out there knows how to do this (seemingly normal) task, please
post back.

thanks in advance,
logan


Logan Murray – lo…@electricstorm.com
AIM: MrCiv  ICQ: 29648209

posted by admin in Uncategorized and have Comments (2)

Coding reliable HTML email for viewing on a Mac

OK , so here’s the thing.
I’ve written a mass-mailer that sends out HTML newsletters to subscribers.
The message is sent with both an HTML and a plain text component but I’m
receiving reports of the message being garbled on Macs.

I’m awaiting screen shots, user info, OS version, mail clients used etc. ,
but in the mean time, does anyone know of a useful resource that might
shed some light on this ?

Many thanks,

Wayne
wa…@inxcom.com

posted by admin in Uncategorized and have Comment (1)

Box width problems using DHTML – only on MacIE

Hi!

I’m coding a webpage that uses javascript for a dynamic menu; this
works fine on all browsers I tried (on PC and GNU/Linux) and it works
on Safari/Mozilla on the Mac side.  Only Mac-IE chokes on it.  I have
no Mac on hand to do trial-and-error, and I badly want to make it
work, I wonder:

* Do you know about DOM functions that are badly implemented/broken on
MacIE?
* Is there any known trouble with widths when boxes are generated
dynamically?

I’ve read
http://www.xs4all.nl/%7Eppk/js/browsers5.html#ie5mac but could not
find anything wrong- is there a better resource?

The page I’m working on is http://journeesdelaculture.qc.ca/ and the
defective script is located at
http://journeesdelaculture.qc.ca/menu_array.js

I’d be grateful for any pointer as I’m mostly working blindly.

Thanks!

posted by admin in Uncategorized and have No Comments

Keys in an NSDictionary

I’d like to implement my own class for use as keys in an NSDictionary.
My first try was to subclass NSObject and implement isEqual: and hash,
which is what the NSDictionary documentation implies is necessary.

When that didn’t work, I subclassed NSString, but had problems
initializing super with the text I wanted.

Does anyone know what the requirements are, or where they might be
documented?

(Or is this not possible?  I note that the GNUstep documentation says
that the key must be an NSString.  Apple’s documentation just says that
the key is an object.)

Thanks,
Steve

posted by admin in Uncategorized and have Comments (7)

CGContextRef

I’m trying to display the contents of a CGContextRef in my NSWindow’s
drawInRect method. I’m wondering if there is a way I could do something
similar to NSImage’s ‘ drawInRect:fromRect:operation:fraction: ‘ method. I
want to draw a part (sub rect) of my CGContextRef into a larger rect in my
NSWindow. NSCopyBits will do something like this, but it requires a graphics
state which I seem to understand will require a window with the CGContext
data already drawn into it.

Does anyone have any ideas? I can’t seem to find a function to help me with
this.

Thanks
Tim

posted by admin in Uncategorized and have No Comments

Outlet between 2 controller object

In Interface Builder the IBOulet "from_A_to_B" was  added to Controller_A
and a connection made from Controller_A to Controller_B

Controller_A.m hold the code

   int v;

   v = [from_A_to_B test_int];

Controller_A.h hold the declaration (in @interface Controller_A : NSObject)

   IBOutlet id from_A_to_B;

Controller_B.m hold the code

   - (int)test_int
   {
   return 12345;
   }

Controller_B.h hold the declaration

   - (int)test_int;

The compiler report this error

   Error   : unknown message selector
   Controller_A.m line 13   v = [from_A_to_B test_int];

Do I have made an illegal IB connection ?
What code is missing/wrong ?

Thank you.

posted by admin in Uncategorized and have Comments (6)

Where do I find header?

I need to find the header where certain AFP errors are found like
kFPBadUAM and others. Where can I find this?

posted by admin in Uncategorized and have Comment (1)