Problème de connexion avec rapi.dll : CeRapiInitEx sous Win7
Bonjour à tous, je suis entrain de travailler sur la portabilité d'une application vers Windows Seven et à ce sujet je suis face un problème bien embarrassant lorsque j'essaye de me connecter à un PDA sous WinCE depuis un PC sous Win7 :
Je possède un thread qui tente d'établir une connexion avec un PDA via rapi.dll.
Tant que le PDA est physiquement connecté (disons "branché"), tout va bien, j'arrive à établir la connexion.
Mais si je tente d'établir la connexion quand le PDA est débranché et que j'attends la fin du thread, alors je n'arrive plus jamais à rétablir la connexion par la suite : CeRapiInitEx me renvoie E_INVALIDARG à chaque tentative avec un handle égal à 0.
Détail intéressant : si je débranche puis rebranche le PDA en restant dans le même thread alors la connexion s'établit.
Je viens de réaliser des tests sous Windows XP et j'ai découvert que CeRapiInitEx retourne toujours un résultat "positif" et me fournit un handle même si le PDA n'est pas branché!
Il ne me reste ensuite plus qu'à tenter une connexion avec WaitForSingleObject(pHandle, pTimeout) et à tester le retour... ce qui m'arrange grandement!
Ma question est donc la suivante : pourquoi CeRapiInitEx se comporte-t-il différemment sous Windows Xp et sous Windows Seven ? Comment y remédier?
Pour info :
- Ce problème intervient sous Windows 7 (32 et 64 bits) mais pas sous Windows XP 32 bits.
- "PDA branché" = PDA reconnu par Windows (le gestionnaire Windows Mobile indique que le périphérique est connecté)
- J'ai simplifié ma procédure au maximum, il ne reste que la méthode qui semble poser problème : CeRapiInitEx.
Définition de RAPIINT :
Code:
struct RAPIINIT{int cbsize; IntPtr heRapiInit; uint hrRapiInit;}
Import de rapi.dll :
Code:
1 2
| [DllImport("rapi.dll", CharSet = CharSet.Unicode)]
static extern uint CeRapiInitEx(ref RAPIINIT pRapiInit) |
Log sous Windows XP 32 bits que le PDA soit branché ou pas
Code:
1 2 3
| CeRapiInitEx(ref rapiInit) = S_OK
- rapiInit.hrRapiInit = S_OK
- rapiInit.heRapiInit = 1456 |
Log du problème sous Windows Seven 64 bits
1. le PDA est branché.
Code:
1 2 3 4 5 6
| a. Début du thread
b. CeRapiInitEx(ref rapiInit) = S_OK
- rapiInit.hrRapiInit = S_OK
- rapiInit.heRapiInit = 1456
d. CeRapiUninit()
e. Le thread se termine. |
2. le PDA est débranché.
Code:
1 2 3 4 5 6
| a. Début du thread
b. CeRapiInitEx(ref rapiInit) = S_OK
- rapiInit.hrRapiInit = E_FAIL
- rapiInit.heRapiInit = 1628
c. CeRapiUninit()
d. Le thread se termine. |
3. le PDA est branché.
Code:
1 2 3 4 5 6
| a. Début du thread
b. CeRapiInitEx(ref rapiInit) = E_INVALIDARG
- rapiInit.hrRapiInit = S_OK
- rapiInit.heRapiInit = 0
c. CeRapiUninit()
d. Le thread se termine. |
A partir de là et à chaque tentative, CeRapiInitEx retourne toujours le même E_INVALIDARG et un handle égal à 0 (valeur invalide...)