Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

how to  programmatically add binary custom resource to vb6 project

Posted on 2007-07-26
13
Medium Priority
?
1,443 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:bobimas
  • 5
  • 3
  • 2
  • +3
13 Comments
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 19573647
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
0
 
LVL 1

Author Comment

by:bobimas
ID: 19573756
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
0
 
LVL 1

Author Comment

by:bobimas
ID: 19573806
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
 
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 46

Expert Comment

by:Kent Olsen
ID: 19573824
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
0
 
LVL 86

Expert Comment

by:jkr
ID: 19574034
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);
    }
}
0
 
LVL 8

Expert Comment

by:Anthony2000
ID: 19576444
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
0
 
LVL 8

Expert Comment

by:Anthony2000
ID: 19576494
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
0
 
LVL 1

Author Comment

by:bobimas
ID: 19577162
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.

0
 
LVL 22

Expert Comment

by:DarkoLord
ID: 19583116
Well, you can change the resource inside the .RES file in the exactly same way as you do it with the .EXE file.
0
 
LVL 1

Author Comment

by:bobimas
ID: 19583132
DarkoLord:
I am not sure i understand what you mean.
0
 
LVL 8

Accepted Solution

by:
Anthony2000 earned 1200 total points
ID: 19583628
bobimas, I found this page that discusses how to build res files without using the ide, maybe this will help.
http://www.vbaccelerator.com/home/vb/code/Libraries/Resources/Using_RC_EXE/article.asp
0
 
LVL 3

Assisted Solution

by:DefreeComan
DefreeComan earned 800 total points
ID: 19586794
bobimas:
The .res files are compiled from .rc files by RC.exe (or similar programs, but since you are using VB I would assume you have Visual Studio, which RC.exe comes with)  The .rc file will contain the name of the binary file that you are editing and wanting to put in in place of its old version in the .res file, so as long as you don't change the name of the binary file you can update the .res file with the command
RC.exe -r resources1.rc
(this is in the article Anthony2000 last pointed you to)  Add several lines like that to a batch file and you'll have your automation.
0
 
LVL 1

Author Comment

by:bobimas
ID: 19586997
Thanks.
I will try your suggestions in the next build and write back/split point.

thanks.
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question