C Board  

Go Back   C Board > Platform Specific Boards > Windows Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-22-2009, 10:44 PM   #1
Registered User
 
Join Date: Oct 2009
Posts: 8
trying to add icon to program

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;
}
MrNoobah is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
g++ compiler errors with vector class after installing/uninstalling libstlport Gatemaze C++ Programming 2 09-16-2009 06:00 AM
Using variables in system() Afro C Programming 8 07-03-2007 12:27 PM
Somewhat new to c++, adding Prime number and Sqrt featre to program... thynksheraze C++ Programming 3 01-14-2003 10:34 PM
Please could someone help me with my 8-function calculator program? Geeth Asokan C Programming 2 05-10-2002 04:16 PM
My program, anyhelp @licomb C Programming 14 08-14-2001 10:04 PM


All times are GMT -6. The time now is 01:01 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22