Professional Web Applications Themes

Shared library / Mach-O: Application crashs if I call a function - Mac Programming

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 this function, the system crashs with the message: "unknown PowerPC" exception, in the debugger there is an invalid opcode. I have a test application (Mach-O bundle) and a shared 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 = ...

  1. #1

    Default 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 this function, the system crashs with the message:
    "unknown PowerPC" exception, in the debugger there is an invalid opcode.

    I have a test application (Mach-O bundle) and a
    shared 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);
    //--------------------
    // No error until here
    //--------------------

    beepTwice(); // Here the application crashs

    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?
    Is it a problem between Mach-O and the shared library?
    Is there another way to call the function?

    Thanks and Regards
    Hans


    Hans Stoessel Guest

  2. #2

    Default 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 this function, the system crashs with the message:
    "unknown PowerPC" exception, in the debugger there is an invalid opcode.

    I have a test application (Mach-O bundle) and a
    shared 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);
    //--------------------
    // No error until here
    //--------------------

    beepTwice(); // Here the application crashs

    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?
    Is it a problem between Mach-O and the shared library?
    Is there another way to call the function?

    Thanks and Regards
    Hans



    Hans Stoessel Guest

  3. #3

    Default Re: Shared library / Mach-O: Application crashs if I call afunction

    > 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);
    > //--------------------
    > // No error until here
    > //--------------------
    >
    > beepTwice(); // Here the application crashs
    >
    > return myerr;
    > }
    >
    You're almost there:

    You should write:

    typedef pascal int (*beepTwiceProcPtr) (void);

    static beepTwiceProcPtr beepTwice;

    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;
    }

    Since 4D Open uses 2 byte alignment, you should also make sure that any
    struct declaration is enclosed by align pragmas.

    Good luck.

    Eric

    Eric VERGNAUD Guest

Similar Threads

  1. Flash MX 2004 Prof - Form application function call question
    By ShellyA webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 2
    Last Post: January 26th, 10:05 PM
  2. Using GetSharedLibrary in a Mach-O application
    By Hans Stoessel in forum Mac Programming
    Replies: 3
    Last Post: September 23rd, 04:18 PM
  3. How can I load a CFM shared library in a Mach-O bundle?
    By Hans Stoessel in forum Mac Programming
    Replies: 0
    Last Post: September 19th, 12:23 PM
  4. Replies: 1
    Last Post: August 18th, 10:51 PM
  5. Shared Library, common function
    By Peteris Krumins in forum UNIX Programming
    Replies: 3
    Last Post: July 5th, 08:05 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