<p>Given the following C function in a DLL:</p>

<pre><code>char * GetDir(char* path );
</code></pre>

<p>How would you P/Invoke this function into C# and marshal the char * properly.
.NET seems to know how to do LPCTSTR but when I can't figure out any marshaling that doesn't cause a NotSupportedException to fire when calling this function.</p>

Try
```
```
[DllImport("your.dll", CharSet = CharSet.Ansi)]
string GetDir(StringBuilder path);
```
```
string is automatically marshalled to a zero-terminated string, and with the CharSet property, you tell the Marshaller that it should use ANSI rather than Unicode.
Note: Use string (or System.String) for a const char*, but StringBuilder for a char*.
You can also try MarshalAs, as in
this example
.