Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A blittable type is a type that has a common representation between managed and unmanaged code and can therefore be passed between them with little or no problem, e.g. byte, int32, etc. </p> <p>A non-blittable type does not have the common representation, e.g. System.Array, System.String, System.Boolean, etc. </p> <p>By specifying the MarshalAs attribute for a non-blittable type you can tell the marshaller what it should be converted to. See this <a href="http://msdn.microsoft.com/en-us/library/75dwhxf7%28v=VS.100%29.aspx" rel="nofollow">article on Blittable and Non-Blittable Types</a> for more information</p> <blockquote> <p>1 - What is the best way to pass strings? Some are short (device id's which can be set by us), and some are file paths (which may contain Asian characters)</p> </blockquote> <p>StringBuilder is generally recommended as the easiest to use but I often use plain byte arrays.</p> <blockquote> <p>2 - Should I pass an IntPtr to the C# struct or should I just let the Marshaller take care of it by putting the struct type in the function signature?</p> </blockquote> <p>If the method is expecting a pointer then pass an IntPtr although you can get probably away with a ref in many cases depending on what it's going to be used for. If it's something that needs to stick around in the same place for a long time then I would manually allocate the memory with Marshal and pass the resulting IntPtr.</p> <blockquote> <p>3 - Should I be worried about any non-pointer datatypes like bools or enums (in other, related structs)? We have the treat warnings as errors flag set in C++ so we can't use the Microsoft extension for enums to force a datatype.</p> </blockquote> <p>Once you've got everything set up with the correct marshalling attributes I don't see why you'd need to worry. If in doubt put in the attribute, if the struct only ever gets used by managed code then the attribute won't be used.</p> <blockquote> <p>4 - Is P/Invoke actually the way to go? There was some Microsoft documentation about Implicit P/Invoke that said it was more type-safe and performant. </p> </blockquote> <p>Can't comment on this, you're into Visual C++ territory there.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload