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.

121 lines
2.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: hgttran.c
  8. //
  9. //--------------------------------------------------------------------------
  10. #include <windows.h>
  11. #include <memory.h>
  12. #include <assert.h>
  13. #include <malloc.h>
  14. #include "gttran.h"
  15. #include "ihgttran.h"
  16. DWORD __stdcall GTOpen(HGT * phTran, const TCHAR * szLibrary, const TCHAR * tszBinding, DWORD fOpen) {
  17. IGTS * pIGTS;
  18. DWORD err = ERROR_SUCCESS;
  19. assert(phTran != NULL);
  20. assert(szLibrary != NULL);
  21. // initialize the return handle
  22. *phTran = 0;
  23. // make a data structure for the handle
  24. if( (pIGTS = (IGTS *) malloc(sizeof(IGTS))) == NULL)
  25. return(ERROR_NOT_ENOUGH_MEMORY);
  26. memset(pIGTS, 0, sizeof(IGTS));
  27. // load the dynamic library
  28. if( (pIGTS->hLib = LoadLibrary(szLibrary)) == NULL ) {
  29. free(pIGTS);
  30. return(ERROR_DLL_NOT_FOUND);
  31. }
  32. // now get all of the proc addres
  33. if( (pIGTS->PfnOpen = (PFNOpen) GetProcAddress(pIGTS->hLib, "Open")) == NULL )
  34. err = ERROR_PROC_NOT_FOUND;
  35. if( (pIGTS->PfnSend = (PFNSend) GetProcAddress(pIGTS->hLib, "Send")) == NULL )
  36. err = ERROR_PROC_NOT_FOUND;
  37. if( (pIGTS->PfnFree = (PFNFree) GetProcAddress(pIGTS->hLib, "Free")) == NULL )
  38. err = ERROR_PROC_NOT_FOUND;
  39. if( (pIGTS->PfnReceive = (PFNReceive) GetProcAddress(pIGTS->hLib, "Receive")) == NULL )
  40. err = ERROR_PROC_NOT_FOUND;
  41. if( (pIGTS->PfnClose = (PFNClose) GetProcAddress(pIGTS->hLib, "Close")) == NULL )
  42. err = ERROR_PROC_NOT_FOUND;
  43. if(err != ERROR_SUCCESS) {
  44. FreeLibrary(pIGTS->hLib );
  45. free(pIGTS);
  46. return(err);
  47. }
  48. // ok, open the file
  49. err = pIGTS->PfnOpen(&pIGTS->hTran, tszBinding, fOpen);
  50. if(err != ERROR_SUCCESS) {
  51. FreeLibrary(pIGTS->hLib );
  52. free(pIGTS);
  53. return(err);
  54. }
  55. // return the handle
  56. *phTran = (HGT) pIGTS;
  57. return(err);
  58. }
  59. DWORD __stdcall GTSend(HGT hTran, DWORD dwEncoding, DWORD cbSendBuff, const BYTE * pbSendBuff) {
  60. IGTS * pIGTS;
  61. assert(hTran != 0);
  62. pIGTS = (IGTS *) hTran;
  63. return(pIGTS->PfnSend(pIGTS->hTran, dwEncoding, cbSendBuff, pbSendBuff));
  64. }
  65. DWORD __stdcall GTFree(HGT hTran, BYTE * pb) {
  66. IGTS * pIGTS;
  67. assert(hTran != 0);
  68. pIGTS = (IGTS *) hTran;
  69. return(pIGTS->PfnFree(pIGTS->hTran, pb));
  70. }
  71. DWORD __stdcall GTReceive(HGT hTran, DWORD * pdwEncoding, DWORD * pcbReceiveBuff, BYTE ** ppbReceiveBuff) {
  72. IGTS * pIGTS;
  73. assert(hTran != 0);
  74. pIGTS = (IGTS *) hTran;
  75. return(pIGTS->PfnReceive(pIGTS->hTran, pdwEncoding, pcbReceiveBuff, ppbReceiveBuff));
  76. }
  77. DWORD __stdcall GTClose(HGT hTran) {
  78. IGTS * pIGTS;
  79. assert(hTran != 0);
  80. pIGTS = (IGTS *) hTran;
  81. // close and free all ofthe junk
  82. pIGTS->PfnClose(pIGTS->hTran);
  83. FreeLibrary(pIGTS->hLib );
  84. free(pIGTS);
  85. return(ERROR_SUCCESS);
  86. }