lstrcpy not updating passed in string

Posted by Rorschach on Stack Overflow See other posts from Stack Overflow or by Rorschach
Published on 2010-04-30T15:52:42Z Indexed on 2010/05/01 19:07 UTC
Read the original article Hit count: 161

Filed under:
|
|

I'm trying to use kernel32.dll's lstrcpy to get a string from a pointer in C#, but it isn't working. lstrlenA IS working, it gives me the length of the string, so I'm hitting the kernel32.dll at least. lstrcpy is working in the VB6 app I'm converting, so I know it CAN work, but I don't have a clue why it isn't here.

The string s never gets filled with the actual string, it just returns the initial padded string.

[DllImport("kernel32.dll", EntryPoint = "lstrlenA", CharSet = CharSet.Ansi)]
private static extern int lstrlen( int StringPointer );

[DllImport( "kernel32.dll",EntryPoint = "lstrcpyA", CharSet = CharSet.Ansi )]
private static extern int lstrcpy(string lpString1, int StringPointer );

private static string StringFromPointer(int pointer)
{
    //.....Get the length of the LPSTR
    int strLen = lstrlen(pointer);

    //.....Allocate the NewString to the right size
    string s = "";
    for (int i = 0; i < strLen; i++)
        s += " ";

    //.....Copy the LPSTR to the VB string
    lstrcpy(s, pointer);
    return s;
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about kernel32