VB-like VC ++ development (1)-Introduction

Source: Internet
Author: User
When programming for beginners, it is always between VB and VC ++. VB is simple and easy to use, and VC ++ is powerful and flexible. If you encounter a problem, you often first look at what the VB implementation is like, and then try VC ++ to implement it. Because I have always been optimistic about VC ++, and I know that the truly powerful language is endless. Therefore, although VC ++ is difficult to learn, it is still very exciting for me to discover some rare treasures along the way.

In other words, one of the main areas of VB's ease of use is the calling of COM components. Using VB to call the attributes and methods of COM components is the same as calling a local code,CodeWriting is natural. VB not only supports general interface method calls, but also supports automatic calls through the idispatch interface.

VC ++ provides two sets of class libraries for COM component programming :(_ Com_ptr_t, _ variant_t, _ bstr_t) and (ccomptr, ccomvariant, ccombstr) are convenient to use. HoweverThe idispatch interface does not provide direct support, so it is very cumbersome to call it.

The idispatch interface is the most important interface in the automation field. The idispatchex interface is an extension of the idispatch interface and is the basis for internal implementation in dynamic languages such as JavaScript. If we want to access JavaScript objects in VC ++, if we want to further encapsulate the Ajax library in binary format, we must have a simple and easy-to-use auxiliary class library for support. Of course, if you want to develop plugin for pimshell, VB-like VC ++ development is also the most common programming paradigm.

In short,Programming LanguageIt must be powerful, flexible, and easy to use. It not only requires the support of the compiler, but also the support of the auxiliary library. NextArticleThrough a series of designs, we can achieve Vb-like VC ++ development.

For example, Javascript in the webpage has a function test. We call test to compare the differences between different paradigms in different languages. (Test can be accessed through the window object. We will discuss the details later .)

 

Javascript

 
Function Test (smessage) {alert (smessage) ;}// run window. Test ("Hello world! ");

 

VB (not VBScript)

 
Dim omethod as objectset omethod = Window. testomethod ("Hello world! ")

 

VB-like VC ++

 
Idispatchptr pmethod = CVB: Get (window, l "test"); CVB: invoke1 (pmethod, null, l "Hellow world! ");

 

General VC ++, (the code has been simplified, and necessary exceptions are not detected)

 // get dispid of "test" dispid; lpctstr szname = l "test"; window-> getidsofnames (iid_null, & ptname, 1, locale_user_default, & dispid); // get property of "test" _ variant_t vresult; dispparams dp = {null, null, 0, 0 }; window-> invoke (dispid, iid_null, locale_system_default, dispatch_propertyget, & DP, & vresult, null, null); // readyidispatchptr pmethod = vresult; // invoke "tes T "_ variant_t vparam = l" Hello world! "; DP. cargs = 1; DP. rgvarg = & vparam; pmethod-> invoke (null, iid_null, locale_system_default, dispatch_method, & DP, null); 

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.