硬汉嵌入式论坛

 找回密码
 立即注册
查看: 3039|回复: 0
收起左侧

[AppWizard] AppWizard的文件系统部分接口函数实现模板

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106989
QQ
发表于 2021-2-18 08:58:00 | 显示全部楼层 |阅读模式


接口实现:

  1. /*********************************************************************
  2. *                SEGGER MICROCONTROLLER SYSTEME GmbH                 *
  3. *        Solutions for real time microcontroller applications        *
  4. **********************************************************************
  5. *                                                                    *
  6. *        (c) 1996 - 2004  SEGGER Microcontroller Systeme GmbH        *
  7. *                                                                    *
  8. *        Internet: www.segger.com    Support:  support@segger.com    *
  9. *                                                                    *
  10. **********************************************************************

  11. ***** emWin - Graphical user interface for embedded applications *****
  12. emWin is protected by international copyright laws.   Knowledge of the
  13. source code may not be used to write a similar product.  This file may
  14. only be used in accordance with a license and should not be re-
  15. distributed in any way. We appreciate your understanding and fairness.
  16. ----------------------------------------------------------------------
  17. File        : APPW_X_Win32.c
  18. Purpose     : Windows file system access
  19. ---------------------------END-OF-HEADER------------------------------
  20. */

  21. #if defined(WIN32)

  22. #include <Windows.h>

  23. #include "AppWizard.h"

  24. /*********************************************************************
  25. *
  26. *         Static data
  27. *
  28. **********************************************************************
  29. */
  30. /*********************************************************************
  31. *
  32. *       _Open
  33. */
  34. static void * _Open(const char * pFilename) {
  35.   HANDLE hFile;

  36.   //
  37.   // Open file
  38.   //
  39.   hFile = CreateFile(pFilename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  40.   if (hFile != INVALID_HANDLE_VALUE) {
  41.     return (void *)hFile;
  42.   }
  43.   return (void *)NULL;
  44. }

  45. /*********************************************************************
  46. *
  47. *       _Seek
  48. */
  49. static int _Seek(const void * p, U32 Off) {
  50.   HANDLE   hFile;
  51.   
  52.   hFile  = (HANDLE)p;
  53.   //
  54.   // Set file pointer to the required position
  55.   //
  56.   if (SetFilePointer(hFile, Off, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) {
  57.     return 1;
  58.   }
  59.   return 0;
  60. }

  61. /*********************************************************************
  62. *
  63. *       _Read
  64. */
  65. static U32 _Read(const void * p, void * pData, U32 NumBytes) {
  66.   HANDLE   hFile;
  67.   DWORD    NumBytesRead;
  68.   
  69.   hFile  = (HANDLE)p;
  70.   //
  71.   // Read data into buffer
  72.   //
  73.   ReadFile(hFile, pData, NumBytes, &NumBytesRead, NULL);
  74.   //
  75.   // Return number of available bytes
  76.   //
  77.   return NumBytesRead;
  78. }

  79. /*********************************************************************
  80. *
  81. *       _Close
  82. */
  83. static void _Close(const void * p) {
  84.   HANDLE hFile;

  85.   hFile = (HANDLE)p;
  86.   CloseHandle(hFile);
  87. }

  88. /*********************************************************************
  89. *
  90. *       _Size
  91. */
  92. static U32 _Size(const void * p) {
  93.   U32 FileSize;
  94.   HANDLE hFile;

  95.   hFile = (HANDLE)p;
  96.   FileSize = GetFileSize(hFile, NULL);
  97.   return FileSize;
  98. }

  99. /*********************************************************************
  100. *
  101. *       _FileAccess
  102. */
  103. static APPW_X_FILEACCESS _FileAccess = {
  104.   _Open,
  105.   _Seek,
  106.   _Read,
  107.   _Close,
  108.   _Size,
  109. };

  110. /*********************************************************************
  111. *
  112. *       Public code
  113. *
  114. **********************************************************************
  115. */
  116. /*********************************************************************
  117. *
  118. *       APPW_X_FS_Init
  119. */
  120. void APPW_X_FS_Init(void) {
  121.   APPW_SetFileAccess(&_FileAccess);
  122. }

  123. #endif

  124. /*************************** End of file ****************************/
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-13 10:12 , Processed in 0.149025 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表