If I try a marshal a string that is really a NULL pointer, what will happen?
views:
167answers:
4Well what do you think ? LPstr is A pointer to a null-terminated array of ANSI characters. NULL is obviously not a pointer to a null terminated array. It will probably try to read from NULL, or something. In any case its undefined behavior, it will crash your app or leave it in unknown state. Why do you want that ? why not just check before mashalling it ?
I imagine it will pass NULL to the underlying API, which may or may not be acceptable input, depending on what you're calling. Most decently designed C(++) code checks for that sort of thing, but it's best to double check.
From native to managed, you get a null string object. From managed to native, you get a null pointer. It's fairly intuitive. :-)
A NULL value when typed as a string will be translated to the respective language representation of NULL when marshalled in either direction (NULL for C and null for C#)