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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
| //MED - J'ai rajouté ça parce que mon projet actuel est en UNICODE.
#undef _UNICODE
#undef UNICODE
//MED - Pour compiler sous Visual 2005
#define _CRT_SECURE_NO_DEPRECATE
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
//MED - Pour que ça compile chez moi, j'ai viré les inclusions de headers manquants
//#include "vbdialog.h"
//#pragma hdrstop
//MED - Pour que ça compile chez moi, j'ai viré les inclusions de headers manquants
#define IDC_CODEFICHIER 1000
#define IDC_CODEINDEX 1001
#define IDC_LGCLE 1002
#define IDC_CLERECH 1003
#define IDC_PATH 1004
static HINSTANCE hInst;
//déclaration des fonctions de la DLL
typedef int (WINAPI *DLL_X_LEC_ART_CLE_DTA)(WORD,WORD,LPSTR,WORD,LPSTR,LPSTR);
//DLL_X_LEC_ART_CLE_DTA x_lec_art_cle_dta;
//defines pour les tailles (à modifier sans doute)
#define TAILLE_CODE_FICHIER 2
#define TAILLE_CODE_INDEX 2
#define TAILLE_LGCLE 3
#define TAILLE_CODE_FICH_IND 3
//MED - déclaration obsolète
//LONG FAR PASCAL SamplesDialog (HWND hWnd,WORD wMsg,WORD wParam,LONG lParam)
INT_PTR CALLBACK SamplesDialog(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
//MED - Eviter les Return multiples
INT_PTR bRetour = TRUE;
//MED - Déplacé les déclarations dans un bloc
// process the message
switch( uMsg )
{
// process command from one of the child controls
case WM_COMMAND:
switch( GET_WM_COMMAND_ID(wParam,lParam) )
{
// ok or cancel, so end the dialog
case IDOK:
{
//MED - Pourquoi utiliser de l'allocation dynamique, en fait ?
char *code_fichier,*code_index,*lgcle,*code_fich_ind,*bufferDest;
char cle_rech[20],path[20];
short *codes;
//int *longCle; MED - Pointeur non-initialisé et inutile.
int longCle;
DLL_X_LEC_ART_CLE_DTA x_lec_art_cle_dta;
//chargement de la dll
HMODULE hDLL = LoadLibrary("DLL.dll");
x_lec_art_cle_dta = (DLL_X_LEC_ART_CLE_DTA)GetProcAddress(hDLL,"X_LEC_ART_CLE_DTA");
code_fichier = calloc(TAILLE_CODE_FICHIER,1);
code_index = calloc(TAILLE_CODE_INDEX,1);
lgcle = calloc(TAILLE_LGCLE,1);
code_fich_ind = calloc(TAILLE_CODE_FICH_IND,1);
bufferDest = calloc(1,1);
GetDlgItemText(hWnd,IDC_CODEFICHIER,code_fichier,TAILLE_CODE_FICHIER);
GetDlgItemText(hWnd,IDC_CODEINDEX,code_index,TAILLE_CODE_INDEX);
GetDlgItemText(hWnd,IDC_LGCLE,lgcle,TAILLE_LGCLE);
GetDlgItemText(hWnd,IDC_CLERECH,cle_rech,20);
GetDlgItemText(hWnd,IDC_PATH,path,20);
//*code_fich_ind = *code_fichier; MED - Il y a plus explicite
//strcat(code_fich_ind,code_index); MED - mauvais
code_fich_ind[0] = code_fichier[0];
strncat(code_fich_ind, code_index, TAILLE_CODE_FICH_IND-1);
//(les fonctions de MS ne mettent pas toujours le zéro terminal)
code_fich_ind[TAILLE_CODE_FICH_IND-1] = '\0';
//MED - J'ignore à quoi sert codes, mais il faut un cast ici
//codes = &code_fich_ind[0];
codes = (short *)code_fich_ind;
//*longCle = atoi(lgcle);
longCle = strtol(lgcle, NULL, 10);
if(x_lec_art_cle_dta(/* * */longCle,*codes,cle_rech,5,path,bufferDest)==0)
{
//SetDlgItemText(hWnd,IDC_MSG,code_fich_ind);
//MessageBox( NULL,"ok", NULL, MB_OK | MB_APPLMODAL );
//MED - Déplacé les free
//MED - Déplacé le break
}
else
{
MessageBox( NULL,"probleme ouverture fichier" , NULL, MB_OK | MB_APPLMODAL );
//MED - Déplacé les free
//MED - Déplacé le break
}
free(code_fichier); code_fichier=NULL;
free(code_index); code_index=NULL;
free(lgcle); lgcle = NULL;
free(code_fich_ind); code_fich_ind=NULL;
free(bufferDest); bufferDest=NULL;
FreeLibrary(hDLL);
}//Bloc de variables locales
break;
case IDCANCEL:
EndDialog(hWnd, 0 );
break;
}
break;
// initialize the dialog
case WM_INITDIALOG:
//bRetour = FALSE; //MED - Il vaut mieux laisser TRUE si on ne règle pas soi-même le focus
break;
default:
bRetour = FALSE;
}//switch
return bRetour;
}
// Turn off warning: Parameter * is never used in function WinMain...
//#pragma argsused
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdLine,int nCmdShow)
{
//MED - Paramètres non-utilisés:
(void)hPrevInstance; //toujours NULL depuis Win32
(void)lpszCmdLine;
(void)nCmdShow;
// save the instance
hInst = hInstance;
// load the samples dialog box
if( DialogBox( hInstance, "Samples", NULL, SamplesDialog ) == -1 )
MessageBox( NULL, "Can't load dialog box!\n", NULL, MB_OK | MB_APPLMODAL );
// end of program
return 0;
} |
Partager