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.

155 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. dynodbc.c
  5. Abstract:
  6. This module provides functions for dynamically loading the ODBC
  7. functions.
  8. Author:
  9. Murali R. Krishnan (MuraliK) 3-Nov-1995
  10. Revision History:
  11. --*/
  12. #include <windows.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. # include "dynodbc.h"
  16. # include "html.h"
  17. #include "resource.h"
  18. //
  19. // ODBC DLL Entry Points, fill by calling LoadODBC
  20. //
  21. pfnSQLAllocConnect pSQLAllocConnect ;
  22. pfnSQLAllocEnv pSQLAllocEnv ;
  23. pfnSQLAllocStmt pSQLAllocStmt ;
  24. pfnSQLBindCol pSQLBindCol ;
  25. pfnSQLCancel pSQLCancel ;
  26. pfnSQLColAttributes pSQLColAttributes ;
  27. pfnSQLConnect pSQLConnect ;
  28. pfnSQLDescribeCol pSQLDescribeCol ;
  29. pfnSQLDisconnect pSQLDisconnect ;
  30. pfnSQLError pSQLError ;
  31. pfnSQLExecDirect pSQLExecDirect ;
  32. pfnSQLExecute pSQLExecute ;
  33. pfnSQLFetch pSQLFetch ;
  34. pfnSQLFreeConnect pSQLFreeConnect ;
  35. pfnSQLFreeEnv pSQLFreeEnv ;
  36. pfnSQLFreeStmt pSQLFreeStmt ;
  37. pfnSQLGetCursorName pSQLGetCursorName ;
  38. pfnSQLNumResultCols pSQLNumResultCols ;
  39. pfnSQLPrepare pSQLPrepare ;
  40. pfnSQLRowCount pSQLRowCount ;
  41. pfnSQLSetCursorName pSQLSetCursorName ;
  42. pfnSQLTransact pSQLTransact ;
  43. pfnSQLSetConnectOption pSQLSetConnectOption;
  44. pfnSQLDrivers pSQLDrivers ;
  45. pfnSQLDataSources pSQLDataSources ;
  46. pfnSQLBindParameter pSQLBindParameter ;
  47. pfnSQLConfigDataSource pSQLConfigDataSource ;
  48. #define LOAD_ENTRY( Name ) (p##Name = (pfn##Name) GetProcAddress( hMod, #Name ))
  49. static char szErrMsg[_MAX_PATH];
  50. static char szODBCErrMsg[_MAX_PATH];
  51. BOOL fODBCLoaded = FALSE;
  52. BOOL
  53. DynLoadODBC(
  54. VOID
  55. )
  56. {
  57. HMODULE hMod;
  58. if ( fODBCLoaded )
  59. return TRUE;
  60. if ( (hMod = (HMODULE) LoadLibrary( "odbc32.dll" ))) {
  61. if ( LOAD_ENTRY( SQLAllocConnect ) &&
  62. LOAD_ENTRY( SQLAllocEnv ) &&
  63. LOAD_ENTRY( SQLAllocStmt ) &&
  64. LOAD_ENTRY( SQLBindCol ) &&
  65. LOAD_ENTRY( SQLCancel ) &&
  66. LOAD_ENTRY( SQLColAttributes ) &&
  67. LOAD_ENTRY( SQLConnect ) &&
  68. LOAD_ENTRY( SQLDescribeCol ) &&
  69. LOAD_ENTRY( SQLDisconnect ) &&
  70. LOAD_ENTRY( SQLError ) &&
  71. LOAD_ENTRY( SQLExecDirect ) &&
  72. LOAD_ENTRY( SQLExecute ) &&
  73. LOAD_ENTRY( SQLFetch ) &&
  74. LOAD_ENTRY( SQLFreeConnect ) &&
  75. LOAD_ENTRY( SQLFreeEnv ) &&
  76. LOAD_ENTRY( SQLFreeStmt ) &&
  77. LOAD_ENTRY( SQLNumResultCols ) &&
  78. LOAD_ENTRY( SQLPrepare ) &&
  79. LOAD_ENTRY( SQLRowCount ) &&
  80. LOAD_ENTRY( SQLTransact ) &&
  81. LOAD_ENTRY( SQLSetConnectOption ) &&
  82. LOAD_ENTRY( SQLDrivers ) &&
  83. LOAD_ENTRY( SQLDataSources ) &&
  84. LOAD_ENTRY( SQLBindParameter )) {
  85. fODBCLoaded = TRUE;
  86. return TRUE;
  87. }
  88. }
  89. else {
  90. HINSTANCE hInst = GetModuleHandle(NULL);
  91. LoadString(hInst, IDS_ERRORMSG, szErrMsg, sizeof(szErrMsg));
  92. LoadString(hInst, IDS_ODBCERRMSG, szODBCErrMsg, sizeof(szODBCErrMsg));
  93. StartHTML(szODBCErrMsg, FALSE);
  94. printf(szErrMsg);
  95. EndHTML();
  96. }
  97. return FALSE;
  98. } // DynLoadODBC()
  99. BOOL fODBCInstallerLoaded = FALSE;
  100. BOOL
  101. DynLoadODBCInstaller(
  102. VOID
  103. )
  104. {
  105. HMODULE hMod;
  106. if ( fODBCInstallerLoaded )
  107. return TRUE;
  108. if ( (hMod = (HMODULE) LoadLibrary( "odbccp32.dll" ))) {
  109. if ( LOAD_ENTRY( SQLConfigDataSource)) {
  110. fODBCInstallerLoaded = TRUE;
  111. return TRUE;
  112. }
  113. }
  114. else {
  115. HINSTANCE hInst = GetModuleHandle(NULL);
  116. LoadString(hInst, IDS_ERRORMSG, szErrMsg, sizeof(szErrMsg));
  117. LoadString(hInst, IDS_ODBCERRMSG, szODBCErrMsg, sizeof(szODBCErrMsg));
  118. StartHTML(szODBCErrMsg, FALSE);
  119. printf(szErrMsg);
  120. EndHTML();
  121. }
  122. return FALSE;
  123. } // DynLoadODBCInstaller()