I can't believe it. One of the series: What exactly does VB do for us? [1]

Source: Internet
Author: User
Tags ole win32
Guide:
"What a surprise series"
Every time I see the Master's things to the wonderful place, I will be simply astounding: "Wow, really unexpected." "。 After a lot of this feeling, I found that as long as we have a brain, we can have something to make others think of. So think of these unexpected east take out and share with you, hope, can lead to more unexpected things.
I can't believe it. One of the series: What exactly does VB do for us?
Keywords: vb, underlying, Win32, API, COM
Difficulty: Intermediate
Requirements: Familiar with VB, will use VC debugger, understand Win32 SDK, COM.
VB has been considered to have the following advantages and disadvantages: The advantages are quick to start, the development efficiency is high, the disadvantage is the limited capacity, low operating efficiency. This is some software to make VB as the preferred language, and some software will certainly not use VB to do the reasons. And many Vc,delphi programmers think that VB in the development of not free, it let us do things easy at the same time, but also let us play more and more small. Indeed, simplicity and power are two contradictions in themselves. That is afraid of a line of code does not write, just start to run an empty form such simple action, VB at the bottom for us to do a lot of complex work (not just register window class, display window, start message loop so simple), these work is transparent to the programmer. We are grateful to the VB development team for our programmers, but also to blame why these underlying actions are not mentioned in the document, although these actions may not affect the final program, but we have the right to know, not to mention that these actions sometimes do affect our work (I will be in the later series of the " VB Multi-Threading "in this effect).
However, all of you who wish to get "undisclosed technical secrets" from this article will be disappointed because I know as much as you do, and all we can do is stand outside and guess what VB has done in it. So I'm not going to take everyone together to the VB reverse engineering, but to guess through the internal work of VB to some of the original fuzzy concept to clear. As a series of the first article, its purpose is to lay the foundation behind the deep, so I will need to point out that we have to grasp the knowledge points, if you are not clear, please timely study the relevant books to make up, specifically see "Bibliography."
Finally, to declare that the various experiments and inferences I have made in this article are my own personal opinion, that I cannot guarantee its correctness and that I do not assume any relevant legal liability.
OK, let's get started. First prepare our weapons, I will use the following tools mainly include: VB6 Chinese Enterprise Edition +sp5 (nonsense), as well as Spy + +, dependency walk and Ole Viewer (hereinafter referred to as Spy and depend and OLEView, Spy in VB CD common/tools/vb/under the Spy directory, OLEView is the oleview.exe in its lower oletools directory, note that there is also a ole2vw32.exe function similar, but this article refers to the Oleview.exe, but also denpend in the unsupprt/depend under it). Also use VC (the above mentioned tools in the VC has), because we also have to look at VB generated code, make VB Advanced development friend must use VC debugger, understand point assembly better. Of course, the focus of this article is not here, so there is no VC does not matter.
Open VB6 New Standard EXE project, in the "project", "Reference" dialog box should have four references, the simple point is: 1, Visual Basic for Application (VBA) 2, VB Runtime Object Library 3, VB Object Library 4, OLE Automation. The first three is any VB project must, you want to not all, do not believe you try to remove the reference to them. So what is the use of these three core type libraries and what role they play in the resulting executable program, which is the first question to be analyzed in this article.
1) The difference between VB, VBA, and VBS have you got it straight?
First VBS should not be compared with VB, VBA, it is Microsoft according to its own definition of the ActiveX scripting specification written completely from the beginning of the scripting language, although its grammatical structure and VB very similar, but VBS only rely on automation objects to expand its function (only late binding), It is not possible to use implements to implement the interface, it is impossible in the VBS directly using the API, there is no varptr such a function to get pointers, and VBS is missing these functions are unique to VB and VBA. Of course, this is not to say that VBS is not as good as VB or vba,windows has provided a strong enough functionality for VBS, we can use VBS to do script COM components, and the ability to borrow automation object VBS can say that the ability is unlimited, so there is a virus to write with VBS, For programmers, the most important feature of VBS is the ability to provide macros to their software, just like the VBS macros provided in VCS. Note that VBS is FREE, and this is different from using VBA in office to provide macro functionality, which requires a low cost license fee for integrating VBA, see MSDN Platform Sdk/tools and languages/scripting for scripting languages. (In the article "scripting" later in this series, I'll do a little software that uses VBS to provide macro functionality)
So what is the difference between VB and VBA? Well, seeing is believing, let's begin our experiment.
If you have Office 2000 or later, open OLEView, click View TypeLib under File to view E:/program Files/common Files/microsoft shared/vba/ Vba6 under the Vbe6.dll type library, and then look at the Msvbvm60.dll type library in the same way, you will find that their type library is basically the same, in addition to Vbe6 a Vbeglobal interface and implement this interface of the global object, this global object we can also in the VBA (such as the VB Editor in Word) to see with the Object Browser. It has two methods, load and unload, and a UserForms property because Vba6 uses the MS Form 2.0 form Designer (Fm20.dll) to design and use UserForm forms (and in VB6, we can use multiple designers.) For example, by using the MS Form 2.0 form Designer, we can use the UserForm user form that VBA uses in VB. Similar to the VBA global object, in VB also has the global object, from the VB Object Browser can know it in Vb6.olb this type library, this type library is each project must refer to the VB Object Library, all the VB built-in objects are here. The objects used in VBA's UserForm are in Fm20.dll.
In addition to the above differences, VB and VBA have one of the biggest difference is that VBA can not generate EXE executable files, but you can guess in the IDE environment VBA and VB to compile code to P-code to execute, I will use experiments to prove that this is true, Although the concrete implementation of VB and VBA are very different.
From the above analysis can see VB and VBA or very different, this difference is mainly embodied in the programming environment and object structure, but in essence they have an inseparable relationship between the blood source. If you had just looked closely at the Msvbvm60.dll type library, you would have found the following fragment:
Generated. idl file (by the Ole/com Object Viewer)
[
Dllname ("Vba6.dll"),
UUID (35BFBDA0-2BCC-1069-82D5-00DD010EDFAA),
HelpContext (0X000F6EC4)
]
Module Strings {
[Entry (0x60000000), HelpContext (0x000f665f)]
Short _stdcall ASC ([in] BSTR string);
[Entry (0x60000001), HelpContext (0x000f6e9f)]
BSTR _stdcall _B_STR_CHR ([in] long charcode);
...............
}
What the. Objects in Msvbvm60.dll whose methods are defined in Vba6.dll: VB installation directory There is not a vba6.dll it. Then use OLEView to look at it, wow, it is unexpectedly and msvbvm60.dll the same. What's going on. Get out depend and see the output functions of the three DLLs, Vba6.dll, Msvbvm60.dll and Vbe6.dll. Ha, there are new discoveries, we can find that in the output function of three DLLs from numbers 512 to 717 most are identical to some functions that start with RTC, such as the Rtcmsgbox of 595 (RTC is what. Should be run time component? Control? Does anyone know that? ), which means that all three DLLs have the same runtime VBA functions.
We'll use depend to look at VB6.exe, We can see that VB6.exe introduced some of the Vba6.dll's unique functions, beginning with EB and tip, from the names of these functions, which can be found to be IDE-related, such as 79 Ebshowcode and 82 tipdeletemodule. VB6.exe does not introduce any functions that begin with the RTC (note one). Let's take a look at Msvbvm60.dll, find a compiled file with the MsgBox function, and observe it with depend, and you'll see that it introduces the Rtcmsgbox function of the number No. 595 msvbvm60.dll output (note two). and introduce many functions, such as __vbavarabs (note three), that begin with the following msvbvm60.dll. In fact, from this three "attention" we can already make some guesses, whether right or wrong, you can think first.
If you did not follow me in the experiment, but just read this article, I guess you should be a little faint. If you have done these experiments yourself, you should now be filled with questions and eager to see the conclusion. So be sure to try it yourself, learning how to study a problem is more important than seeing a conclusion.
At least we can come to the conclusion that VB and VBA is the sister of the same ancestor, but the elder sister VB than the sister VBA calendar harm some. But the elder sister will only fight alone is a strong woman, but the sister will only a wealthy. The elder sister has the fertility, is the real woman, but the sister does not have the cub, but the deep spectrum husband's way, some teaches under the command may make her husband to add a lot of, and the VBS, is also large house's daughter, but does not have the VB and the VBA sister excellent pedigree, Petite does not have to command some automatic obedient object to work She is willing to help people, not like VBA as only the rich, VB, VBA, vbs three women I like.
2) What exactly did native code (local code) do.

This article turns from
Http://www.cn-doc.com/_soft_visual_basic_tech_doc/2005_08_18_00/20050818001733242.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.