Use the SDK to play with ActiveX

Source: Internet
Author: User
Tags include ole

Call ActiveX control? Well, it's really not an easy thing to do: with a variety of packaging sophisticated framework (MFC, VCL, etc.), the final product of the volume of EXE will inevitably be large; with the SDK although it can effectively reduce the volume, but often do not know--in short, this seems to be a fish and bear's paw can not be a pity. Fortunately, "not easy" does not mean "impossible", Li Ma in this article to introduce to you, is a "play" ActiveX method, this method includes the call from the ActiveX control to ActiveX control event handling all the necessary details. Of course, the title of the "SDK" is not a pure SDK, but with the help of ATL OLE support, after all, using the SDK to implement the OLE container is too cumbersome.

Before I begin the text, I would also like to explain the readership that this article faces. First, you have to understand how the SDK is programmed and how the COM component is invoked, because the vast majority of the sample code in this article is relevant and I will not explain it, and secondly, you may not understand ATL, Because the use of ATL in this article is limited to ActiveX OLE containers, I just give a brief description in the right place; again, you can not understand COM connection point knowledge, I will give a detailed introduction in the article.

So gossip is needless, let's get started.

Preparatory work

Now let's do something outside the code, and follow these steps to build our project:

1. Open Visual C + + and create a new Win32 application (my name is ActiveX).

2. Create a new resource script (resource scripting) in which you add a dialog box (my name is Idd_main_dlg).

3. Right-click on the dialog box and select Insert ActiveX control ... (as shown below). In this article, I take Microsoft Agent control as an example, so in the list that follows, select Microsoft Agent Control 2.0.

4. After the completion of the dialog box as shown below.

Skeleton Code

Now it's time to write code. Create a C + + source file (c + +), where you enter the following skeleton of the program:

#include <atlbase.h>
CComModule _Module;
#include <atlwin.h>
#import "C:\WINNT\msagent\agentctl.dll"
using namespace AgentObjects;
#include "resource.h"
int WINAPI _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd )
{
   _Module.Init( NULL, hInstance );
   _Module.Term();
   return 0;
}

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.