As per this StackOverflow answer, you can pass your Objective-C object to a C method. Although that answer specifically deals with passing an instance of the class and calling an instance method instead of a static one, give this a try as in my head, it should work unless I've missed something glaringly obvious.
I know you've said this isn't ideal, as your library will call the C function, but maybe there's another way to pass this?
Define the C method with an id parameter like this:
void cFunction(id param)
Then call it (something) this:
Class thisClass = [self getClass];
cFunction(self);
Modify your above code as per this
//Objective-C class
@interface ActionNotifier : NSObject
+(void)printMessage;
@end
@implementation ActionNotifier
+(void)printMessage {
NSLog(@"Received message from C code");
}
@end
//C class:
#import "ActionNotifier.h"
#import <Cocoa/Cocoa.h>
void cFunction(id param)
{
[param printSecurityMessage];
}
If that wouldn't be acceptable
You could leverage NSNotificationCenter
in Core Foundation as per This StackOverflow post, although if you need [ActionNotifier printMessage]
to be static, you'll need to do the [NSNotificationCenter addObserver]
wire-up somewhere else.
//NSNotificationCenter Wire-up
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(method), @"MyNotification", nil];
-(id)method{
[ActionNotifier printMessage];
}
//Objective-C class
@interface ActionNotifier : NSObject
+(void)printMessage;
@end
@implementation ActionNotifier
+(void)printMessage {
NSLog(@"Received message from C code");
}
@end
//C source: //may need to rename to .mm if you cannot see the core foundation
#include <CoreFoundation/CoreFoundation.h>
void cFunction()
{
CFNotificationCenterRef center = CFNotificationCenterGetLocalCenter();
CFNotificationCenterPostNotification(center, CFSTR("MyNotification"), NULL, NULL, TRUE);
}