求易语言API(RegEnumKeyExA)的用法。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了求易语言API(RegEnumKeyExA)的用法。相关的知识,希望对你有一定的参考价值。
刚接触API,比如要取HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run 下所有的子键,应该怎么写?
RegEnumKeyVB声明Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long说明枚举指定项的子项。在Win32环境中应使用RegEnumKeyEx返回值Long,零(ERROR_SUCCESS)表示成功。其他任何值都代表一个错误代码参数表参数类型及说明hKeyLong,一个已打开项的句柄,或者指定一个标准项名dwIndexLong,欲获取的子项的索引。第一个子项的索引编号为零lpNameString,用于装载指定索引处项名的一个缓冲区cbNameLong,lpName缓冲区的长度注解用RegQueryInfoKey判断容纳最长那个项所需的缓冲区长度 RegOpenKeyVB声明Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long说明打开一个现有的注册表项返回值Long,零(ERROR_SUCCESS)表示成功。其他任何值都代表一个错误代码参数表参数类型及说明hKeyLong,一个已打开项的句柄,或指定一个标准项名lpSubKeyString,要打开的项名phkResultLong,指定一个变量,用于装载(保存)打开注册表项的一个句柄注解在NT环境下,这个函数会使用默认的安全参数 参考技术A 链接: https://pan.baidu.com/s/1pLAyvIN 密码: jttt去下载链接文件然后解压,创建新易语言程序,加入压缩包里的模块,然后
枚举注册项(,,)查看描述自己填
至于API函数用法:通过API助手或上网查导入API:RegEnumKeyExA和RegOpenKeyA
RegOpenKeyA:参数1.根目录依据以下填
#根类:2147483648 #现行用户:2147483649 #本地机器:2147483650 #所有用户:2147483651 #现行设置:2147483653 (填数字不要填#XXX,不然会变成易语言系统常量)
你的是2147483650
参数2. "Software\Microsoft\Windows\CurrentVersion\Run"
参数3填一个变量,变量用于获取注册项句柄,我这里填 “注册项句柄” 整数型
RegEnumKeyExA:
参数1. 注册项句柄
参数2.项索引(从0开始,填写你需要的)
参数3.创建一个字节集变量,我这里“Ipname” , 然后 Ipname=取空白字节集(255)
参数4. 255
参数5. 0
参数6. 取空白字节集(255)
参数7. 255
参数8. 新建一个变量,类型为 文件时间_ (没有自己定义一个数据类型,通过API助手导入一般会有的),然后直接填变量名称。
用API不要想着简单,因为学习不能总是依靠别人的模块,希望你能看我的代码举一反三而不是完全地照抄,这样真的没多大用处
IOS Runtime的用法
什么是runtime?
1> runtime是一套底层的C语言API(包含很多强大实用的C语言数据类型、C语言函数)
2> 实际上,平时我们编写的OC代码,底层都是基于runtime实现的
* 也就是说,平时我们编写的OC代码,最终都是转成了底层的runtime代码(C语言代码)
runtime有啥用?
1> 能动态产生一个类、一个成员变量、一个方法
2> 能动态修改一个类、一个成员变量、一个方法
3> 能动态删除一个类、一个成员变量、一个方法
常见的函数、头文件
#import <objc/runtime.h> : 成员变量、类、方法
Ivar * class_copyIvarList : 获得某个类内部的所有成员变量
Method * class_copyMethodList : 获得某个类内部的所有方法
Method class_getInstanceMethod : 获得某个实例方法(对象方法,减号-开头)
Method class_getClassMethod : 获得某个类方法(加号+开头)
method_exchangeImplementations : 交换2个方法的具体实现
#import <objc/message.h> : 消息机制
objc_msgSend(....)
#import "HMViewController.h" #import "HMPerson.h" #import <objc/runtime.h> #import <objc/message.h> @interface HMViewController () @property (weak, nonatomic) IBOutlet UIImageView *iconView1; @property (weak, nonatomic) IBOutlet UIImageView *iconView2; @property (nonatomic, strong) NSMutableArray *names; @property (nonatomic, strong) NSArray *books; @end @implementation HMViewController - (NSMutableArray *)names { if (_names == nil) { self.names = [NSMutableArray array]; } return _names; } - (void)viewDidLoad { [super viewDidLoad]; // NSDictionary *info = @{@"name" : @"jack", @"age" : @10}; // // NSString *key = nil; // // NSLog(@"%@", info[key]); NSMutableDictionary *info = [NSMutableDictionary dictionary]; info[@"name"] = nil; // self.books = @[@"kiuhua", @"xxx"]; // // NSLog(@"%@", self.books[4]); // [self addName:@"jack"]; // [self addName:@"rose"]; // [self addName:@"jim"]; // // NSLog(@"%@", self.names[4]); // NSLog(@"%@", [self.names objectAtIndex:4]); } - (void)addName:(NSString *)name { [self.names addObject:name]; } - (void)imageSwizzle { // 什么是iOS Swizzle?利用运行时函数交换2个方法的实现 // BOOL iOS7 = [[UIDevice currentDevice].systemVersion floatValue] >= 7.0; // if (iOS7) { // self.iconView1.image = [UIImage imageNamed:@"face_os7"]; // self.iconView2.image = [UIImage imageNamed:@"vip_os7"]; // } else { // self.iconView1.image = [UIImage imageNamed:@"face"]; // self.iconView2.image = [UIImage imageNamed:@"vip"]; // } self.iconView1.image = [UIImage imageNamed:@"face"]; self.iconView2.image = [UIImage imageNamed:@"vip"]; } - (void)testRuntimeIvar { // Ivar : 成员变量 unsigned int count = 0; // 获得所有的成员变量 Ivar *ivars = class_copyIvarList([HMPerson class], &count); for (int i = 0; i<count; i++) { // 取得i位置的成员变量 Ivar ivar = ivars[i]; const char *name = ivar_getName(ivar); const char *type = ivar_getTypeEncoding(ivar); NSLog(@"%d %s %s", i, name, type); } // HMPerson *p = [[HMPerson alloc] init]; // objc_msgSend(p, @selector(setAge:), 20); // NSLog(@"%d", p.age); }
HMPerson.h /.m(获取所有成员变量)
#import <Foundation/Foundation.h> @interface HMPerson : NSObject <NSCoding> @property (nonatomic, assign) int age; @property (nonatomic, copy) NSString *name; @property (nonatomic, assign) double height; - (void)run; @end
#import "HMPerson.h" #import <objc/runtime.h> @implementation HMPerson - (void)run { NSLog(@"run----"); } - (void)encodeWithCoder:(NSCoder *)encoder { unsigned int count = 0; Ivar *ivars = class_copyIvarList([HMPerson class], &count); for (int i = 0; i<count; i++) { // 取得i位置的成员变量 Ivar ivar = ivars[i]; const char *name = ivar_getName(ivar); NSString *key = [NSString stringWithUTF8String:name]; [encoder encodeObject:[self valueForKeyPath:key] forKey:key]; } } @end
UIImage+Extension(交换2个方法的实现)
#import <objc/runtime.h> @implementation UIImage (Extension) /** * 只要分类被装载到内存中,就会调用1次 */ + (void)load { Method otherMehtod = class_getClassMethod(self, @selector(imageWithName:)); Method originMehtod = class_getClassMethod(self, @selector(imageNamed:)); // 交换2个方法的实现 method_exchangeImplementations(otherMehtod, originMehtod); } + (UIImage *)imageWithName:(NSString *)name { BOOL iOS7 = [[UIDevice currentDevice].systemVersion floatValue] >= 7.0; UIImage *image = nil; if (iOS7) { NSString *newName = [name stringByAppendingString:@"_os7"]; image = [UIImage imageWithName:newName]; } if (image == nil) { image = [UIImage imageWithName:name]; } return image; } @end
NSObject+Extension(交换2个方法的实现)
#import <objc/runtime.h> @implementation NSObject(Extension) + (void)swizzleClassMethod:(Class)class originSelector:(SEL)originSelector otherSelector:(SEL)otherSelector { Method otherMehtod = class_getClassMethod(class, otherSelector); Method originMehtod = class_getClassMethod(class, originSelector); // 交换2个方法的实现 method_exchangeImplementations(otherMehtod, originMehtod); } + (void)swizzleInstanceMethod:(Class)class originSelector:(SEL)originSelector otherSelector:(SEL)otherSelector { Method otherMehtod = class_getInstanceMethod(class, otherSelector); Method originMehtod = class_getInstanceMethod(class, originSelector); // 交换2个方法的实现 method_exchangeImplementations(otherMehtod, originMehtod); } @end @implementation NSArray(Extension) + (void)load { [self swizzleInstanceMethod:NSClassFromString(@"__NSArrayI") originSelector:@selector(objectAtIndex:) otherSelector:@selector(hm_objectAtIndex:)]; } - (id)hm_objectAtIndex:(NSUInteger)index { if (index < self.count) { return [self hm_objectAtIndex:index]; } else { return nil; } } @end @implementation NSMutableArray(Extension) + (void)load { [self swizzleInstanceMethod:NSClassFromString(@"__NSArrayM") originSelector:@selector(addObject:) otherSelector:@selector(hm_addObject:)]; [self swizzleInstanceMethod:NSClassFromString(@"__NSArrayM") originSelector:@selector(objectAtIndex:) otherSelector:@selector(hm_objectAtIndex:)]; } - (void)hm_addObject:(id)object { if (object != nil) { [self hm_addObject:object]; } } - (id)hm_objectAtIndex:(NSUInteger)index { if (index < self.count) { return [self hm_objectAtIndex:index]; } else { return nil; } } @end
以上是关于求易语言API(RegEnumKeyExA)的用法。的主要内容,如果未能解决你的问题,请参考以下文章