Advertisement
rnort

SPO-5-WIN-LIB

Dec 30th, 2012
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. // dilib.cpp: определяет экспортированные функции для приложения DLL.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <stdio.h>
  6. extern "C"
  7. {
  8. __declspec(dllexport) int ASyncRead(HANDLE hFile, char* FileContent, int size, DWORD offset)
  9. {
  10.     DWORD nBytesRead;
  11.     OVERLAPPED fOverLapped;
  12.     ZeroMemory(&fOverLapped, sizeof(OVERLAPPED));
  13.     fOverLapped.hEvent = CreateEvent(NULL, false, false, NULL);
  14.     fOverLapped.Offset = offset;
  15.  
  16.     ReadFile(hFile, FileContent, 1024, NULL, &fOverLapped);
  17.     WaitForSingleObject(fOverLapped.hEvent, INFINITE);
  18.     GetOverlappedResult(hFile, &fOverLapped, &nBytesRead, false);
  19.     return nBytesRead;
  20. }
  21.  
  22. __declspec(dllexport) void ASyncWrite(HANDLE hFile, char* FileContent, DWORD *offset)
  23. {
  24.         char buf[15];
  25.         DWORD nBytesWritten;
  26.         OVERLAPPED fOverLapped;
  27.         ZeroMemory(&fOverLapped, sizeof(OVERLAPPED));
  28.         fOverLapped.Offset = *offset;
  29.         fOverLapped.hEvent = CreateEvent(NULL, false, false, NULL);
  30.        
  31.         WriteFile(hFile, FileContent, strlen(FileContent), NULL, &fOverLapped);
  32.         WaitForSingleObject(fOverLapped.hEvent, INFINITE);
  33.         *offset += strlen(FileContent);
  34.  
  35.         CloseHandle(fOverLapped.hEvent);
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement