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

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

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

    1. Flash MX 2004 Prof - Form application function call question
      I have a flashmx 2004 professional application using forms. I am able to call methods on my application form from child forms with no problem. ...
    2. 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...
    3. How can I load a CFM shared library in a Mach-O bundle?
      Hi In my application (Mach-O bundle package) I should load a Shared library. How can I do that? Is it possible? Have I to use...
    4. Calling a Managed C++ library which uses a load library function from a WS
      Good Day! Im trying to call a managed c++ library from a web service using c# but when i go trough the code the was'nt able to load the library....
    5. Shared Library, common function
      Hello, I have created a shared library, so any tool within project shared most commonly used functions. One of the functions looks like this:...
  3. #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

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

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