#1
  1. Cast down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    321
    Rep Power
    12

    What in C is equal to VB's LoadResData


    I have a exe in my resource, in VB, I would use LoadResData to load the exe into a char array. In C, how can I do this? I have the .res and it compiles fine, but I want to read each byte either into an array (not really, in case of big EXE's), I wanna write it out to a file.
  2. #2
  3. It Doesn't Work!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Slovenia
    Posts
    112
    Rep Power
    12
    You mean this?
    Code:
    FILE *input;
    #define BS 2048
    
    //llength is a length of a file
    fseek(input, 0L, SEEK_END);
    long llength = ftell(input);
    
    short eof = 0;
    long status = 0;
    char buffer[BS];
    
    while(eof == 0){
    	for(short temp = 0; temp < BS; temp++){
    		status++;
    		if(status <= llength){
    			buffer[temp] = (char)getc(input);
    		}
    		else{
    			eof = 1;
    			break;
    		}
    	}
    //here you've got the string
    }
    You write with the same loops.
    Last edited by Loser; August 25th, 2003 at 01:14 AM.
  4. #3
  5. Cast down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    321
    Rep Power
    12
    Yes, but the problem is that the exe I am putting in an array, is a resource in my program, what do I put for fopen(), as the filename to open.
  6. #4
  7. Cast down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    321
    Rep Power
    12
    I found you can easily do it with these APIs:
    FindResource, LoadResource, LockResource, and CreateFile

    But how would I do it without using API?
  8. #5
  9. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    Why can't you use these APIs?
    Include the header files into your program and use them.
  10. #6
  11. Cast down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    321
    Rep Power
    12
    I can, I am at the moment, I just don't want to. I want to learn how to do it without them.
  12. #7
  13. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    I don't understand why you want to re-invent the wheel here. This is the tools designed for the job, I personally don't see why you wouldn't want to use them.
  14. #8
  15. Cast down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    321
    Rep Power
    12
    I have no use for them, if I am developing a proffesional app, I would use them, but right now I am just curious about how they work, I just wanna play around with them, write my own, and probably never touch them again, :)
  16. #9
  17. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    27
    >>I personally don't see why you wouldn't want to use them.

    Thay are from the WIN32 API and as such platform dependant..........



    Then again what type of app hides an exe inside it, only to dump it later?
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa

IMN logo majestic logo threadwatch logo seochat tools logo