hey i wanted to make a function that adds icon to program but i think i got some problems here it corrupts the file but i don't know it's problem hopefully someone here can help me out
Code:#include <stdio.h> #include <windows.h> #define MIN 2 char *ReadFile(char *SzFile,int *BytesCount) { int fSize; FILE *pFile; char *Buffer; if(!(pFile=fopen(SzFile,"rb"))) return NULL; fseek(pFile,0,SEEK_END); fSize=ftell(pFile); rewind(pFile); if(!(Buffer=(char*)calloc(fSize,sizeof(char)))) return NULL; fread(Buffer,fSize,1,pFile); *BytesCount=fSize; return Buffer; } bool AddIcon(char *SzFile,char *SzIcon) { HANDLE ih; char *Buffer; int fSize=0; if(!(Buffer=ReadFile(SzIcon,&fSize)) || !(ih=BeginUpdateResource(SzFile,FALSE))) return false; if(!UpdateResource(ih,RT_ICON,SzIcon,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),Buffer,fSize*sizeof(char))) return false; if(!EndUpdateResource(ih,FALSE)) return false; CloseHandle(ih); free(Buffer); return true; } int main(int argc,char *argv[]) { if(argc<MIN) { printf("wrong usage: must be bigger than %d\n",MIN); return 1; } int sucess=0; for(int i=1;i<argc;i++) if(AddIcon(argv[i],argv[argc-1])) { printf("\nadded icon %s to file %s\n",argv[argc-1],argv[i]); sucess++; } printf("we succesfully added %d icons",sucess); return 0; }



LinkBack URL
About LinkBacks


