Calling Mono function with reference param from Obj C

Discussion in 'Mac Programming' started by satyam90, Oct 9, 2008.

  1. satyam90 macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #1
    I am using Obj C with Cocoa framework.
    I have a Mono (C# on linux) class with a function
    Code:
    void CheckForUpdate(string ID,out int version);
    
    I made changes to call other mono functions from Obj C successfully.
    But the above said mono function is expecting a reference while calling it.
    How can I call it from my ObjC code?
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    if this is for real-life use, and not an academic exercise, I would recommend writing a C# function like this:
    Code:
    int wrapCheckForUpdate(string ID, int version) {
      CheckForUpdate(ID,out version);
      return version;
    }
    
    Then in your C/Objective-C code, using the embedded mono libraries (which it sounds like you already know how to do), call wrapCheckForUpdate passing ID and version by value, and grab its result.

    If the value of version that you pass in is unimportant, and its value after the call is all that matters, you can just do something like:
    Code:
    int wrapCheckForUpdate(string ID) {
      int version;
      CheckForUpdate(ID, out version);
      return version;
    }
    
    It seems strange not to just return the version and set a reference parameter if the value passed in is not needed, but *shrug* it makes your wrapper and invocation simpler if that's the case.

    If you DO want to do this "purely"... well, I don't have time to review the Embedded Mono docs. There's probably a way, but I haven't needed it to this point.

    -Lee
     

Share This Page