How to call Microsoft Agent in C ++ Builder

Source: Internet
Author: User
Select a blog from sas_razor

After a full night, I read the materials of countless masters and finally showed Merlin on my desktop. There are a lot of information about this on the internet, but there are always a lot of errors when copying these programs. Below is a post in csdn: csdn-Expert Clinic-C ++ builder VCL component usage and Development Problems

Http://community.csdn.net/Expert/TopicView3.asp? Id = 4074506

Many friends provide valuable information, suchConstantine)AndF117p (Blue Fox ),However, copying these programs still has many errors and the MS Agent cannot be correctly called.

So I 'd like to share with you some tips on using Microsoft Agent in C ++ builder.

Step 1: to call the MS Agent, you must first install Microsoft Agent 2.0. Windows and XP have already installed this program. Generally, you do not need to install it unless you have uninstalled it.

Step 2: Open c ++ builder, choose component> Import ActiveX Control..., select Microsoft Agent control 2.0, and install. Then, the system prompts you to compile and confirm. After successful, the MS agent has been installed on the ActiveX control bar, the name is tagent. (here, I want to talk about how to uninstall tagent. Some people may use it because once the installation fails, you must uninstall it and reinstall it. Open dclusr. BPK in BCB, remove the two files related to agentobjects_ocx in the package-dclusr.bpk window, compile again, and repeat Step 2)

Step 3: Create a project and add the following code in form1. The code can be placed in form_create or where you need it:

Char TMP [100]; // used to save the Windows Installation Directory
Getwindowsdirectory (TMP, 100); // obtain the Windows Installation Directory
String tmppath = string (TMP) + "// msagent // chars // Merlin. ACS ";
// String (TMP) converts the char type to string, and stores the complete path of the file in tmppath.
BSTR agentname = BSTR ("Merlin"); // convert string type to wchar_t *
Variant agentpath = variant (tmppath); // convert the tmppath type to tagvariant

Agent1-> characters-> load (agentname, agentpath );
// Load the MS Agent character. The load format is load (wchar_t *, tagvariant)
Iagentctlcharacterex * Merlin = (iagentctlcharacterex *) agent1-> characters-> character (agentname );
Specify the character to the variable Merlin. you can name it yourself.

// The following are some basic tests. For more information about MS Agent operations, see the relevant documentation.
Merlin-> show (variant (0 ));
Merlin-> moveTo (100,100, variant (2 ));
Merlin-> play (widestring ("Search "));

// The above program has been compiled on C ++ Builder 6.0.

Summary: The most common error in MS Agent manipulation in BCB is Data Type Mismatch. BSTR () and variant () solve this problem well. When learning BCB, don't worry. I tried these two functions slowly. I also want to thank all users for providing widestring, c_bstr (), tvariant () and other functions.

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.