1

I'm trying to call into a MonoTouch assembly from an existing Objective C project. I found this article:

http://www.guidebee.biz/forum/redirect.php?fid=16&tid=176&goto=nextoldset

In there it pretty much describes the steps very well however when I try to build the project in XCode I get the following error:

error: There is no SDK with specified name or path '/Developer/MonoTouch/SDKs/MonoTouch.iphonesimulator.sdk'

So, to be clear:

  1. I have the correct path added the Architectures Additional SDKs
  2. Physically checked the path is correct
  3. I am building against the latest SDK (that I have anyway) which is iOS 4.2

I am stumped. Is this a problem with XCode not finding the correct path to the SDK or something deeper? Worryingly I noticed that the URL referenced in the article ( http://monotouch.net/Documentation/XCode ) is now missing - so has Novell MonoTouch deliberately removed this for some reason?

Update:

Well I'm completely stumped - I cannot cal from Mono into Obj-C code using Selectors either. So as a last ditch attempt I'm posting the code:

@implementation MonoWrapper
- (id)init {
    self = [super init];
    
    if (self) {
        NSBundle *main = [NSBundle mainBundle];
        NSString *path = [main bundlePath];
        const char *c_path = [path UTF8String];
        
        [main autorelease]; 
        [path autorelease];
        
        chdir (c_path);
        setenv ("MONO_PATH", c_path, 1);
        setenv ("MONO_XMLSERIALIZER_THS", "no", 1);
        setenv ("DYLD_BIND_AT_LAUNCH", "1", 1);
        setenv ("MONO_REFLECTION_SERIALIZER", "yes", 1);

        _domain = mono_jit_init_version ("MonoTouch", "v2.0.50727");
        MonoAssembly *assembly = mono_assembly_open("PhoneGap.dll", NULL);
        MonoImage *image = mono_assembly_get_image(assembly);
        MonoClass *class = mono_class_from_name(image, "PhoneGap", "PhoneGap");
        MonoMethodDesc *methodDesc = mono_method_desc_new("PhoneGap.PhoneGap:getInt", TRUE);
        _callbackMethod = mono_method_desc_search_in_class(methodDesc, class);
        
        /* allocate memory for the object */
        _instance = mono_object_new (_domain, class);
        /* execute the default argument-less constructor */
        mono_runtime_object_init (_instance);   
        
    }
    // Done
    return self;
}

- (void)DoSomething {
    int jim = 0;
} 

- (int)multiplyA:(int)a {
    void *params[] = { self, @selector(DoSomething), &a };
    MonoObject *result = mono_runtime_invoke(_callbackMethod, _instance, params, NULL);
    int n = *(int*)mono_object_unbox (result);
    return n;
}
@end

And in Mono:

using System;
using MonoTouch.ObjCRuntime;  

namespace PhoneGap
{
    public class PhoneGap
    {
        public PhoneGap ()
        {
        }

        public int getInt(IntPtr instance, IntPtr sel, int val) {
            
            
            Messaging.void_objc_msgSend (instance, sel);
            return val * 2;
        }
    }
}

Can anyone tell me how to get the Target instance handle in Mono and how to get the Selector?

Community
  • 1
  • 1
James
  • 41
  • 3

1 Answers1

1

MonoTouch historically included support before we had our own debugger. We have since deprecated this support as we now have a fully fledged debugger. What you are trying to do, while technically possible is not a supported workflow. If you wish to continue down this path, I suggest using the "-keeptemp" flag to MonoTouch combined with "-v -v -v" which will not delete the temporary files we generate when compiling the project.

Using this information you can extract the main.m template, and could theoretically figure out how to invoke arm-darwin-mono to cross compile yourself.

Geoff Norton
  • 5,056
  • 1
  • 19
  • 17
  • I am writing a PhoneGap based application and this uses the Objective-C implementation that is PhoneGap to launch the application. I can't rewrite all of PhoneGap but I would like to leverage MonoTouch so long as it's possible to talk across both worlds. I had thought of creating a MonoTouch project and then using PhoneGap as a library but this would still require a bridge between the two and PhoneGap expects to be the hosting application - so difficult choices either way. – James Mar 30 '11 at 08:22
  • Hi Geoff - I've managed to get everything running to the point of being able to load an assembly from Obj-C and call into a function. However I cannot get the Assembly to P/Invoke a C function in my code. I noticed this guy had the same problem: http://stackoverflow.com/questions/5085528/monotouch-pinvoke-system-entrypointnotfoundexception - did this ever get filed as a bug and if so was it fixed? – James Mar 30 '11 at 12:45
  • Geoff - do you have a response to this? I would really appreciate your help here. I want to: 1. Load a MT dll in Objc-C. 2. Call into the MT DLL from Obj-C. 3. Callback into Obj-C from the MT DLL. I can 1 and 2 but it just not possible to do 3 and I don't really understand why. If I load a MT project and link to a static Obj-C library then I can call into Obj-C but this is the wrong way around for the project. Please can you send me an example that does 1, 2 and 3 within the same code or at least tell me it's not possible Additionally - do you provide paid for support? – James Apr 01 '11 at 09:09
  • James, I presume you are the James that e-mailed me. I indicated what you did wrong by email in your specific case. – Geoff Norton Apr 01 '11 at 15:46