.386 .model flat,stdcall option casemap:none
include windows.inc include kernel32.inc include user32.inc includelib kernel32.lib includelib user32.lib include shlwapi.inc ;PathRemoveFileSpec 用 includelib shlwapi.lib
.data hInstance dd ? szProfileName db MAX_PATH dup (?) szFileName db '/test.ini',0 szAppName db 'sec',0 szKeyName db 'Key',0 szKeyValue db 'value',0 szKeyName2 db 'hello',0 szKeyValue2 db 'good',0 szAppNameInt db 'INTS',0 szKeyValueInt db 'int',0 szBufInt db '%d',0 szBuffer db MAX_PATH DUP (?) .code start: invoke GetModuleHandle,NULL mov hInstance,eax invoke GetCurrentDirectory,MAX_PATH,addr szProfileName ;获取路径方法一 mov edi,offset szProfileName invoke lstrlen,edi mov ecx,offset szFileName ;ini文件名 .if byte ptr [edi+eax-1] == '/' ;当前路径的最后一个字符是 / 吗 inc ecx ;是,则跳过ini文件名的/,防止生成两个// .endif invoke lstrcat,edi,ecx ;连接组成完成路径名 ;注意这种方法 invoke MessageBox,NULL,edi,NULL,MB_OK invoke GetModuleFileName,NULL,addr szProfileName,MAX_PATH ;获取路径方法二 invoke PathRemoveFileSpec,addr szProfileName mov edi,offset szProfileName invoke lstrlen,edi mov ecx,offset szFileName .if byte ptr [edi+eax-1] == '/' inc ecx .endif invoke lstrcat,edi,ecx invoke MessageBox,NULL,edi,NULL,MB_OK invoke WritePrivateProfileString,addr szAppName,addr szKeyName,addr szKeyValue,edi invoke WritePrivateProfileString,addr szAppName,addr szKeyName2,addr szKeyValue2,edi invoke GetPrivateProfileString,addr szAppName,addr szKeyName2,NULL,addr szBuffer,MAX_PATH,EDI invoke MessageBox,NULL,addr szBuffer,NULL,MB_OK invoke GetCurrentProcessId ;写数值型 invoke wsprintf,addr szBuffer,addr szBufInt,eax ;转换为字符 invoke WritePrivateProfileString,addr szAppNameInt,addr szKeyValueInt,addr szBuffer,edi invoke GetPrivateProfileInt,addr szAppNameInt,addr szKeyValueInt,NULL,edi ;读数值型 invoke wsprintf,addr szBuffer,addr szBufInt,eax ;转化为字符 invoke MessageBox,NULL,addr szBuffer,NULL,MB_OK invoke ExitProcess,NULL end start
