[Mono-devel-list] cocoa#
meddochat (Matthijs ter Woord)
meddochat at zonnet.nl
Sat Jun 19 13:13:52 EDT 2004
In monocvs there is a module named cocoasharp (or somethign like that).
does somebody has taken a look at it?
meddochat
----- Original Message -----
From: Patrick Beard
To: mono-devel-list at lists.ximian.com
Sent: Saturday, June 19, 2004 19:12
Subject: Re: [Mono-devel-list] cocoa#
I know of no official Cocoa# effort. However, here's a little sample code I've written that might get things started. I'm still learning C# myself, so I don't know if there is a more direct way to get a library loaded, so this causes the Cocoa umbrella framework to be loaded by calling into NSRealMemoryAvailable().
- Patrick
using System;
using System.Reflection;
using System.Runtime.InteropServices; // for DllImport.
public class CocoaTest {
const string libobjc = "libobjc.dylib";
[DllImport(libobjc, EntryPoint="objc_getClass", CharSet=CharSet.Ansi)]
public static extern int objc_getClass(string name);
[DllImport(libobjc, EntryPoint="sel_registerName", CharSet=CharSet.Ansi)]
public static extern int sel_registerName(string name);
[DllImport(libobjc, EntryPoint="objc_msgSend")]
public static extern int objc_msgSend(int self, int cmd);
[DllImport(libobjc, EntryPoint="objc_msgSend", CharSet=CharSet.Ansi)]
public static extern int objc_msgSend(int self, int cmd, string arg);
static int selector(string name) {
return sel_registerName(name);
}
const string Cocoa = "/System/Library/Frameworks/Cocoa.framework/Cocoa";
[DllImport(Cocoa, EntryPoint="NSRealMemoryAvailable")]
public static extern uint NSRealMemoryAvailable();
[DllImport(Cocoa, EntryPoint="NSLog")]
public static extern void NSLog(int message);
public static void Main(string[] args) {
// Call into Cocoa to get it loaded.
uint realMemoryAvailable = NSRealMemoryAvailable();
Console.WriteLine("realMemoryAvailable = " + realMemoryAvailable);
// Push an autorelease pool.
int NSAutoreleasePool = objc_getClass("NSAutoreleasePool");
int pool = objc_msgSend(NSAutoreleasePool, selector("new"));
// allocate an NSString.
int NSString = objc_getClass("NSString");
int message = objc_msgSend(NSString, selector("stringWithCString:"), "Hello from Cocoa!");
NSLog(message);
objc_msgSend(pool, selector("release"));
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20040619/e840c928/attachment.html
More information about the Mono-devel-list
mailing list