From: Arne Vajhøj on 29 Apr 2010 22:00 On 29-04-2010 17:22, Tony Johansson wrote: > Here I have some code from an example from MSDN. > What I don't fully understand here is how is it possible to pass an object > of type StringBuilder and receive this parameter in the > windows API as an LPTSTR ? > > Documentation for Win32 GetShortPathName() API Function > // DWORD GetShortPathName( > // LPCTSTR lpszLongPath, // file for which to get short path > // LPTSTR lpszShortPath, // short path name (output) > // DWORD cchBuffer // size of output buffer > // ); > > [DllImport("Kernel32", CharSet = CharSet.Auto)] > static extern Int32 GetShortPathName( > String path, // input string > StringBuilder shortPath, // output string > Int32 shortPathLength); // StringBuilder.Capacity The function returns a "string". System.String is immutable. System.Text.StringBuilder seems as a good choice for returning a "string" in. Do you have any better suggestions? Technically the glue that .NET uses knows how to handle a StringBuilder. Arne
|
Pages: 1 Prev: DllImport property Preservesig Next: What to name an object? |