`
cxsjabc
  • 浏览: 19819 次
  • 性别: Icon_minigender_1
  • 来自: 合肥
最近访客 更多访客>>
社区版块
存档分类
最新评论

iphone-common-codes-ccteam源代码 CCDylib.m

阅读更多
//  
//  CCDylib.m  
//  CCFC  
//  
//  Created by xichen on 11-12-23.  
//  Copyright 2011 ccteam. All rights reserved.  
//  
  
#import "CCDylib.h"  
#import "CCNSString.h"  
#import "CCCommon.h"  
#import <dlfcn.h>  
  
@implementation CCDylib  
  
+ (void *)open:(NSString *)dylibFileFullPath  
{  
    return dlopen([dylibFileFullPath UTF8String], RTLD_LAZY);  
}  
  
+ (void *)openSystemDylib:(NSString *)dylibFileName  
{  
    NSString *path = [dylibFileName systemLibraryPath];  
    return [self open:path];  
}  
  
+ (void *)openMobileSubstrateDylib:(NSString *)dylibFileName  
{  
    NSString *path = [NSString stringWithFormat:  
            @"%@%@", MOBILE_SUBSTRATE_PATH, dylibFileName];  
    return [self open:path];  
}  
  
  
+ (int)close:(void *)dylibPtr  
{  
    return dlclose(dylibPtr);  
}  
  
  
- (id)initWithFileFullPath:(NSString *)fileFullPath  
{  
    COMMON_INIT_BEGIN  
      
    _handle = [CCDylib open:fileFullPath];  
    EQUAL_NULL_RETURN_NIL(_handle)  
      
    COMMON_INIT_END  
}  
  
- (id)initWithSystemDylib:(NSString *)dylibFileName  
{  
    COMMON_INIT_BEGIN  
      
    _handle = [CCDylib openSystemDylib:dylibFileName];  
    EQUAL_NULL_RETURN_NIL(_handle)  
      
    COMMON_INIT_END  
}  
  
- (id)initWithMobileSubstrateDylib:(NSString *)dylibFileName  
{  
    COMMON_INIT_BEGIN  
      
    _handle = [CCDylib openMobileSubstrateDylib:dylibFileName];  
    EQUAL_NULL_RETURN_NIL(_handle)  
      
    COMMON_INIT_END  
}  
  
- (void)dealloc  
{  
    [super dealloc];  
}  
  
  
- (intVoidFunc)getIntVoidFunc:(NSString *)funcName  
{  
    return (intVoidFunc)dlsym(_handle, [funcName UTF8String]);  
}  
  
- (voidVoidFunc)getVoidVoidFunc:(NSString *)funcName  
{  
    return (voidVoidFunc)dlsym(_handle, [funcName UTF8String]);  
}  
  
- (charStarVoidFunc)getCharStarVoidFunc:(NSString *)funcName  
{  
    return (charStarVoidFunc)dlsym(_handle, [funcName UTF8String]);  
}  
  
- (nSStringVoidFunc)getNSStringVoidFunc:(NSString *)funcName  
{  
    return (nSStringVoidFunc)dlsym(_handle, [funcName UTF8String]);  
}  
  
  
- (NSString *)getError  
{  
    return [NSString stringWithUTF8String:dlerror()];  
}  
  
  
- (int)close  
{  
    return dlclose(_handle);  
}  
  
  
@end  

googlecode链接地址(会有更新):http://code.google.com/p/iphone-common-codes-ccteam/source/browse/trunk/CCFC/files/CCDylib.m
0
3
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics