Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.6 KiB

  1. //////////////////////////////////////////////
  2. //
  3. // This file has the helper function used in the win32 r/w
  4. // I copied them in this file to share them with the res32 r/w
  5. //
  6. #include <afxwin.h>
  7. #include "..\common\helper.h"
  8. //=============================================================================
  9. // Get functions
  10. //
  11. UINT
  12. GetPascalStringW( BYTE * * lplpBuf, LPSTR lpszText, WORD wMaxLen, LONG* pdwSize )
  13. {
  14. // Get the length of the string
  15. WORD wstrlen = 0;
  16. WORD wMBLen = 0;
  17. GetWord( lplpBuf, &wstrlen, pdwSize );
  18. if ((wstrlen+1)>wMaxLen) {
  19. *pdwSize -= wstrlen*2;
  20. *lplpBuf += wstrlen*2;
  21. } else {
  22. if (wstrlen) {
  23. WCHAR* lpwszStr = new WCHAR[wstrlen+1];
  24. if (!lpwszStr) *pdwSize =0;
  25. else {
  26. memcpy(lpwszStr, *lplpBuf, (wstrlen*2));
  27. *(lpwszStr+wstrlen) = 0;
  28. wMBLen = (WORD)_WCSTOMBS( lpszText, (WCHAR*)lpwszStr, wMaxLen);
  29. delete lpwszStr;
  30. }
  31. }
  32. *(lpszText+wMBLen) = 0;
  33. *lplpBuf += wstrlen*2;
  34. *pdwSize -= wstrlen*2;
  35. }
  36. return(wstrlen+1);
  37. }
  38. UINT
  39. GetPascalStringA( BYTE * * lplpBuf, LPSTR lpszText, BYTE bMaxLen, LONG* pdwSize )
  40. {
  41. // Get the length of the string
  42. BYTE bstrlen = 0;
  43. GetByte( lplpBuf, &bstrlen, pdwSize );
  44. if ((bstrlen+1)>bMaxLen) {
  45. *pdwSize -= bstrlen;
  46. *lplpBuf += bstrlen;
  47. } else {
  48. if (bstrlen)
  49. memcpy(lpszText, *lplpBuf, bstrlen);
  50. *(lpszText+bstrlen) = 0;
  51. *lplpBuf += bstrlen;
  52. *pdwSize -= bstrlen;
  53. }
  54. return(bstrlen+1);
  55. }