PCallNative() already works fine, it's only CCallNatve() that is not implemented yet. But in your sample, this function returns INT (the type specified in the generic argument), this cannot be cast to an object as in VO. You will need to use a different approach in .Net, can you please show us the complete relevant code and also mention which OLE item you are using?
Kromi wrote: Casting an int to an object should not be a problem, I guess.
Check this code. First assignment compiles, the second not. Aren't they equivalent?
LOCAL i := 67 AS INT
LOCAL o1 AS OBJECT
LOCAL o2 AS OBJECT
o1 := (OBJECT)i
o2 := OBJECT(_CAST, i)
In this specific code sample, it would had been safe to do such a cast, but this is code written specifically for .Net (X# or vulcan), it's not code that would compile in VO. When there is such a cast in VO, it is almost always used to convert an int, holding a pointer to an object to a var holding a reference to that object itself (like in your original code with the OLE object). This did work in VO (Win32 apps in general), but it is completely not allowed in .Net, it will never work like that.
For this reason, we intentionally disallowed that specific syntax (OBJECT(_CAST, i)) in order to trap such problems at compile time and not at runtime later. If that was code that was compiling without errors in Vulcan, then this was a problem, because if this code was executed, you would get a runtime exception. In X#, you get a warning (error actually) about this at compile time, so you discover it first, before the customer!
In VO the OBJECT(_CAST) syntax tells the compiler that the memory location 67 is a reference to an object.
Apart from the fact that (in AnyCPU) a memory address does not always fit in an int, this is obviously wrong.
The syntax (OBJECT) i or OBJECT(i) tells the compiler to store the int value in an object.
In general you should look carefully at all _CAST keywords in your code.
_CAST tells the compiler that you know what you are doing. And quite often this has been used by people that did not know what they were doing....
XSharp Development Team
If you really need to use an integer to represent an object then there is another trick in .Net.
You can use the GCHandle class to lock an object in memory and get its handle.
var gch := GCHandle.Alloc(oMyObject)
You can then call GCHandle.ToIntPtr(gch) to convert the handle to an IntPtr (4 bytes or 8 bytes for x86 or x64).
On the receiving side you can then use this IntPtr to get the GcHandle back and then access the object
var gch := GCHandle.FromIntPtr(param)
var omyObject := (MyObject)gch.Target