-
May 1st, 2021, 01:37 AM
#1
Thread Starter
PowerPoster
Vb6 res file size error?DWord Alignment of VB Resource File Entries
I put the DLL and OCX into the resource file, which can be loaded without decompressing it to the hard disk, but the file size was mistaken by the compiler. As a result, the DLL cannot be loaded in the memory.
I PUT A FILE TO Res file,
size=377093
dim bt2() as byte
BT2 = LoadResData(ResNameOrId, ResGroup)
ubound(bt2)+1=377096
Why is it adding 3 bytes? It’s so weird
===================
Other people on the Internet have also encountered this problem:
When you plan to add a text file to the resource file and release it while the program is running, you will definitely think of using the resource editor. Okay, the program is ready, load the text file with the byte array loadresdata, and then use open/ Put/close or use API to write this text file to the hard disk, press F5 to run, open the text file to see, uh, no problem, ok, compile the program to EXE, then run it again, open the text file to check, uh , Still the original content.
Many people will think that the program is normal when they see this. In fact, you can use the HEX editor (ULTRA EDIT or other) to compare the text file generated by running in the IDE environment and the text file generated by running after compilation, you will find There are 2 more bytes (00 00) at the end of the text file generated after compilation. These two bytes will not have a big impact on general text files, but for files like XML that need to be strictly interpreted , Two more unnecessary bytes is a fatal injury.
Wonder, how did these two bytes come into being? Analyze the process of file generation:
First look at the results of running under the IDE
The first is loadresdata to load the text file data in the resource file into a byte array
Will there be a problem here? Run in the IDE, set the interrupt, check the value of ubound (byte array), and find that it is the same as the original number of bytes in the text file, so it is excluded from the loading process
Then output the file through VB's own file writing statement or API function
Run in IDE, use OPEN/PUT/CLOSE and CREATEFILE/WRITEFILE/CLOSEHANDLE to generate files. Normally, they are the same as the original file bytes, so it can also be excluded.
Then look at the result of running the compiled EXE file
The same is to loadresdata first to load the text file data in the resource file into a byte array
You can’t see the result here. You can set a msgbox prompt ubound (byte array) value in the program. You can see that the array is 2 bytes more than in the IDE. I can’t explain whether there is a problem here, and continue.
Then output the file through VB's own file writing statement or API function
After inspection, the files are more than 2 bytes, eliminating the possibility of function errors
So where is the problem? Keep watching
Then use PE explorer to check the internal resources of the EXE file, you can find the text file we put into the resource file, we select this resource, and then click the resource property to view the size of the resource, the shortcut key is (shift+ctrl+P), you can see The number of bytes displayed is 2 bytes larger than the original file. It turns out that the culprit we are looking for is here. It is already so big. No wonder the output will be larger than the original file. The function is not wrong. The function is just for you to output honestly, or from the resource The data coming out of the file doesn't have to be messed up, so why is the IDE output correct, but the EXE output is wrong? It is because the EXE has been compiled and the resource files are compiled into the EXE file. The problem lies in the compiler. The text files in the EXE resource files that are handed out by it are all 2 bytes larger. As for why there are any Conclusion, waiting for the master to answer us. However, it's better to come out and give us a lecture, and send us a new compiler by the way.
Last edited by xiaoyao; May 1st, 2021 at 12:53 PM.
-
May 1st, 2021, 04:46 AM
#2
Re: Vb6 res file size error?
I tried adding a text file as a custoum resource and loaded it into a byte array using LoadResData. The resulting number of bytes in the array is exactly the same as in the file. So no mysterious additional bytes in my case. Perhaps you could create a small project demonstrating your case for people to examine?
Last edited by Peter Swinkels; May 2nd, 2021 at 05:00 AM.
Reason: fixed a sentence.
-
May 1st, 2021, 07:59 AM
#3
Thread Starter
PowerPoster
Re: Vb6 res file size error?
Originally Posted by Peter Swinkels
I tried adding a text file as custoum resource and loaded it into a byte array using LoadResData. The resulting number of bytes in the array is exactly the same as in the file. So no mysterious additional bytes in my case. Perhaps you could create a small project demonstrating your case for people to examine?
This does have this kind of problem, it is normal in IDE, compiling into EXE will cause a small amount of resource files to take up bytes after reading. Maybe part of the new version of VB6.EXE may fix this problem. In short, VB6's resource manager tool software has BUG.
-
May 1st, 2021, 11:13 AM
#4
Re: Vb6 res file size error?
-
May 1st, 2021, 12:44 PM
#5
Thread Starter
PowerPoster
Re: Vb6 res file size error?
Originally Posted by dilettante
Very perfect article, thanks!
maybe wrote a module by Ourself. All the files in the resource are written in a notepad file with the format:
Resource name, Size, File path
Resource name ,Size ,File path
Resource name, Size ,File path
Add this file size list to the resource, the name is: ResFileSize
When opening the software, read this resource first, then parse it into a dictionary or collection object, and then read files in other resources, and then reduce the byte array according to this list.
I have encountered a situation where sometimes it is necessary to increase or decrease a few bytes to keep the consistency. I never know why, but this time I realized that the original content was mistaken by the resource tool.
VB6 has been used for so many years. In addition to not supporting 64-bit EXE compilation, many Internet senior programmers have added multithreading, standard DLL generation and other functions to him, as well as powerful OLEEXP.TLB, OLELIB.TLB and so on.
Almost perfect product with few bugs.
VisualFreebasic developed by the Chinese now has many problems. After all, individuals are only developing based on interest, and the development progress is slow. If there are 30-200 engineers in the development team like Microsoft, more than 95% of the bugs will be fixed.
Last edited by xiaoyao; May 1st, 2021 at 12:50 PM.
-
May 1st, 2021, 06:38 PM
#6
Re: Vb6 res file size error?DWord Alignment of VB Resource File Entries
If you're putting a manifest in a resource, yes you need to align it. I started running into problem with unaligned manifests.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|