.


:




:

































 

 

 

 





HANDLE FindFirstChangeNotification (

LPCTSTR lpPathName, //

BOOL bWatchSubtree, //

DWORD dwNotifyFilter // );

INVALID_HANDLE_VALUE.

dwNotifyFilter , :

FILE_NOTIFY_CHANGE_FILE_NAME ;

FILE_NOTIFY_CHANGE_DIR_NAME ;

FILE_NOTIFY_CHANGE_ATTRIBUTES ;

FILE_NOTIFY_CHANGE_SIZE ;

, .

BOOL FindNextChangeNotification(

HANDLE hChangeHandle //

);

FindCloseChangeNotification, .

BOOL FindCloseChangeNotification(

HANDLE hChangeHandle //

);

 

1. , .

#include <windows.h>

#include <iostream>

#include <conio.h>

using namespace std;

int main()

{

char buf[256],buf1[256];

int iMenu;

char cMenu[200]=" :\n1 - \n2 - \n3 - \n4 - \n5 - / \n6 - \n7 - \n";

CharToOem(cMenu, cMenu);

while(1)

{

WIN32_FIND_DATA FindFileData;

HANDLE hFind;

LONG cFiles=1;

BOOL bFindMore = TRUE;

system("cls");

cout << cMenu; cin >> iMenu;

switch(iMenu)

{

system("cls");

case 1:

CharToOem(" \n ? ", buf); cout << buf; cin >> buf;

if(!CreateDirectory(buf,NULL))

{

cerr << "Create directory failed!" <<endl

<< "The last error code: " << GetLastError() <<endl;

cout << "Press any key to continue";

getch();

break;

}

else

cout << "directory created";

getch();

break;

case 2:

CharToOem(" \n ? ", buf); cout << buf; cin >> buf;

if ((hFind=FindFirstFile(buf,&FindFileData)) == INVALID_HANDLE_VALUE)

{

cerr << endl << "Find First File failed!" << endl

<< "The last error code: " << GetLastError() <<endl;

cout << "Press any key to continue";

getch();

break;

}

cout << endl << FindFileData.cFileName << endl;

while (bFindMore)

{

if(bFindMore = FindNextFile(hFind, &FindFileData))

{

cout << FindFileData.cFileName << endl;

cFiles++;

}

}

cout << endl << "The search is completed." << endl

<< cFiles << " files were found" << endl;

cout<<"\nPress any key to continue!";

getch();

break;

case 3:

CharToOem(" \n ?", buf); cout << buf;cin>>buf;

if(!RemoveDirectory(buf))

{

cerr << endl << "Remove Directory failed!" << endl

<< "The last error code: " << GetLastError() <<endl;

cout << "Press any key to continue";

getch();

break;

}

cout << "directory removed";

cout<<"\nPress any key to continue!";

getch();

break;

case 4:

CharToOem(" \n ?", buf); cout << buf; cin >> buf;

CharToOem(" ?", buf1); cout << buf1;cin >> buf1;

if(!MoveFile(buf,buf1))

{

cerr << endl << "Move Directory failed!" << endl

<< "The last error code: " << GetLastError() <<endl;

cout << "Press any key to continue";

getch();

break;

}

cout << "directory moved";

cout<<"\nPress any key to continue!";

getch();

break;

case 5:

CharToOem(" :\n", buf); cout << buf;

GetCurrentDirectory(sizeof(buf),buf);

cout << buf <<endl;

CharToOem(" ?(y/n) ", buf); cout << buf; cin >> buf;

if(*buf=='y')

{

CharToOem(" ! ", buf);cout << buf; cin >> buf;

if(!SetCurrentDirectory(buf))

{

cerr << endl << "Set Current failed!" << endl

<< "The last error code: " << GetLastError() <<endl;

}

else cout << "The current directory is set" << endl;

}

cout<<"\nPress any key to continue!";

getch();

break;

case 6:

CharToOem(" \n ?", buf); cout << buf; cin>>buf;

if ((hFind=FindFirstChangeNotification(buf,false, FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_DIR_NAME|FILE_NOTIFY_CHANGE_SIZE)) == INVALID_HANDLE_VALUE)

{

cerr << endl << "Find First Notification failed!" << endl

<< "The last error code: " << GetLastError() <<endl;

cout << "Press any key to continue";

getch();

break;

} else cout << "Watch.." << endl;

while (WaitForSingleObject(hFind,10000)!=WAIT_OBJECT_0) { }

cout << endl << "The watched directory has been changed." << endl;

bFindMore=false;

cout << "Find next change notification?(y/n)"; cin >>buf;

if(*buf='y') bFindMore=true;

while (bFindMore)

{

if(bFindMore = FindNextChangeNotification(hFind))

{

cout << "Watch.." << endl;

while (WaitForSingleObject(hFind, 10000)!= WAIT_OBJECT_0) {}

cout << endl << "The watched directory has been changed again." << endl;

cout << "Find next change notyfication?(y/n)"; cin >>buf;

if(*buf=='y') bFindMore=true; else bFindMore=false;;

}

else

{

cerr << endl << "Find Notification failed!" << endl

<< "The last error code: " << GetLastError() <<endl;

bFindMore=false;

}

}

FindCloseChangeNotification(hFind);

cout<<"\nPress any key to continue!";

getch();

break;

case 7: return 0;

}

}

return 0;

}

1. :

− ;

− ;

− ;

− ;

− ;

− .

2. , .

3. , .

 

1. ?

2. , ?

3. ?

4. : FindFirstFile .

5. : FindNextFile .

6. : FindClose .

7. GetFileAttributes ?

8. lhffd?

9. FindFirstFile ?

 

11

:

:

1. Win32 API, DLL.

2. , , .

, . , .

. , . , .

DLL (. Dynamic Link Library ) Microsoft Windows OS / 2. *. dll, *. ocx ( , ActiveX) *. drv ( ). DLL , PE- (Portable Executable) 32 -, 64- Windows, New-Executable (NE) 16- Windows. DLL , .

 

1.

DLL DllMain DLL . DllMain DLL , . :

BOOL WINAPI DllMain(

HINSTANCE hinstDLL, // DLL

DWORD fdwReason, // DllMain

LPVOID lpvReserved // Windows

);

 

, . Microsoft Visual C+ + :

1. DLL, , , .

2. .LIB, . .

3. .DLL, . , , , .DLL .

, - . , :

_declspec (dllexport)

DWORD MyFunction (...);

_declspec ,

MyFunction , .

.DLL .LIB. .LIB , .DLL .

_declspec (dllimport)

DWORD MyFunction (...);

, .. .exe , Project -->Setting Link Project_Options MyFunction.lib. , .DLL . .DLL , .

, , ( LoadLibrary) ( FreeLibrary). . ; . . : LoadLibrary, GetProcAddress FreeLibrary.

HINSTANCE LoadLibrary (LPCTSTR lpLibFileName);

( HINSTANCE, HANDLE) NULL . .DLL . LoadLibrary .. , DLL ( LoadLibrary), . DLL , LoadLibrary , , .

LoadLibraryEx , .

, , , . , , :

BOOL FreeLibrary (HINSTANCE hLibModule);

GetProcAddress.

FARPROC GetProcAddress (HMODULE module, LPCSTR lpProcName);

hModule, ( HINSTANCE HMODULE), , LoadLibrary GetModuleHandle, . lpProcName, Unicode, . NULL.

GetModuleFileName, , hModule. , ( . .dll) GetModuleHandle , , . .

1. , , DLL.

#include "stdafx.h"

#include <iostream>

using namespace std;

 

extern "C++" __declspec(dllexport) void LetterList()

{

cout << "This function was called from LetterList() " << endl;

}

extern "C++" __declspec(dllexport) int PutInt(int param)

{

return param;

}

 

2. .

// myFirstDll.dll

#include <windows.h>

int WINAPI DllMain(HINSTANCE hInstance,

DWORD fdReason,

PVOID pvReserved)

{

return TRUE;

}

extern "C" __declspec(dllexport) int MyFunction(char *str)

{

MessageBox(NULL, str,"Function from DLL",MB_OK);

return 1;

}





:


: 2016-11-24; !; : 728 |


:

:

, .
==> ...

1853 - | 1652 -


© 2015-2024 lektsii.org - -

: 0.056 .