#include #include #include #define ASSERT(x) { if( !(x) ) { printf("%s is NULL at:%s:%d\n", #x, __FILE__, __LINE__); exit(-1); } } void* (* objcsharp_get_class)(const char*) = NULL; void* (* callv)(void*, char*, ...) = NULL; float (* callf)(void*, char*, ...) = NULL; typedef void* (*IMP)(void*,void*,...); void* (* get_sel)(char*) = NULL; IMP (* get_imp)(void*, void*) = NULL; static void Init(); // gcc -o nmtest2.exe test.c && strip nmtest2.exe main() { Init(); void* SC = objcsharp_get_class("NSString"); ASSERT( SC ); void* s = callv(SC, "alloc"); ASSERT( s ); s = callv(s, "initWithCString:", "42.23"); ASSERT( s ); char* cs = (char*) callv(s, "cString"); float f = callf(s, "floatValue"); printf("string('%s')'s float value is: %f\n", cs, f); void* sel = get_sel("floatValue"); ASSERT( sel ); float (*fimp)(void*,void*) = (float (*)(void*,void*)) get_imp(SC, sel); ASSERT( fimp ); printf("direct float value is: %f\n", fimp(s, sel)); return 0; } static void Init() { HMODULE objc = LoadLibrary("objc.dll"); ASSERT( objc ); ASSERT( LoadLibrary("gnustep-base.dll") ); HMODULE objcglue = LoadLibrary("gnustep-objcsharp.dll"); ASSERT( objcglue ); objcsharp_get_class = (void* (*)(const char*)) GetProcAddress(objcglue, "objcsharp_get_class"); ASSERT( objcsharp_get_class ); callv = (void* (*)(void*, char*, ...)) GetProcAddress(objcglue, "objcsharp_msg_send"); callf = (float (*)(void*, char*, ...)) GetProcAddress(objcglue, "objcsharp_msg_send_d"); ASSERT( callv ); ASSERT( callf ); get_sel = (void* (*)(char*)) GetProcAddress(objc, "sel_register_name"); ASSERT( get_sel ); get_imp = (IMP (*)(void*, void*) ) GetProcAddress(objc, "get_imp"); ASSERT( get_sel ); void* apc = objcsharp_get_class("NSAutoreleasePool"); ASSERT( apc ); void* ap = callv(apc, "alloc"); ASSERT( ap ); ap = callv(ap, "init"); ASSERT( ap ); }