ehh
ehh

Reputation: 3480

RCW does not convert integer when passing from .Net to COM

As per MSDN, regarding the conversion of types done by the RCW between .Net client to unmanaged objects, it is written:

...Other types require no conversion. For instance, a standard wrapper will always pass a 4-byte integer between managed and unmanaged code without converting the type.

AFAIK,

So if an Int32 is passed as parameter from a .Net to a VBA method and no conversion is done by the RCW so how the parameter is passed?

Upvotes: 0

Views: 36

Answers (1)

Simon Mourier
Simon Mourier

Reputation: 138841

What's important is how the conversion is defined between the two worlds (unmanaged vs managed) in the native or managed code side.

If conversion is defined using a COM / Automation Type Library (in DLL or TLB for example), then it will be declared as the corresponding type automatically, especially for very well known types such as the unsigned 16-bit integer type.

So a VBA 16-bit type will be declared as the equivalent (if it's a standard well-known type) .NET 16-byte. For example, VBA integer will be declared as .NET's Int16 (like the short keyword in C#).

If conversion is defined manually, for example using .NET interface with COM annotations, then it's the developer's task to ensure the declaration is consistent for both sides (or problems/bugs/crashes may happen).

I suggest two links in the official doc about this: Default Marshaling Behavior and Blittable and Non-Blittable Types to determine what can be considered as standard or well-known types.

Upvotes: 1

Related Questions