Using GetSharedLibrary in a Mach-O application

Ask a Question related to Mac Programming, Design and Development.

  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. Similar Questions and Discussions

    1. CF and Mach-ii ??
      What makes a Big Difference when coding with Plain CF when compared to working with MACH-II applying OO design, it's been more structural you could...
    2. Mach II Framework Questions
      I am considering rewriting my website using the machii framework. First a specific question as of right now my site loads a topbar and a menubar...
    3. mach-ii opinions and experiences??
      Just been evaluating mach-ii. It seems pretty easy and pretty powerful in that you get the whole MVC thing happening, I am pretty happy to start...
    4. Mach II & URLSessionFormat()
      I am working through the MachII sample sites, trying to incorporate #URLSessionFormat()# to pass JSESSIONID to maintain session without cookies. I...
    5. Shared library / Mach-O: Application crashs if I call a function
      Hi, me again Meanwhile, I can load the shared library in my Mach-O Application and I found my function (BeepTwice) in it. But if I try to call...
  3. #2

    Default Re: Using GetSharedLibrary in a Mach-O application

    dans l'article bkevqj$139a5$1@ID-142477.news.uni-berlin.de, Hans Stoessel à
    [email]hstoessel.list@pm-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

  4. #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.vergnaud@wanadoo.fr> schrieb im Newsbeitrag
    news:BB91573C.126BC%eric.vergnaud@wanadoo.fr...
    > dans l'article bkevqj$139a5$1@ID-142477.news.uni-berlin.de, Hans Stoessel
    à
    > [email]hstoessel.list@pm-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

  5. #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

Posting Permissions

  • You may not post new threads
  • You may 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