Dynamic loading of System Frameworks???
Dynamic loading of System Frameworks???
- Subject: Dynamic loading of System Frameworks???
- From: "Huyler, Christopher M" <email@hidden>
- Date: Fri, 27 Jun 2003 14:51:43 -0400
- Thread-topic: Dynamic loading of System Frameworks???
Ok, thanks for everyone's help with my Gestalt issues. I finally tracked the problem down to the loader. Although the symbols for all the functions were defined, the libraries in the CoreServices framework had not fully been initialized. This was because I was calling Gestalt inside a constructor.
Anyway, rather than let the loader decide when to initialize the libraries, I decided to load it myself. (See test program below) However I have one problem. I have to specifiy the full path of the library. Does anyone know if this will be a problem as Apple upgrades their libraries? Could the library be located in a different place on a different computer? Is there a better way to do this? I'm open to suggestions.
/* load.c */
#include <stdio.h>
#include <mach-o/dyld.h>
typedef short (*gestalt_t)(
unsigned long,
long *
);
enum {
SystemVersion = 'sysv' /* system version*/
};
int main()
{
NSSymbol symbol;
const struct mach_header *header;
long version;
gestalt_t func;
char image[256] = "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/CarbonCore";
unsigned long image_options = NSADDIMAGE_OPTION_WITH_SEARCHING;
char name[16] = "_Gestalt";
unsigned long symbol_options = NSLOOKUPSYMBOLINIMAGE_OPTION_BIND|NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR;
header = NSAddImage(image,image_options);
symbol = NSLookupSymbolInImage(header,name,symbol_options);
func = NSAddressOfSymbol(symbol);
if (func(SystemVersion,&version) == 0)
{
printf("OS X %x.%x.%x\n",(version&0xff00)>>8,(version&0x00f0)>>4,(version&0xf));
}
}
Christopher Huyler
Computer Associates
Programmer
tel: +1 508 628 8232
fax: +1 508 628 8704
<
mailto:email@hidden>
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.