J'essaye d'obtenir un appel à EnumThreadWindows fonctionnant, mais j'obtiens toujours un mauvais Parameter-Error, bien que mon code soit presque le même que this example on pinvoke.net. Je ne sais pas pourquoi cela ne fonctionne pas:Appel de Win32 EnumThreadWindows() en C#
public static IntPtr FindMsgBoxFrom(IntPtr MainHWND)
{
SetLastError(0);
uint ThreadID = GetThreadID(MainHWND);
EnumThreadWindows(ThreadID, new WNDENUMPROC(decoder.FindMsgBox), IntPtr.Zero);
int last = Marshal.GetLastWin32Error();
if (last != 0)
MessageBox.Show("EnumThreadWindows-Error:\n" + GetLastErrorString());
return MSGHWND;
}
et c'est decoder.FindMsgBox
:
public static bool FindMsgBox(IntPtr hwnd, IntPtr lparam)
{
if (IsMsgBox(hwnd))
{
MSGHWND = hwnd;
return false;
}
else
return true;
}
}
Quel est le problème avec ça?
Veuillez inclure votre déclaration d'EnumThreadWindows et le délégué WNDENUMPROC. Aussi, si vous pouviez inclure plus d'informations sur l'erreur qui serait utile. Par exemple, obtenez-vous une heure de compilation ou une erreur d'exécution? Il est inutile d'appeler SetLastError à partir du code managé. –
oh je suis désolé j'ai oublié que: [DllImport ("user32.dll", SetLastError = true)] public static extern bool EnumThreadWindows (Uint dwThreadId, WNDENUMPROC lpfn, IntPtr lParam); délégué public booléen WNDENUMPROC (IntPtr hWnd, IntPtr lParam); et j'obtiens l'erreur quand j'appelle Marshal.GetLastWin32Error(); et formatez-le avec FormatMessage – alex
Modifiez votre question avec les nouvelles informations. Il n'y a pas de formatage sur les commentaires, c'est presque impossible à lire. – ChrisF