Link to home
Start Free TrialLog in
Avatar of bobimas
bobimasFlag for United States of America

asked on

how to programmatically add binary custom resource to vb6 project

I have a resource file aaa.res

How can i programmatically add binary custom resource (vb6) to that.res file.
What i do now is to open VB6 ide, press the resource editor button inside the IDE, then choose "Add custom resource" button and add a binary resource .

How can i programmatically do that from another exe (ie, exe2 will run, and add the binary custom resource to the .res file)?
I.E from another exe/batch file
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Hi Bob,

Do you truly want an arbitrary control added to the form or do you just want to enable/disable a control?

If the latter, just put it on the form at design time and set its Visible property to false.


Kent
Avatar of bobimas

ASKER

Hi.
Thanks for your answer but i think you answered some other question since you answer does not have anything to do with my question (control/enable/disable a control???).

Can you please re read my question.
Thanks
Avatar of bobimas

ASKER

To clarify, i have .res file.
I want to automate the process of adding resource entry to that .res file.
To add a resorec entry to that .res file what i do now is to open VB6 ide, press the resource editor button inside the IDE, then choose "Add custom resource" button and add a binary resource .
I do not want to do that since that binary entry i add to that .res file is still changing.
So i want to have another exe/batch file that when i press it, it will read the binary file "bnry" from the disk, and add it to the .res file (with id and resource type - just like the ide do).
Of course it will need to remove the old "bnry" file from the .res file.
So what i need is this:
1)Read the "bnry" file from disk to buf.
2)Open .res file, find the entry /custom/101 for example and remove it
3)Write the buf contact to the .res file as a custom resource type with id 101
 
Hi Bob,

I was trying to "read between lines" and thought that you might be trying to modify the resource file as a way to change a program's behavior.

I don't know of any good way, or really a good reason to do this, except during program development.  All of the IDEs do this, of course, but that's part of their purpose.

Can you describe the ultimate goal.  Maybe there's an easier way.

Kent
Check out http://www.codeproject.com/cpp/UpdateResource.asp ("UpdateResource - How to manipulate raw resources (RT_RCDATA) using UpdateResource()") - this article describes how to do that by adding the Windows calculator as a binary resource to an arbitrary executable. The scoop is to

HANDLE hFile;
DWORD dwFileSize,      
      dwBytesRead;
LPBYTE lpBuffer;

hFile = CreateFile(L"C:\\Winnt\\System32\\calc.exe", GENERIC_READ,
                   0,
                   NULL,
                   OPEN_EXISTING,
                   FILE_ATTRIBUTE_NORMAL,
                   NULL);

if (INVALID_HANDLE_VALUE != hFile)
{
    dwFileSize = GetFileSize(hFile, NULL);

    lpBuffer = new BYTE[dwFileSize];

    if (ReadFile(hFile, lpBuffer, dwFileSize, &dwBytesRead, NULL) != FALSE)
    {
        // do something with lpBuffer here
    }

    delete [] lpBuffer;        
   
    CloseHandle(hFile);
}

HANDLE hResource;

hResource = BeginUpdateResource(L"C:\\...\\t3.exe", FALSE);
if (NULL != hResource)
{
    if (UpdateResource(hResource,
        RT_RCDATA,
        MAKEINTRESOURCE(104),
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        (LPVOID) lpBuffer,
        dwFileSize) != FALSE)
    {
        EndUpdateResource(hResource, FALSE);
    }
}
I think what bobimas wants to do is to incorporate the process of adding a resource at build time. He just wants to automate the process. Am I correct?

I found some information to help create an add-in. But, I am afraid you will have to write it yourself or maybe someone else can put one together for you. Another thought, but I don't know how to do it, is to create a script (using say VB script) to automate the procedure. Maybe another expert can help.

Anthony
bobimas, if I was correct about what you are looking for, I found this product that maybe of use.
http://www.qwerks.com/product/1877.html
Avatar of bobimas

ASKER

Ok.
More infor what i  am doing
I have X builds of the same exe.
Each exe should have its own resource.
exe1 has bnry1 and some other files (only bnry chances since it is in develop).
So i have:
project 1 (.vbp) with res1.res
project 2 (.vbp) with res2.res
project 3 (.vbp) with res3.res
....
The source file in all projects are the same files (except some very few files).
And also res1.res  .. resn.res are not the same.

What i do now is that every time i change bnry1...bnryn, i need to open EACH project1 to projectn
press the resource editor button (in each project) inside the IDE, delete the prev bnry file inside the .res file then choose "Add custom resource" button and add the new binary (bnry) resource.
I have a batch file that create bnry1..bnryn.
What i want is an auto way to replace the old bnry1 to bnryn inside the .res1.res...resn.res.
I do NOT change the resource inside the final exe.
So this  is the process:
1)I work on bnry1 to bnry2 and develop them.
2)I finish developing them, then i press the batch file i have that creates them.
3) HERE where i need the help.
I want here to replace the OLD bnry1 to bnryn inside the .res1.res .. .resn.res with these new bnry files without doing it in the IDE.
4)I create the final exe1 ...exen that contains the res1.res ...  resn.res

All does automatically except from step 3 where i need your help.

I do NOT change the resource inside the final exe.

Well, you can change the resource inside the .RES file in the exactly same way as you do it with the .EXE file.
Avatar of bobimas

ASKER

DarkoLord:
I am not sure i understand what you mean.
ASKER CERTIFIED SOLUTION
Avatar of Anthony2000
Anthony2000
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bobimas

ASKER

Thanks.
I will try your suggestions in the next build and write back/split point.

thanks.