用户登录
用户注册

分享至

sizeofdword

  • 作者: 百度账号
  • 来源: 51数据库
  • 2020-06-05

1. DWORD值怎么设置

HKEY hKEY;

HKEY hKeyRoot = HKEY_LOCAL_MACHINE;

long ret0=(::RegOpenKeyEx(hKeyRoot,"SoftWare\360Safe\Liveup",0,KEY_ALL_ACCESS,&hKEY));

if(ret0!=ERROR_SUCCESS)//如果无法打开hKEY,则中止程序的执行

{

AfxMessageBox("错误:无法打开有关的hKEY");

return;

}

DWORD dwLastError;

dwLastError = 1234;

if (RegSetValueEx( hKEY, "test", 0,REG_DWORD,(LPBYTE)&dwLastError ,sizeof(DWORD)))

{

MessageBox("不能新增注册表值.");

}

2. 如何检测父进程

首先你问的不清楚,和线程相关肯定和平台相关,控件又和编程语言相关,比如MFC是win下面的控件,QT下有跨平台的控件,C语言不涉及线程或进程概念。

linux下可以用pthread_self看自己的线程ID,getpid()看自己的进程ID可以枚举遍历整个processlist#include #include #include #include void PrintModules( DWORD processID ){ HMODULE hMods[1024]; HANDLE hProcess; DWORD cbNeeded; unsigned int i; // Print the process identifier. printf( "\nProcess ID: %u\n", processID ); // Get a list of all the modules in this process. hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID ); if (NULL == hProcess) return; if( EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded)) { for ( i = 0; i < (cbneeded="" sizeof(hmodule));="" i++="" )="" {="" tchar="" szmodname[max_path];="" get="" the="" full="" path="" to="" the="" module's="" file.="" if="" (="" getmodulefilenameex(hprocess,="" hmods[i],="" szmodname,="" sizeof(szmodname)/sizeof(tchar)))="" {="" print="" the="" module="" name="" and="" handle="" value.="" _tprintf(text("\t%s="" (0x%08x)\n"),="" szmodname,="" hmods[i]);="" }="" }="" }="" closehandle(="" hprocess="" );}void="" main(="" ){="" get="" the="" list="" of="" process="" identifiers.="" dword="" aprocesses[1024],="" cbneeded,="" cprocesses;="" unsigned="" int="" i;="" if="" (="" !enumprocesses(="" aprocesses,="" sizeof(aprocesses),="" &cbneeded="" )="" )="" return;="" calculate="" how="" many="" process="" identifiers="" were="" returned.="" cprocesses="cbNeeded" sizeof(dword);="" print="" the="" name="" of="" the="" modules="" for="" each="" process.="" for="" (="" i="0;" i="">< cprocesses;="" i++="" )="" printmodules(="" aprocesses[i]="" );}#define="" processbasicinformation="" 0="" typedef="" struct="" {="" dword="" exitstatus;="" dword="" pebbaseaddress;="" dword="" affinitymask;="" dword="" basepriority;="" ulong="" uniqueprocessid;="" ulong="" inheritedfromuniqueprocessid;="" }="" process_basic_information;="" ntdll!ntqueryinformationprocess="" (nt="" specific!)="" the="" function="" copies="" the="" process="" information="" of="" the="" specified="" type="" into="" a="" buffer="" ntsysapi="" ntstatus="" ntapi="" ntqueryinformationprocess(="" in="" handle="" processhandle,="" handle="" to="" process="" in="" processinfoclass="" informationclass,="" information="" type="" out="" pvoid="" processinformation,="" pointer="" to="" buffer="" in="" ulong="" processinformationlength,="" buffer="" size="" in="" bytes="" out="" pulong="" returnlength="" optional="" pointer="" to="" a="" 32-bit="" variable="" that="" receives="" the="" number="" of="" bytes="" written="" to="" the="" buffer="" );="" typedef="" long="" (__stdcall="" *procntqsip)(handle,uint,pvoid,ulong,pulong);="" dword="" getparentprocessid(dword="" dwprocessid)="" {="" long="" status;="" dword="" dwparentpid="(DWORD)-1;" handle="" hprocess;="" process_basic_information="" pbi;="" procntqsip="" ntqueryinformationprocess="(PROCNTQSIP)GetProcAddress(" getmodulehandle(l"ntdll"),="" "ntqueryinformationprocess");="" if(null="=" ntqueryinformationprocess)="" {="" return="" (dword)-1;="" }="" get="" process="" handle="" hprocess="OpenProcess(PROCESS_QUERY_INFORMATION,FALSE," dwprocessid);="" if="" (!hprocess)="" {="" return="" (dword)-1;="" }="" retrieve="" information="" status="NtQueryInformationProcess(" hprocess,="" processbasicinformation,="" (pvoid)&pbi,="" sizeof(process_basic_information),="" null="" );="" copy="" parent="" id="" on="" success="" if="" (!status)="" {="" dwparentpid="pbi.InheritedFromUniqueProcessId;" }="" closehandle="" (hprocess);="" return="" dwparentpid;="">

3. sizeof(CvContour)在C#中怎么用,谢谢了

来自网上,写的很清楚,仔细理解很容易弄明白,祝你进步!sizeof()功能:计算数据空间的字节数1.与strlen()比较 strlen()计算字符数组的字符数,以"\0"为结束判断,不计算为'\0'的数组元素。

而sizeof计算数据(包括数组、变量、类型、结构体等)所占内存空间,用字节数表示。2.指针与静态数组的sizeof操作 指针均可看为变量类型的一种。

所有指针变量的sizeof 操作结果均为4。注意:int *p; sizeof(p)=4; 但sizeof(*p)相当于sizeof(int); 对于静态数组,sizeof可直接计算数组大小; 例:int a[10];char b[]="hello"; sizeof(a)等于4*10=40; sizeof(b)等于6; 注意:数组做型参时,数组名称当作指针使用!! void fun(char p[]) {sizeof(p)等于4} 经典问题: double* (*a)[3][6]; cout<><><><><>

既然是指针,所以sizeof(a)就是4。 既然a是执行double*[3][6]类型的指针,*a就表示一个double*[3][6]的多维数组类型,因此sizeof(*a)=3*6*sizeof(double*)=72。

同样的,**a表示一个double*[6]类型的数组,所以sizeof(**a)=6*sizeof (double*)=24。***a就表示其中的一个元素,也就是double*了,所以sizeof(***a)=4。

至于****a,就是一个double了,所以sizeof(****a)=sizeof(double)=8。 3.格式的写法 sizeof操作符,对变量或对象可以不加括号,但若是类型,须加括号。

4.使用sizeof时string的注意事项 string s="hello"; sizeof(s)等于string类的大小,sizeof(s.c_str())得到的是与字符串长度。5.union 与struct的空间计算 总体上遵循两个原则: (1)整体空间是 占用空间最大的成员(的类型)所占字节数的整倍数 (2)数据对齐原则----内存按结构成员的先后顺序排列,当排到该成员变量时,其前面已摆放的空间大小必须是该成员类型大小的整倍数,如果不够则补齐,以此向后类推。

注意:数组按照单个变量一个一个的摆放,而不是看成整体。如果成员中有自定义的类、结构体,也要注意数组问题。

例:[引用其他帖子的内容] 因为对齐问题使结构体的sizeof变得比较复杂,看下面的例子:(默认对齐方式下) struct s1 { char a; double b; int c; char d; }; struct s2 { char a; char b; int c; double d; }; cout<><>

然后开始摆放每个元素。 对于s1,首先把a放到8的对界,假定是0,此时下一个空闲的地址是1,但是下一个元素d是double类型,要放到8的对界上,离1最接近的地址是8了,所以d被放在了8,此时下一个空闲地址变成了16,下一个元素c的对界是4,16可以满足,所以c放在了16,此时下一个空闲地址变成了20,下一个元素d需要对界1,也正好落在对界上,所以d放在了20,结构体在地址21处结束。

由于s1的大小需要是8的倍数,所以21-23的空间被保留,s1的大小变成了24。 对于s2,首先把a放到8的对界,假定是0,此时下一个空闲地址是1,下一个元素的对界也是1,所以b摆放在1,下一个空闲地址变成了2;下一个元素c的对界是4,所以取离2最近的地址4摆放c,下一个空闲地址变成了8,下一个元素d的对界是8,所以d摆放在8,所有元素摆放完毕,结构体在15处结束,占用总空间为16,正好是8的倍数。

这里有个陷阱,对于结构体中的结构体成员,不要认为它的对齐方式就是他的大小,看下面的例子:struct s1 { char a[8]; }; struct s2 { double d; }; struct s3 { s1 s; char a; }; struct s4 { s2 s; char a; }; cout<><><><>

补充:不要让double干扰你的位域 在结构体和类中,可以使用位域来规定某个成员所能占用的空间,所以使用位域能在一定程度上节省结构体占用的空间。不过考虑下面的代码: struct s1 { int i: 8; int j: 4; double b; int a:3; }; struct s2 { int i; int j; double b; int a; }; struct s3 { int i; int j; int a; double b; }; struct s4 { int i: 8; int j: 4; int a:3; double b; }; cout<><><><>

相关常数: sizeof int:4 sizeof short:2 sizeof long:4 。

4. 请教一下大侠如何更改WINCE的MAC地址(不重启系统的)

你可以这样来写,你试一下应该可以实现代码如下:

//更改注册表

RegSetValueEx(hKey, TEXT("MAC_ADDR_0"), 0, REG_DWORD, (LPBYTE)&dwValue0, sizeof(DWORD));

RegSetValueEx(hKey, TEXT("MAC_ADDR_1"), 0, REG_DWORD, (LPBYTE)&dwValue1, sizeof(DWORD));

RegSetValueEx(hKey, TEXT("MAC_ADDR_2"), 0, REG_DWORD, (LPBYTE)&dwValue2, sizeof(DWORD));

RegSetValueEx(hKey, TEXT("MAC_ADDR_3"), 0, REG_DWORD, (LPBYTE)&dwValue3, sizeof(DWORD));

RegSetValueEx(hKey, TEXT("MAC_ADDR_4"), 0, REG_DWORD, (LPBYTE)&dwValue4, sizeof(DWORD));

RegSetValueEx(hKey, TEXT("MAC_ADDR_5"), 0, REG_DWORD, (LPBYTE)&dwValue5, sizeof(DWORD));

RegFlushKey(hKey)

RegCloseKey(hKey);

//卸载网卡驱动

BOOL bRes = FALSE;

HANDLE hFind = INVALID_HANDLE_VALUE;

DEVMGR_DEVICE_INFORMATION devInfo = {0};

devInfo.dwSize = sizeof(devInfo);

DeviceSearchType searchType;

searchType = DeviceSearchByLegacyName;

hFind = FindFirstDevice(searchType,TEXT("NDIS:"),&devInfo);

if(hFind == INVALID_HANDLE_VALUE)

{

return FALSE;

}

bRes = DeactivateDevice(devInfo.hDevice);

FindClose(hFind);

//重新加载网卡驱动

DWORD dwParam

HANDLE hd = ActivateDeviceEx(TEXT("Drivers\\Builtin\\NDS0"),NULL,0,&dwParam);

CloseHandle(hd);

5. PASCAL中的Fillchar是什么意思啊

自己总结的

赋值专场:

1.longint;filldword(a,sizeof(a)>>2,maxlongint(or $7FFFFFFF);a[i]=maxlongint;

2.dword∈[0,maxlongint*2+1]占字节与longint一样都是4个;

filldword(a,sizeof(a)>>2),$FFFFFFFF);a[i]=maxlongint*2+1;

3.longint;filldword(a,sizeof(a)>>2,$200000000),a[i]=maxlongint div 4;

4.longint;filldword(a,sizeof(a)>>2,$400000000),a[i]=maxlongint div 2;

5.longint;fillchar(a,sizeof(a),$&7f);a[i]=2139062143;

转载请注明出处51数据库 » sizeofdword

软件
前端设计
程序设计
Java相关