c# - Why does Code Analysis in VS2013 RC lead me into a box canyon? -
i ran code analysis on utility i'm maintaining, , advised me change this:
private static extern int readmenu1file(string menu1path);
...to this:
private static extern int readmenu1file(unmanagedtype.lpwstr menu1path);
...with verbiage: "specify marshaling p/invoke string arguments reduce security risk, marshal parameter 'menu1path' unicode, setting dllimport.charset charset.unicode, or explicitly marshaling parameter unmanagedtype.lpwstr. if need marshal string ansi or system-dependent, specify marshalas explicitly, , set bestfitmapping=false; added security, set throwonunmappablechar=true."
...but when did, says, "the type name 'lpwstr' not exist in type 'system.runtime.interopservices.unmanagedtype'" , "'system.runtime.interopservices.unmanagedtype.lpwstr' 'field' used 'type'"
code completion not helping (no suggestions after typing "unmanagedtype.") nor there context menu option add missing using.
i suspect you've misinterpreted advice. suspect suggesting:
private static extern int readmenu1file([marshalas(unmanagedtype.lpwstr)] string menu1path);
edit: fits in advice:
or explicitly marshaling parameter
unmanagedtype.lpwstr
that's not same saying "change parameter type unmanagedtype.lpwstr
" - it's telling that's how ought marshal parameter.
the other recommendations set on [dllimport]
instead.
Comments
Post a Comment