Help with Macintosh programming

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

Archive for May, 2010

Is OT C++ compatible (or only C)?

I know it seems like a ridiculous question, but here’s the thing.  I
downloaded the OTSimpleDownloadHTTP and OTSimpleServerHTTP from Apple.
Both programs are C projects and a little bit of touching is necessary
to get the OTSimpleDownloadHTTP program to compile (implicit conversion
from void* to char* has to be explicit, little stuff).  However, the
OTSimpleServerHTTP has a serious problem.  It defines the following function:

static pascal void YieldingNotifier(EndpointRef ep, OTEventCode code,
        OTResult result, void* cookie)
{
        etc.

}

and tries to pass this function to OTInstallNotifier like:
OSStatus junk = OTInstallNotifier(ep, &YieldingNotifier, ep);

This won’t compile because YieldingNotifier has the wrong structure.
Note that the OTSimpleDownloadHTTP does compile, but it looks like this:

static pascal void YieldingNotifier(void* contextPtr, OTEventCode code,
        OTResult result, void* cookie)
{
        etc.

}

OSStatus junk = OTInstallNotifier(ep, &YieldingNotifier, ep);

See?  The difference between void* and the EndpointRef in the first
parameter to YieldingNotifier can’t be reconciled.  If I turn off the
Activate C++ code switch in my project, everything compiles fine, but
this is unacceptable.  It means I can’t write C++ for heaven’s sake!

What’s the solution.  Thank you for any help.

. . .. … ….. …….. …………. …………………
.. … ….. ……. ……….. …………. ……………..
. .. …. …….. ……………. …………………………..
Keith Wiley                            *
kwi…@cs.unm.edu                       *   * *     *   *      *
http://www.unm.edu/~keithw            ***    **   * *    **     *
http://www.listensmart.com/Keith (mp3 music) *     **   **    ***

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

using zlib with low memory

Hi.

I try to compress and decompress data (p.e. from a file) with small
buffers (I want to call deflate and inflate in a loop).

The sample code from the file "example.c" inside the zlib package is to
short to help me.

Does someone have a sample code?

You can see my routines below, but it fails with an error (unknown data
format for decoding).

infile and outfile are file ref numbers.

//———————————————————————-
// Encode
// Encoding/Compressing
//———————————————————————-
void  ZipClass::Encode (void)  
{
   long     fileSize,
            ioCount = sizeof (long);
   OSStatus err = GetEOF (infile, &fileSize);

   if (err == noErr)
      err = FSWrite (outfile, &ioCount, &fileSize);
   if (err == noErr)
   {
      z_stream z;
      Ptr         input_buffer = NewPtr (kBufferSize),
               output_buffer = NewPtr (kBufferSize);

      z.zalloc = (alloc_func)0;
      z.zfree = (free_func)0;
      z.opaque = (voidpf)0;

      err = deflateInit (&z, Z_DEFAULT_COMPRESSION);

      z.avail_in = 0;

      while (z.total_in < fileSize)
      {
         if (z.avail_in == 0)
         {
            ioCount = kBufferSize;
            err = FSRead (infile, &ioCount, input_buffer);
            if (err == noErr || err == eofErr)
               err = noErr;
            else
               break;
            z.avail_in = ioCount;
            z.next_in  = (unsigned char *) input_buffer;
         }

         z.avail_out = kBufferSize;
         z.next_out = (unsigned char *) output_buffer;

         err = deflate (&z, Z_NO_FLUSH);

         if (err == Z_OK)
         {
            ioCount = kBufferSize – z.avail_out;
            if (ioCount != 0)
            {
               err = FSWrite (outfile, &ioCount, &output_buffer);
               if (err != noErr)
                  break;
            }
         }
         else
            break;
      }
      z.avail_in = 0;
      z.next_in  = NULL;
      while (err == Z_OK)
      {
         z.avail_out = kBufferSize;
         z.next_out = (unsigned char *) output_buffer;
         err = deflate (&z, Z_FINISH);
         if (err == Z_OK)
         {
            ioCount = kBufferSize – z.avail_out;
            if (ioCount != 0)
            {
               err = FSWrite (outfile, &ioCount, &output_buffer);
               if (err != noErr)
                  break;
            }
         }
         // if (err == Z_STREAM_END)
        //     break;
       }

       err = deflateEnd (&z);

      if (input_buffer != NULL)
         DisposePtr (input_buffer);
      if (output_buffer != NULL)
         DisposePtr (output_buffer);
   }

}

//———————————————————————-
// Decode
// Decoding/Uncompressing
//———————————————————————-
void  ZipClass::Decode (void)  
{
   long        fileSize,
               ioCount = sizeof (long);
   OSStatus    err = FSRead (infile, &ioCount, &fileSize);

   if (err == noErr)
   {
      z_stream z;
      Ptr         input_buffer = NewPtr (kBufferSize),
               output_buffer = NewPtr (kBufferSize);

      z.zalloc = (alloc_func)0;
      z.zfree = (free_func)0;
      z.opaque = (voidpf)0;

      err = inflateInit (&z);

      z.avail_in = 0;

      while (z.total_in < fileSize)
      {
         if (z.avail_in == 0)
         {
            ioCount = kBufferSize;
            err = FSRead (infile, &ioCount, input_buffer);
            if (err == noErr || err == eofErr)
               err = noErr;
            else
               break;
            z.avail_in = ioCount;
            z.next_in  = (unsigned char *) input_buffer;
         }

         z.avail_out = kBufferSize;
         z.next_out = (unsigned char *) output_buffer;

         err = inflate (&z, Z_NO_FLUSH);

         if (err == Z_OK)
         {
            ioCount = kBufferSize – z.avail_out;
            if (ioCount != 0)
            {
               err = FSWrite (outfile, &ioCount, &output_buffer);
               if (err != noErr)
                  break;
            }
         }
         else
            break;
      }
      z.avail_in = 0;
      z.next_in  = NULL;
      while (err == Z_OK)
      {
         z.avail_out = kBufferSize;
         z.next_out = (unsigned char *) output_buffer;
         err = inflate (&z, Z_FINISH);
         if (err == Z_OK)
         {
            ioCount = kBufferSize – z.avail_out;
            if (ioCount != 0)
            {
               err = FSWrite (outfile, &ioCount, &output_buffer);
               if (err != noErr)
                  break;
            }
         }
         // if (err == Z_STREAM_END)
        //     break;
       }

       err = inflateEnd (&z);

      if (input_buffer != NULL)
         DisposePtr (input_buffer);
      if (output_buffer != NULL)
         DisposePtr (output_buffer);
   }

- Hide quoted text — Show quoted text -

}

posted by admin in Uncategorized and have Comment (1)

Tab problem

I have a dialog with several tabs in it. In one, the user can enter some
data. When the user clicks okay (which is the button outside the tabs!), my
app examines the entered data and complains if some data is missing or
wrong. So long, so good.

But I want to complain also when the user has entered wrong data and then
wants to change tab. I can prevent the new tab from displaying (= the items
in it) but the system activates the new tab. And I can’t prevent this
because when the program enters my eventfilter procedure of the ModalDialog,
the new tab is already activated.

(I thought of posting a mouseclick event with PPostEvent. This would exactly
fit my needs, but I don’t know the coordinates of the point to pass in this
call. Where is this active region stored?)

Thanks for any help
John

posted by admin in Uncategorized and have Comments (5)

proxy code?

Anyone know how to implement proxy support?  Any source code examples?

thanks!
Bill
wmodes…@mac.com_NOSPAM

posted by admin in Uncategorized and have Comments (3)

Multiprocessing under MacOS 9.1

I am using the multiprocessing SDK to use the 2nd processor
on my Dual G4 PowerMac .   I pass a pointer to a structure
with a bunch of pointers to the arrays and variables I need.
It’s not clear to me what if any of these I need to allocate
using MPAllocate() rather than vec_alloc() or malloc().  The
debugger correctly shows the contents of the variables and arrays to
which the passed structure points.  But I’m not totally confident
that everything little thing is there and will remain as things
evolve.  The multiprocessing stuff is more difficult to debug
so I’m trying to get the memory stuff straight first.  Any thoughts
or experience would be welcome.  Thanks.

Don

posted by admin in Uncategorized and have No Comments

Drawing round pen using QuickDraw?

**** Post for FREE via your newsreader at post.usenet.com ****

I’m trying to draw using a round pen shape on QD. My current implementation
uses a DDA algorithm where each pixel is drawn as a round rect. This works
fine but when exporting to PICT, the resulting file has as many objects as
there are rects. So I’d like to convert those to a series of LineTo calls
instead. Is there a published algorithm to do that? Is there a better way?

TIA
Karim

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 *** Usenet.com – The #1 Usenet Newsgroup Service on The Planet! ***
                      http://www.usenet.com
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

posted by admin in Uncategorized and have Comments (7)

AHGotoHelp

Assalamu 3alaikum,
I am trying to to use the function AHGotoPage in the classic
environment. But I seem not to have included the library file
where it is definied. I don’t want to use CarbonLib. Does anyone
know where the function is definied? If not, does anyone know a
function that will take the path of an html help file and open
it in the help viewer?
Thanks….

posted by admin in Uncategorized and have Comment (1)

meaning of frontwindow()

Hi!
I am totally new to mac programming and have to port an application which
will send messages to the actual running application.
I am using Powerplant because of the simplicity, and wrote an application
which executes a specific function on idling.
this function uses frontwindow to determine the most top window.
the point is that I always get the windowptr of my own application window in any
case. If i switch to another program like netscape for example frontwindow still
returns the handle of my programwindow. ( the function outputs the title of the
determined window continously to a file).
What I am doing wrong? HELPPPPP

Please could you also add a CC to my email : Goekhan.Ba…@dlr.de

Thanks in advance.

Goekhan BakIr


_____________________________________________________________
NewsGroups Suchen, lesen, schreiben mit http://netnews.web.de

posted by admin in Uncategorized and have Comments (2)