I got problem with this function for adding icon to a program with small programs it corupts it and with bigger programs it doesn't even do anything
#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)) \
|| !UpdateResource(ih,MAKEINTRESOURCE(3),MAKEINTRESOURCE(50),0,Buffer+22,fSize-22) \
|| !EndUpdateResource(ih,FALSE)
){
Buffer ? free(Buffer) , ih ? CloseHandle(ih) : 0 : 0;
return false;
}
free(Buffer),CloseHandle(ih);
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;
}
I searched all the net i couldn't find what's the problem this is
hopefully someone will help me what's wrong