能力值:
( LV9,RANK:380 )
2 楼
没人指导吗?
我写了一些,调式都头晕了
.386
.model flat,stdcall
option casemap:none
include windows.inc
include kernel32.inc
include user32.inc
includelib kernel32.lib
includelib user32.lib
.data
FileName db "C:\test.txt",0
lpBuffer db '心魔原来是酒魔',0
sz1 db '成功找到!',0
x_str db 256 dup(0)
szjie db '结果是: %d',0
x_strlen DWORD 20
hSize dd ?
.code
start:
_ifile proc
local @hFile,@dwFileSize,@hMapFile,@lpMemory
invoke CreateFile,addr FileName,GENERIC_READ,\
FILE_SHARE_READ or FILE_SHARE_WRITE,NULL,\
OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,NULL
.if eax != INVALID_HANDLE_VALUE
mov @hFile,eax
invoke GetFileSize,eax,NULL
mov @dwFileSize,eax
.if eax
invoke CreateFileMapping,@hFile,\
NULL,PAGE_READONLY,0,0,NULL
.if eax
mov @hMapFile,eax
invoke MapViewOfFile,eax,\
FILE_MAP_READ,0,0,0
.if eax
mov @lpMemory,eax
invoke lstrlen,addr FileName
mov hSize,eax
invoke ReadFile ,@lpMemory, addr x_str ,hSize, addr x_strlen , NULL
invoke lstrcmp , addr lpBuffer,addr x_str
.if eax != NULL
;这里开始处理找到的
mov eax , FALSE
ret
.endif
invoke UnmapViewOfFile,@lpMemory
;********************************************************************
.endif
invoke CloseHandle,@hMapFile
.endif
invoke CloseHandle,@hFile
.endif
.endif
mov eax , TRUE
ret
_ifile endp
call _ifile
invoke ExitProcess,NULL
end start
能力值:
( LV9,RANK:970 )
3 楼
Delphi的源码要不要?
能力值:
( LV9,RANK:380 )
4 楼
发来看看...参考参考
能力值:
( LV2,RANK:10 )
5 楼
看不懂,既然MapViewOfFile了,为啥还要ReadFile ?
能力值:
( LV9,RANK:970 )
6 楼
看看这个是不是你要的效果
先打开test.txt文本
再点button1
你要的那句就复制出来了:)
上传的附件:
能力值:
( LV9,RANK:250 )
7 楼
#include <windows.h>
int StrEqual(const char* deststr, const char *srcstr);
int FindText(LPVOID lpAddr, int memsize, LPCSTR lpKeyWord);
int FindSpecText(LPCSTR lpFileName, LPCSTR lpKeyWord);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
if(0 <= FindSpecText("test.txt", "一个简单的字符串查找程序"))
MessageBox(NULL, "Find it", "Test", 0);
return 0;
}
int StrEqual(const char* deststr, const char *srcstr)
{
int len = strlen(srcstr);
for(int i = 0; i < len; i++)
{
if(deststr[i] != srcstr[i])
return -1;
}
return 0;
}
int FindText(LPVOID lpAddr, int memsize, LPCSTR lpKeyWord)
{
if(NULL == lpAddr || NULL == lpKeyWord || 0 == memsize)
return -1;
int len = strlen(lpKeyWord);
for(int i = 0; i < memsize - len; i++)
{
if(0 == StrEqual((LPCSTR)lpAddr + i, lpKeyWord)) return i;
}
return -1;
}
int FindSpecText(LPCSTR lpFileName, LPCSTR lpKeyWord)
{
int iret = 0;
HANDLE hFile = INVALID_HANDLE_VALUE;
HANDLE hMapFile = NULL;
LPVOID lpMap = NULL;
__try
{
hFile = CreateFile(lpFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(INVALID_HANDLE_VALUE == hFile) { iret = -1; __leave; }
hMapFile = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
if(NULL == hMapFile) { iret = -1; __leave; }
lpMap = MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0);
if(NULL == lpMap) { iret = -1; __leave; }
iret = FindText(lpMap, GetFileSize(hFile, NULL), lpKeyWord);
}
__finally
{
if(lpMap != NULL)
UnmapViewOfFile(lpMap);
if(hMapFile != NULL)
CloseHandle(hMapFile);
if(hFile != INVALID_HANDLE_VALUE)
CloseHandle(hFile);
}
return iret;
}
能力值:
( LV9,RANK:380 )
8 楼
OK,已经搞定........我已经可以实现了,嘿嘿