Ask a Question related to Mac Programming, Design and Development.
-
Hans Stoessel #1
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
-
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. ... -
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... -
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... -
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.... -
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:... -
Hans Stoessel #2
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
-
Eric VERGNAUD #3
Re: Shared library / Mach-O: Application crashs if I call afunction
> Here is the code I use:
You're almost there:>
> //--------------------------------------------------------------------------
> // 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 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



Reply With Quote

