[API windows] Problème d'argument de type LPSTR
Bonjour,
Je travaille sur un petit programme permettant de retourner les coordonnées d'une fenêtre dont le nom est passé en paramètre.
Voici mon problème :
Je tente de récupérer les arguments d'appel de mon programme grâce à LPWSTR GetCommandLineW() et LPWSTR* CommandLineToArgvW(LPCWSTR, int *).
Je veux ensuite passer en 2eme argument de la fonction HWND WINAPI FindWindow(LPCTSTR, LPCTSTR) le second champ de cette LPWSTR* que je caste donc en LPSTR (donc (LPSTR)commande[1]).
Le problème est qu'en appelant le programme il me renvoie ceci (il n'a pas trouvé la fenêtre nommée "Fenetre") :
Code:
1 2 3
| C:\Users\Sabotaz\FindWindow>FindWindow.exe Fenetre
Fenetre
2000082261 -2 19851693 2000334401 |
alors qu'en passant directement la chaine "Fenetre" à la fonction FindWindow() il me renvoie bien ceci :
Code:
1 2 3
| C:\Users\Sabotaz\FindWindow>FindWindow.exe Fenetre
Fenetre
0 1366 22 728 |
Voici la totalité de mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include <windows.h>
#include <stdio.h>
int WINAPI WinMain (
HINSTANCE cetteInstance,
HINSTANCE precedenteInstance,
LPSTR lignesDeCommande,
int modeDAffichage
)
{
HWND fenetre;
WINDOWINFO infoFenetre;
LPWSTR* commandes;
int nbCommandes;
LONG gauche, droit, haut, bas;
commandes = CommandLineToArgvW(GetCommandLineW(), &nbCommandes);
infoFenetre.cbSize = sizeof(WINDOWINFO);
printf("%ws\n", commandes[1]);
//fenetre = FindWindow(NULL, (LPSTR)commandes[1]);
fenetre = FindWindow(NULL, "Fenetre");
GetWindowInfo(fenetre, &infoFenetre);
gauche = infoFenetre.rcClient.left;
droit = infoFenetre.rcClient.right;
haut = infoFenetre.rcClient.top;
bas = infoFenetre.rcClient.bottom;
printf("%i %i %i %i\n", gauche, droit, haut, bas);
LocalFree(commandes);
return 0;
} |
Merci de votre aide, et en espérant avoir été assez clair,
Sab.