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.

94 lines
2.5 KiB

  1. /*
  2. File GuidMap.c
  3. Defines function to map a guid interface name to an unique descriptive
  4. name describing that interface and vice versa.
  5. Paul Mayfield, 8/25/97
  6. Copyright 1997, Microsoft Corporation.
  7. */
  8. #include "precomp.h"
  9. static HANDLE hConfig = NULL;
  10. //
  11. // Set the server that the name mapper will utilize
  12. //
  13. DWORD IfNameMapSetServer(HANDLE hMprConfig) {
  14. hConfig = hMprConfig;
  15. return NO_ERROR;
  16. }
  17. //
  18. // Map the guid name to the friendly name
  19. //
  20. DWORD IfName2DescriptionW(IN PWCHAR pszName, OUT PWCHAR pszBuffer, IN LPDWORD lpdwBufSize) {
  21. if (hConfig == NULL || lpdwBufSize == NULL)
  22. return ERROR_CAN_NOT_COMPLETE;
  23. return MprConfigGetFriendlyName (hConfig, pszName, pszBuffer, *lpdwBufSize);
  24. }
  25. //
  26. // Map the friendly name to the guid name
  27. //
  28. DWORD Description2IfNameW(IN PWCHAR pszName, OUT PWCHAR pszBuffer, IN LPDWORD lpdwBufSize) {
  29. if (hConfig == NULL || lpdwBufSize == NULL)
  30. return ERROR_CAN_NOT_COMPLETE;
  31. return MprConfigGetGuidName (hConfig, pszName, pszBuffer, *lpdwBufSize);
  32. }
  33. // ==================================================================
  34. // ANSI versions of the above functions
  35. // ==================================================================
  36. #define mbtowc(mb,wc) MultiByteToWideChar (CP_ACP, 0, (mb), strlen ((mb)) + 1, (wc), 1024)
  37. #define wctomb(wc,mb) WideCharToMultiByte (CP_ACP, 0, (wc), wcslen ((wc)) + 1, (mb), 1024, NULL, NULL)
  38. DWORD IfName2DescriptionA(LPSTR pszName, LPSTR pszBuffer, LPDWORD lpdwBufSize) {
  39. WCHAR pszNameW[1024];
  40. WCHAR pszBufferW[1024];
  41. DWORD dwErr;
  42. int ret;
  43. // Translate params to wide char
  44. ret = mbtowc(pszName, pszNameW);
  45. if (!ret)
  46. return GetLastError();
  47. // Call wide char version of function and copy back to multi byte
  48. dwErr = IfName2DescriptionW (pszNameW, pszBufferW, lpdwBufSize);
  49. if (dwErr == NO_ERROR) {
  50. ret = wctomb(pszBufferW, pszBuffer);
  51. if (ret == 0)
  52. return GetLastError();
  53. }
  54. return dwErr;
  55. }
  56. DWORD Description2IfNameA(LPSTR pszDesc, LPSTR pszBuffer, LPDWORD lpdwBufSize) {
  57. WCHAR pszNameW[1024];
  58. WCHAR pszBufferW[1024];
  59. DWORD dwErr;
  60. int ret;
  61. // Translate params to wide char
  62. ret = mbtowc(pszDesc, pszNameW);
  63. if (ret == 0)
  64. return GetLastError();
  65. // Call wide char version of function and copy back to multi byte
  66. dwErr = Description2IfNameW(pszNameW, pszBufferW, lpdwBufSize);
  67. if (dwErr == NO_ERROR) {
  68. ret = wctomb(pszBufferW, pszBuffer);
  69. if (!ret)
  70. return GetLastError();
  71. }
  72. return dwErr;
  73. }