I am producing a .NET assembly using .NET AssemblyBuilder and the ILGenerator; the assembly will interface to a C++ COM Interop layer and the interface definition of the assembly is driven from the COM direction. The method names and parameters are described by COM: the types are defined using a VARIANT type – such as VT_BYREF|VT_I4 and the parameter directions are defined using the IDLFLAG enumeration.
This all works as I evaluate the variant type and set Type[] values for TypeBuilder.DefineMethod() appropriately, as well as the ParameterAttributes using the IDLFLAG.
So a COM method: HRESULT MoveX(long pos), will translate to:
Type[] parameters = new Type[1];
Parameters[0] = typeof(int32);
TypeBuilder.DefineMethod(“MoveX”, MethodAttributes.Public, typeof(Int32), parameters);
And I can generate the assembly and even make the call correctly (which calls back into the COM interop layer).
BUT – the problem is when I want to return a value, such as the COM method:
HRESULT GetX(long* pos), I cannot seem to define the parameter type 'int*' correctly for the DefineMethod() so that the assembly shows the parameter as a ref parameter!
I want the assembly to show:
Void GetX(ref int32 pos);
But I have tried to set the Type as typeof(int*) – using unsafe – but this results in ‘int32*’ and NOT ‘ref int32’ – also this then cannot be accessed via VB.NET (a goal). I’ve tried ‘typeof(&int)’ but this is not valid code… I’ve tried using ‘typeof(object)’ – by this results in ‘object’ not ‘ref object’…. I’ve even tried:
Object ob = new Object();
Object pob = ob;
Typeof(pob); - but even this does not result in ‘ref object’ !!!!!!!!!!!!
How do I define the C# Type so that the generated assembly will display the parameter type as ‘ref’ ???????????
Help Please, if you can…