How to register the MSComm control during installation and deployment

Source: Internet
Author: User

It is very convenient to use MSComm, but you have to pay the price, that is, when you install the MSComm control on a PC without a registered MSComm control, you have to register this control, most of the information on the Internet is manually registered with the MSComm control, but it is impossible for every customer to manually perform the operation. Therefore, this method is not feasible at the time of release, A better way is to enable the installer to automatically register MSComm during installation.

Note: For how to manually register MSComm controls, refer to: http://blog.csdn.net/flydream0/article/details/8002012

This article is based on this starting point and uses vs2010 to achieve this goal.

Overall idea: use custom action editor in vs2010 to achieve this goal, specifically write a program to register MSComm, and then execute it in the installer. I will not elaborate on how to use vs2010 to build a installation and deployment project. Here I will mainly discuss the specific program content for registration.

Registemscomm. cpp:

// Registermscomm. CPP: defines the entry point for the console application. // # include "stdafx. H "# include <stdio. h> # include <string. h> # include <windows. h> // copy the three files to the system directory void copefile (char file [], char tarpath []) {char tempsys [100]; // char * R; // char * t; // R = tarpath; // T = tempsys; // strcpy (T, R); char path [256]; char * P; char * q; // get the file path under the current program directory to getmodulefilename (getmodulehandle (null), path, sizeof (Path ); P = path; while (strchr (p, '\') {P = strchr (p, '\'); P ++ ;} * P = '\ 0'; P = strchr (path,' \ 0'); q = file; strcpy (p, q ); // obtain the full path information of the target file strcpy (tempsys, tarpath); P = strchr (tempsys, '\ 0'); * P =' \ '; P ++; Q = file; strcpy (p, q); // copy the copyfile (path, tempsys, false);} // write the relevant information to the Registry void regsted () {hkey; DWORD dwdip; byte bytearray [80]; lpbyte owner_get = bytearray; DWORD type_1 = REG_SZ; DWORD cbdata_1 = 80; long exist = regqueryva Lueex (hkey_classes_root, "licenses \ javase830-6ac2-11cf-8adb-00aa00c00905", null, & type_1, owner_get, & cbdata_1); If (exist! = Error_success) {long ret = regcreatekeyex (hkey_classes_root, "licenses \ keys", 0l, null, delimiter, key_all_access, null, & hkey, & dwdip); DWORD Leng = 37; char key [37] = "kjljvjjjoquqmjjvpqqkqmqykypoqjquoun";/* lpbyte LPB = new byte (37); For (INT I = 0; I <37; I ++) LPB [I] = Key [I]; */long ret2 = regsetvalueex (hkey, null, null, REG_SZ, (lpbyte) & Key [0]/* LPB */, leng) ;}}// call the void regocx () {char CommandLine [256]; char windowsdir [256]; char lastcommandline [257]; process_information PI; startupinfo Si; char ocxfile [50] = "\ mscomm32.ocx"; char regfile [50] = "\ regsvr32.exe"; char * P, * q; getsystemdirectory (windowsdir, 256); P = CommandLine; q = windowsdir; strcpy (p, q); P = strchr (CommandLine, '\ 0'); q = ocxfile; strcpy (p, q); P = strchr (windowsdir, '\ 0'); q = regfile; strcpy (p, q); P = CommandLine; q = & lastcommandline [1]; strcpy (Q, P); lastcommandline [0] = ''; // start regsvr32.exe as the sub-process bool ret = CreateProcess (windowsdir, lastcommandline, null, null, false, 0, null, null, & Si, & PI); If (RET) {closehandle (Pi. hthread); closehandle (Pi. hprocess) ;}} int _ tmain (INT argc, _ tchar * argv []) {char sys [100]; char file1 [20] = "mscomm32.ocx "; char file2 [20] = "mscomm32.dep"; char file3 [20] = "MSComm. SRG "; // get the Win32 path getsystemdirectory (sys, 100); // copy the file copefile (file1, sys); copefile (file2, sys); copefile (file3, sys ); // register ocxregocx (); // modify the Registry regsted (); Return 0 ;}

The Code consists of three steps:

Step 1: copy the file to the Win32 Directory.

Step 2: register the MSComm component.

Step 2: Modify the registry.

Note: This code can run normally in debug, but in release, the Code cannot be compiled by default, and the external symbols regqueryvalueex, regcreatekeyex, and regsetvalueex cannot be found.

Through error locating, the release location is under release and the corresponding lib library is missing. Therefore, in the project properties-> linker-> input-> addtional dependencies, change the content to be consistent with the corresponding content under debug, that is:

Kernel32.lib; user32.lib; gdi32.lib; winspool. Lib; comdlg32.lib; runtime; shell32.lib; ole32.lib; oleaut32.lib; UUID. Lib; odbc32.lib; runtime; % (runtime)

In this way, you can compile and run normally.

Complete!

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.