Trouver une ressource (Nouvelle version du moteur, plus rapide & pertinent, essayez le !)
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
TYPE DE LECTEUR EN ASM INLINE VC++
Information sur la source
Description
Des radioButtons remplissent une Combo avec liste des lecteurs correspondants. Le prog est en C qui appelle le remplissage en asm.
LectLogic.cpp dans le zip contient la version remplissage en C mais invalidée.
Tous les fichiers pour recompiler sont dans le zip.
Source
- LectLogic.cpp
- #include <windows.h>
- #include "resource.h"
- #include "CmbDrvs.h"
-
- BOOL CALLBACK AppDlgProc(HWND hdlg, UINT mssg, WPARAM wParam, LPARAM lParam)
- {
- switch(mssg) {
- case WM_INITDIALOG:
- SetClassLong(hdlg, GCL_HICON, (long)LoadIcon(0, IDI_APPLICATION));
- SendDlgItemMessage(hdlg, IDRAD_FLOP, BM_SETCHECK, 1, 0);
- PostMessage(hdlg, WM_COMMAND, IDRAD_FLOP, 0);
- return 1;
- case WM_COMMAND:
- switch(wParam) {
- TYPEDRV tpdrv;
- case IDRAD_FLOP:
- tpdrv = LECT_DSKT; goto drvchng;
- case IDRAD_FIX:
- tpdrv = LECT_DDUR; goto drvchng;
- case IDRAD_CD:
- tpdrv = LECT_CD; goto drvchng;
- case IDRAD_FLOP_CD:
- tpdrv = LECT_DSKT_CD; goto drvchng;
- case IDRAD_FLOP_FIX:
- tpdrv = LECT_DSKT_DDUR; goto drvchng;
- case IDRAD_FIX_CD:
- tpdrv = LECT_DDUR_CD; goto drvchng;
- case IDRAD_TOUS:
- tpdrv = LECT_TOUS;
- drvchng:
- FillCmbDrives(GetDlgItem(hdlg, IDCMB_DRV), tpdrv);
- return 0;
- case IDCANCEL: EndDialog(hdlg, 0);
- }
- }
- return 0;
- }
-
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, int)
- {
- DialogBox(hInstance, MAKEINTRESOURCE(IDD_APP), NULL, AppDlgProc);
- return 0;
- }
- -----------------------------------------------------
- CmbDrvs.cpp
- #include "CmbDrvs.h"
-
- __declspec(naked) void __stdcall FillCmbDrives(HWND hcmb, TYPEDRV typLect)
- {
- __asm {
- lea eax, [esp-36] ; [esp-20]
- mov [esp-12], esi
- mov [esp-4], ebp
- mov [esp-16], edi
- mov [eax+28], ebx
- xor ecx, ecx
- mov dword ptr[eax+16], 5C3A00h ; "\0:\\0"
- mov esi, [eax+44] ; ESI = typLect
- mov ebp, [eax+40] ; EBP = hcmb
- mov esp, eax ; + 4 params de SendMessage
- mov [eax+12], ecx
- mov [eax+8], ecx
- mov dword ptr[eax+4], 14Bh ; CB_RESETCONTENT
- mov [eax], ebp
- call dword ptr GetLogicalDrives
- mov edi, eax ; EDI = dwdrvs
- call dword ptr SendMessage ; ESP += 16
- mov ebx, 65
- goDrvs:
- shr edi, 1
- jc short insDrv
- jz short drvsEnd
- jmp short nextDrv
- insDrv:
- mov byte ptr[esp], bl
- or esi, esi
- jz short drvOK
- push esp
- call dword ptr GetDriveType
- test esi, 0F00h
- jz short typUnic
- mov ecx, esi
- mov edx, esi
- cmp ch, al
- je short drvOK
- cmp dl, al
- je short drvOK
- jmp short nextDrv
- typUnic:
- cmp eax, esi
- jne short nextDrv
- drvOK:
- push esp
- push 0
- push 143h ; CB_ADDSTRING
- push ebp
- call dword ptr SendMessage
- nextDrv:
- inc ebx
- jmp short goDrvs
- drvsEnd:
- lea eax, [esp+4]
- mov [esp], ebp
- mov edi, [eax]
- mov esi, [eax+4]
- mov ebx, [eax+8]
- mov dword ptr[eax+8], 0
- mov dword ptr[eax+4], 0
- mov dword ptr[eax], 14Eh ; CB_SETCURSEL
- call dword ptr SendMessage ; ESP += 16
- pop ebp
- ret 8
- }
- }
LectLogic.cpp
#include <windows.h>
#include "resource.h"
#include "CmbDrvs.h"
BOOL CALLBACK AppDlgProc(HWND hdlg, UINT mssg, WPARAM wParam, LPARAM lParam)
{
switch(mssg) {
case WM_INITDIALOG:
SetClassLong(hdlg, GCL_HICON, (long)LoadIcon(0, IDI_APPLICATION));
SendDlgItemMessage(hdlg, IDRAD_FLOP, BM_SETCHECK, 1, 0);
PostMessage(hdlg, WM_COMMAND, IDRAD_FLOP, 0);
return 1;
case WM_COMMAND:
switch(wParam) {
TYPEDRV tpdrv;
case IDRAD_FLOP:
tpdrv = LECT_DSKT; goto drvchng;
case IDRAD_FIX:
tpdrv = LECT_DDUR; goto drvchng;
case IDRAD_CD:
tpdrv = LECT_CD; goto drvchng;
case IDRAD_FLOP_CD:
tpdrv = LECT_DSKT_CD; goto drvchng;
case IDRAD_FLOP_FIX:
tpdrv = LECT_DSKT_DDUR; goto drvchng;
case IDRAD_FIX_CD:
tpdrv = LECT_DDUR_CD; goto drvchng;
case IDRAD_TOUS:
tpdrv = LECT_TOUS;
drvchng:
FillCmbDrives(GetDlgItem(hdlg, IDCMB_DRV), tpdrv);
return 0;
case IDCANCEL: EndDialog(hdlg, 0);
}
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, int)
{
DialogBox(hInstance, MAKEINTRESOURCE(IDD_APP), NULL, AppDlgProc);
return 0;
}
-----------------------------------------------------
CmbDrvs.cpp
#include "CmbDrvs.h"
__declspec(naked) void __stdcall FillCmbDrives(HWND hcmb, TYPEDRV typLect)
{
__asm {
lea eax, [esp-36] ; [esp-20]
mov [esp-12], esi
mov [esp-4], ebp
mov [esp-16], edi
mov [eax+28], ebx
xor ecx, ecx
mov dword ptr[eax+16], 5C3A00h ; "\0:\\0"
mov esi, [eax+44] ; ESI = typLect
mov ebp, [eax+40] ; EBP = hcmb
mov esp, eax ; + 4 params de SendMessage
mov [eax+12], ecx
mov [eax+8], ecx
mov dword ptr[eax+4], 14Bh ; CB_RESETCONTENT
mov [eax], ebp
call dword ptr GetLogicalDrives
mov edi, eax ; EDI = dwdrvs
call dword ptr SendMessage ; ESP += 16
mov ebx, 65
goDrvs:
shr edi, 1
jc short insDrv
jz short drvsEnd
jmp short nextDrv
insDrv:
mov byte ptr[esp], bl
or esi, esi
jz short drvOK
push esp
call dword ptr GetDriveType
test esi, 0F00h
jz short typUnic
mov ecx, esi
mov edx, esi
cmp ch, al
je short drvOK
cmp dl, al
je short drvOK
jmp short nextDrv
typUnic:
cmp eax, esi
jne short nextDrv
drvOK:
push esp
push 0
push 143h ; CB_ADDSTRING
push ebp
call dword ptr SendMessage
nextDrv:
inc ebx
jmp short goDrvs
drvsEnd:
lea eax, [esp+4]
mov [esp], ebp
mov edi, [eax]
mov esi, [eax+4]
mov ebx, [eax+8]
mov dword ptr[eax+8], 0
mov dword ptr[eax+4], 0
mov dword ptr[eax], 14Eh ; CB_SETCURSEL
call dword ptr SendMessage ; ESP += 16
pop ebp
ret 8
}
}
Conclusion
__declspec(naked) est mis devant la fonction asm pour dire au compilo qu'il n'y mette pas ses pattes. Ceci permet toute liberté sur manipulation des registres.
Fichier Zip
Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
Télécharger le zip
Sources de la même categorie
Commentaires
|
CalendriCode
| | | L | M | M | J | V | S | D |
| 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 | | | | | |
|
|