I wrote a MSComm serial communication program and couldn't run it on a machine without VC installed. You need to manually register the control. For more information, see http://www.cnblogs.com/yrh284269/archive/2007/06/19/789213.html. However, manual registration can be completed by writing a BAT file. First, create a folder and set MSComm under Windows/system32. copy the SRG, mscomm32.ocx, and mscomm32.dep files to the folder, view the content of mscomm32.dep, add regedit4 lines to the top, save it as 1.reg, and put it in the folder.
Create a text in the folder and write
@ Echo off
Copy. \ mscomm32.ocx % SystemRoot % \ system32
Copy. \ mscomm32.dep % SystemRoot % \ system32
Copy. \ MSComm. SRG % SystemRoot % \ system32
Regsvr32/S % SystemRoot % \ system32 \ mscomm32.ocx
Regedit/s 1.reg
Save and change the suffix to bat. Click Run to complete registration.
There is another Win32 application method. I also want to learn it. However, it is easy and convenient to use the BAT file.
Http://www.wangchao.net.cn/bbsdetail_72535.html
# Include <windows. h>
# Include <stdio. h>
# Include <string. h>
Void cpfile (char file );
Void regsted ();
Void regocx ();
Void cpfile (char file [], char tarpath []) // copy the three files to the system directory.
{
Char tempsys [100];
Char * R;
Char * t;
R = tarpath;
T = tempsys;
Strcpy (T, R );
Char path [256];
Char * P;
Char * q;
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 );
P = strchr (tempsys, '\ 0 ');
* P = '\\';
P ++;
Q = file;
Strcpy (p, q );
Copyfile (path, tempsys, false );
}
Void regsted () // write relevant information to the Registry
{
Hkey;
DWORD dwdip;
Lpbyte owner_get = new byte [80];
DWORD type_1 = REG_SZ;
DWORD cbdata_1 = 80;
Long exist = regqueryvalueex (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, reg_option_volatile, 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, LPB, Leng );
}
}
Void regocx () // call a new process Register Components
{
Char CommandLine [256];
Char windowsdir [256];
Char lastcommandline [257];
Process_information PI;
Startupinfo Si = {sizeof (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 a sub-process
Bool ret = CreateProcess (windowsdir, lastcommandline, null, null, false, 0, null, null, & Si, & PI );
If (RET)
{
Closehandle (PI. hthread );
Closehandle (PI. hprocess );
}
}
Int apientry winmain (hinstance,
Hinstance hprevinstance,
Lpstr lpcmdline,
Int ncmdshow)
{
Char sys [100];
Char file1 [20] = "mscomm32.ocx ";
Char file2 [20] = "mscomm32.dep ";
Char file3 [20] = "MSComm. SRG ";
Getsystemdirectory (sys, 100 );
Cpfile (file1, sys );
Cpfile (file2, sys );
Cpfile (file3, sys );
Regocx ();
Regsted ();
Return 0;
}