我在头文件中定义了一个结构:
#import <UIKit/UIKit.h>
typedef struct ORIGINAL_QUOTA_DATA_tag
{
byte exch;
byte complex_stat;
char contract[8];
byte status;
byte type;
}ORIGINAL_QUOTA_DATA;
@interface NetTestAppDelegate : NSObject <UIApplicationDelegate> {
CFSocketRef _socket;
CFDataRef address;
ORIGINAL_QUOTA_DATA oQuota;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
在我的.m文件中:
static void TCPServerConnectCallBack(CFSocketRef socket, CFSocketCallBackType type, CFDataRef address, const void *data, void *info){
memset(&oQuota, 0, sizeof(oQuota));
}
但它得到了考虑:
答案 0 :(得分:1)
您正在引用C函数中的oQuota
(它也是静态的,但这不是问题)。您的oQuota
变量仅适用于NetTestAppDelegate
的Objective-C方法实现中的“范围内”:
void myCFunction()
{
// oQuota cannot be referenced here.
}
@implementation NetTestAppDelegate
- (void)myObjectiveCMethod
{
// oQuota is in scope, can reference it.
}
@end
但可以做的是将对象传递给你的回调:
static void TCPServerConnectCallBack(CFSocketRef socket, CFSocketCallBackType type, CFDataRef address, const void *data, void *info){
memset(
&((NetTestAppDelegate *)info)->oQuota,
0,
sizeof(((NetTestAppDelegate *)info)->oQuota)
);
// Not sure whether the sizeof works, try it.
}
在CFSocketContext
中,您需要设置:
myCFSocketContext.info = self;