J'essaie d'utiliser lstrcpy de kernel32.dll pour obtenir une chaîne à partir d'un pointeur en C#, mais cela ne fonctionne pas. lstrlenA fonctionne, cela me donne la longueur de la chaîne, donc je tape au moins kernel32.dll. lstrcpy travaille dans l'application VB6 que je convertis, donc je sais que ça PEUT fonctionner, mais je ne sais pas pourquoi il n'est pas là.lstrcpy pas de mise à jour passée dans la chaîne
La chaîne s n'est jamais remplie avec la chaîne actuelle, elle renvoie simplement la chaîne initiale.
[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;
}
http://msdn.microsoft.com/en-us/library/7b620dhe(v=VS.100).aspx – dtb
Marshal.PtrToStringAnsi fonctionne! Si vous répondez, je le marquerai comme la réponse acceptée. –