Question
i'm developing a COM object that should work in C# and also in VBScript. Also it must support 32 and 64 bits.
The problem I have is with pointers. See part of my .IDL
HRESULT Copy([in] PTRTYPE destAddr, [in] PTRTYPE srcAddr, [in] int bytes);
If I declare PTRTYPE as void*, c# sees them as an IntPtr and VB6/VBScript sees them "As Any"
The problem with this approach is that I cannot do simpler pointer math with "Any" type parameters.
If I declare PTRTYPE as long (and "hyper" in 64 bits), now I can do pointer math but in C# I have two different definitions for the same method depending 32/64 bit platform.
I wish to avoid using VARIANT as PTRTYPE type.
Is there any way to make it compatible with both C# and VBScript?
Thanks in advance, Mauro.
Solution 2
The solution I adopted was the following:
1) Copy .idl to another folder
2) Replace the __int3264 with void* in the variables you want to be IntPtr
3) Build the .tlb file from the .idl one
4) Build a primary interop based on the .tlb file.
Voilá!
Regards, Mauro.
OTHER TIPS
I would recommend not forcing the consumer of your type to do the pointer math.
If declare this as void, you can always allow the offsets to be passed as a parameter, instead of forcing the consumer to do the manipulation. This could look a bit more like this Array.Copy overload in the .NET framework, where the source + destination have an offset passed as a simple integer.
By doing this, you allow the method to work correctly no matter what consumer you choose, as well as providing you a means of doing the validation (ie: making sure the offset is legitimate) in your own code instead of relying on the consumer.