Click here to Skip to main content
16,004,890 members
Home / Discussions / C#
   

C#

 
QuestionHow to get Windows Directory with C# Pin
Mmithat24-Mar-03 8:28
Mmithat24-Mar-03 8:28 
AnswerRe: How to get Windows Directory with C# Pin
leppie24-Mar-03 8:35
leppie24-Mar-03 8:35 
GeneralRe: How to get Windows Directory with C# Pin
Mmithat24-Mar-03 9:29
Mmithat24-Mar-03 9:29 
GeneralRe: How to get Windows Directory with C# Pin
leppie24-Mar-03 9:54
leppie24-Mar-03 9:54 
GeneralRe: How to get Windows Directory with C# Pin
Mmithat24-Mar-03 10:03
Mmithat24-Mar-03 10:03 
GeneralRe: How to get Windows Directory with C# Pin
leppie24-Mar-03 9:57
leppie24-Mar-03 9:57 
GeneralRe: How to get Windows Directory with C# Pin
Mmithat24-Mar-03 10:03
Mmithat24-Mar-03 10:03 
AnswerRe: How to get Windows Directory with C# Pin
James T. Johnson24-Mar-03 13:09
James T. Johnson24-Mar-03 13:09 
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
private static extern uint GetWindowsDirectory(
    [MarshalAs(UnmanagedType.LPTStr)]
    System.Text.StringBuilder lpBuffer, // buffer for Windows directory
    uint uSize // size of directory buffer
); 
 
// 255 == buffer size
System.Text.StringBuilder buffer = new System.Text.StringBuilder(255); 
GetWindowsDirectory( buffer, (uint) buffer.MaxCapacity );
Works here.

I think as a general rule, when you need to pass in a buffer to receive text you use a StringBuilder object.

[edit]Looking at MSDN for the GetWindowsDirectory function it is supposed to accept a TCHAR, so the MarshalAs and DllImport attributes should be changed accordingly as above.[/edit]

James

"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation

GeneralRe: How to get Windows Directory with C# Pin
Member 13901624-Mar-03 23:48
Member 13901624-Mar-03 23:48 
GeneralRe: How to get Windows Directory with C# Pin
Stephane Rodriguez.25-Mar-03 0:28
Stephane Rodriguez.25-Mar-03 0:28 
Generalwinamp Pin
Vlad Beu24-Mar-03 7:37
Vlad Beu24-Mar-03 7:37 
QuestionIs an array of ref's or out's possible? Pin
Marc Clifton24-Mar-03 7:15
mvaMarc Clifton24-Mar-03 7:15 
AnswerRe: Is an array of ref's or out's possible? Pin
leppie24-Mar-03 8:27
leppie24-Mar-03 8:27 
GeneralRe: Is an array of ref's or out's possible? Pin
Marc Clifton24-Mar-03 9:59
mvaMarc Clifton24-Mar-03 9:59 
GeneralEmbed Seperate "Document" Icon Pin
Scott Lee24-Mar-03 6:51
Scott Lee24-Mar-03 6:51 
Generalbgcolor of the box within the checkbox Pin
hogehoge24-Mar-03 5:16
hogehoge24-Mar-03 5:16 
GeneralExternal exes Pin
Marix24-Mar-03 5:09
Marix24-Mar-03 5:09 
GeneralRe: External exes Pin
leppie24-Mar-03 8:30
leppie24-Mar-03 8:30 
QuestionDataBinding????????? Pin
Marix24-Mar-03 5:04
Marix24-Mar-03 5:04 
AnswerRe: DataBinding????????? Pin
A.Wegierski24-Mar-03 20:54
A.Wegierski24-Mar-03 20:54 
AnswerRe: DataBinding????????? Pin
Marix25-Mar-03 1:14
Marix25-Mar-03 1:14 
GeneralC# COM+ Pin
John Karbin24-Mar-03 4:52
John Karbin24-Mar-03 4:52 
GeneralRe: C# COM+ Pin
Anonymous24-Mar-03 11:21
Anonymous24-Mar-03 11:21 
QuestionOnwer drawn caption bar? Pin
Zinii23-Mar-03 21:42
sussZinii23-Mar-03 21:42 
Generalcsharp fatal error C1102 Pin
Harm Salomons23-Mar-03 19:53
Harm Salomons23-Mar-03 19:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.