MSComm控件注册
写了个MSComm的串口通信程序,在没有安装Vc的机器上没有办法运行。需要手动注册控件。从http://www.cnblogs.com/yrh2847189/archive/2007/06/19/789213.html看到的方法。不过手动注册可以写成bat文件来完成。首先是建一个文件夹,将Windows/system32下的Mscomm.srg, Mscomm32.ocx,Mscomm32.dep文件拷到文件夹中,然后查看 Mscomm32.dep的内容,在顶部加入REGEDIT4一行,另存为1.reg,也放在该文件夹中。
然后在文件夹中建一个文本,写入
@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
保存,更改后缀为bat。点击运行,就可以完成注册。
另有一个Win32 Application的方法,也学习一下,不过感觉还是bat文件跟简单方便,呵呵。
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[]) //将三个文件拷贝到系统目录
{
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() //将相关信息写入注册表
{
HKEY 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\\4250E830-6AC2-11cf-8ADB-00AA00C00905", NULL, &type_1, owner_Get, &cbData_1);
if(exist!=ERROR_SUCCESS)
{
long ret = RegCreateKeyEx(HKEY_CLASSES_ROOT,"Licenses\\4250E830-6AC2-11cf-8ADB-00AA00C00905",0l,NULL,REG_OPTION_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,&dwDip);
DWORD leng=37;
char key[37]="kjljvjjjoquqmjjjvpqqkqmqykypoqjquoun";
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()//调用新进程注册组件
{
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]=' ';
// 启动regsvr32.exe作为子进程
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,
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;
}
然后在文件夹中建一个文本,写入
@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
保存,更改后缀为bat。点击运行,就可以完成注册。
另有一个Win32 Application的方法,也学习一下,不过感觉还是bat文件跟简单方便,呵呵。
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[]) //将三个文件拷贝到系统目录
{
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() //将相关信息写入注册表
{
HKEY 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\\4250E830-6AC2-11cf-8ADB-00AA00C00905", NULL, &type_1, owner_Get, &cbData_1);
if(exist!=ERROR_SUCCESS)
{
long ret = RegCreateKeyEx(HKEY_CLASSES_ROOT,"Licenses\\4250E830-6AC2-11cf-8ADB-00AA00C00905",0l,NULL,REG_OPTION_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,&dwDip);
DWORD leng=37;
char key[37]="kjljvjjjoquqmjjjvpqqkqmqykypoqjquoun";
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()//调用新进程
{
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]=' ';
// 启动regsvr32.exe作为子进程
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,
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;
}