Professional Web Applications Themes

Using GetSharedLibrary in a Mach-O application - Mac Programming

Hi Can I use GetSharedLibrary in a Mach-O application? Or is there a workaround to load a CFM shared library in a Mach-O application? I use this shared library only because I can't link a CFM library in a Mach-O application which I use. Thanks for the help Regards Hans...

  1. #1

    Default Using GetSharedLibrary in a Mach-O application

    Hi

    Can I use GetSharedLibrary in a Mach-O application?
    Or is there a workaround to load a CFM shared library in a Mach-O
    application?

    I use this shared library only because I can't link a CFM library in a
    Mach-O application which I use.

    Thanks for the help

    Regards
    Hans


    Hans Stoessel Guest

  2. #2

    Default Re: Using GetSharedLibrary in a Mach-O application

    dans l'article bkevqj$139a5$1ID-142477.news.uni-berlin.de, Hans Stoessel à
    [email]hstoessel.listpm-medici.ch[/email] a écrit le 19/09/03 15:20:
    > Hi
    >
    > Can I use GetSharedLibrary in a Mach-O application?
    > Or is there a workaround to load a CFM shared library in a Mach-O
    > application?
    >
    > I use this shared library only because I can't link a CFM library in a
    > Mach-O application which I use.
    >
    > Thanks for the help
    >
    > Regards
    > Hans
    >
    >
    I think you need to use GetDiskFragment and FindSymbol.

    Eric

    Eric VERGNAUD Guest

  3. #3

    Default Re: Using GetSharedLibrary in a Mach-O application

    Hi

    Thanks for your help. Now I can load the fragment and I found my function in
    it. But if I try to call this function, the system crashs with the message:
    "unknown PowerPC" exception. I have a test application (Mach-O bundle) and a
    shared CFM library which I want load in the test application.

    Here is the code I use:

    //--------------------------------------------------------------------------
    --
    // Test application: Test.cpp
    //--------------------------------------------------------------------------
    --
    static pascal int (*beepTwice) (void);

    static pascal OSErr loadLibrary()
    {
    OSErr myerr;
    CFragConnectionID connID = kInvalidID;
    FSSpec fsSpec;
    CFragSymbolClass symClass;

    myerr = FSMakeFSSpec(0, 0, "\pShlb4DOpen", &fsSpec);
    myerr = GetDiskFragment(&fsSpec,
    0,
    kCFragGoesToEOF,
    NULL,
    kLoadCFrag,
    &connID,
    NULL,
    NULL);

    myerr = FindSymbol (connID, "\pBeepTwice",
    (Ptr*) &beepTwice, &symClass);

    beepTwice();

    return myerr;
    }


    //--------------------------------------------------------------------------
    --
    // Shared Library: BeepTwice.c
    //--------------------------------------------------------------------------
    --
    #include <Sound.h>

    #pragma export on

    int BeepTwice ( void );

    #pragma export off

    int BeepTwice (void)
    {
    SysBeep(2);
    SysBeep(2);
    return 0;
    }

    Is it maybe a C/C++ problem?
    Or a problem with the keyword pascal?

    Thanks and Regards
    Hans



    "Eric VERGNAUD" <eric.vergnaudwanadoo.fr> schrieb im Newsbeitrag
    news:BB91573C.126BC%eric.vergnaudwanadoo.fr...
    > dans l'article bkevqj$139a5$1ID-142477.news.uni-berlin.de, Hans Stoessel
    à
    > [email]hstoessel.listpm-medici.ch[/email] a écrit le 19/09/03 15:20 :
    >
    > > Hi
    > >
    > > Can I use GetSharedLibrary in a Mach-O application?
    > > Or is there a workaround to load a CFM shared library in a Mach-O
    > > application?
    > >
    > > I use this shared library only because I can't link a CFM library in a
    > > Mach-O application which I use.
    > >
    > > Thanks for the help
    > >
    > > Regards
    > > Hans
    > >
    > >
    >
    > I think you need to use GetDiskFragment and FindSymbol.
    >
    > Eric
    >

    Hans Stoessel Guest

  4. #4

    Default Re: Using GetSharedLibrary in a Mach-O application

    > Thanks for your help. Now I can load the fragment and I found my function in
    > it. But if I try to call this function, the system crashs with the message:
    > "unknown PowerPC" exception. I have a test application (Mach-O bundle) and a
    > shared CFM library which I want load in the test application.
    >
    > Here is the code I use:
    >
    > //--------------------------------------------------------------------------
    > --
    > // Test application: Test.cpp
    > //--------------------------------------------------------------------------
    > --
    > static pascal int (*beepTwice) (void);
    >
    > static pascal OSErr loadLibrary()
    > {
    > OSErr myerr;
    > CFragConnectionID connID = kInvalidID;
    > FSSpec fsSpec;
    > CFragSymbolClass symClass;
    >
    > myerr = FSMakeFSSpec(0, 0, "\pShlb4DOpen", &fsSpec);
    > myerr = GetDiskFragment(&fsSpec,
    > 0,
    > kCFragGoesToEOF,
    > NULL,
    > kLoadCFrag,
    > &connID,
    > NULL,
    > NULL);
    >
    > myerr = FindSymbol (connID, "\pBeepTwice",
    > (Ptr*) &beepTwice, &symClass);
    >
    > beepTwice();
    >
    > return myerr;
    > }
    The following should work (I haven't tried to compile it though):

    UInt32 my_template[6] = {0x3D800000, 0x618C0000, 0x800C0000, 0x804C0004,
    0x7C0903A6, 0x4E800420};

    void *CFM2MachO( void *cfmfp )
    {
    UInt32 *mfp = (UInt32*) NewPtr( sizeof(my_template) );
    mfp[0] = my_template[0] | ((UInt32)cfmfp >> 16);
    mfp[1] = my_template[1] | ((UInt32)cfmfp & 0xFFFF);
    mfp[2] = my_template[2];
    mfp[3] = my_template[3];
    mfp[4] = my_template[4];
    mfp[5] = my_template[5];
    MakeDataExecutable( mfp, sizeof(my_template) );
    return( mfp );
    }

    typedef pascal int (*BeepPointer) (void);

    static BeepPointer beepTwice;

    static pascal OSErr loadLibrary()
    {
    OSErr myerr;
    CFragConnectionID connID = kInvalidID;
    FSSpec fsSpec;
    CFragSymbolClass symClass;
    Ptr CFMBeepTwice;

    myerr = FSMakeFSSpec(0, 0, "\pShlb4DOpen", &fsSpec);
    myerr = GetDiskFragment(&fsSpec,
    0,
    kCFragGoesToEOF,
    NULL,
    kLoadCFrag,
    &connID,
    NULL,
    NULL);

    myerr = FindSymbol (connID, "\pBeepTwice",
    (Ptr*) &CFMBeepTwice, &symClass);

    beepTwice = (BeepPointer)CFM2MachO(CFMBeepTwice);
    beepTwice();
    DisposePtr((Ptr)beepTwice);

    return myerr;
    }


    Martin Guest

Similar Threads

  1. CF and Mach-ii ??
    By weblover in forum Coldfusion - Advanced Techniques
    Replies: 1
    Last Post: July 6th, 03:01 AM
  2. Mach II Framework Questions
    By JakeFlynn in forum Coldfusion - Advanced Techniques
    Replies: 10
    Last Post: June 9th, 12:11 AM
  3. Uploading files with mach-ii
    By restlessmedia in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: April 20th, 12:35 PM
  4. Mach II & URLSessionFormat()
    By monochrome13 in forum Macromedia ColdFusion
    Replies: 0
    Last Post: February 28th, 01:50 PM
  5. Shared library / Mach-O: Application crashs if I call a function
    By Hans Stoessel in forum Mac Programming
    Replies: 2
    Last Post: September 22nd, 01:02 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139