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.

89 lines
2.3 KiB

  1. #include "windows.h"
  2. #include "nntpdrv.h"
  3. HINSTANCE g_hInst;
  4. extern "C" {
  5. BOOL WINAPI RPCProxyDllMain(HINSTANCE, DWORD, LPVOID);
  6. HRESULT STDAPICALLTYPE RPCProxyDllRegisterServer();
  7. HRESULT STDAPICALLTYPE RPCProxyDllUnregisterServer();
  8. HRESULT STDAPICALLTYPE RPCProxyDllGetClassObject(REFCLSID, REFIID, void **);
  9. HRESULT STDAPICALLTYPE RPCProxyDllCanUnloadNow();
  10. }
  11. BOOL WINAPI DllMain(
  12. HINSTANCE hinstDLL,
  13. DWORD fdwReason,
  14. LPVOID lpvReserved)
  15. {
  16. if(fdwReason == DLL_PROCESS_ATTACH)
  17. g_hInst = hinstDLL;
  18. return RPCProxyDllMain(hinstDLL, fdwReason, lpvReserved);
  19. }
  20. HRESULT STDAPICALLTYPE DllRegisterServer() {
  21. HRESULT hr;
  22. WCHAR wszFilename[MAX_PATH];
  23. wszFilename[MAX_PATH - 1] = L'\0';
  24. if (GetModuleFileNameW(g_hInst, wszFilename, MAX_PATH - 1) <= 0) {
  25. return HRESULT_FROM_WIN32(GetLastError());
  26. }
  27. ITypeLib *ptLib;
  28. hr = LoadTypeLib(wszFilename, &ptLib);
  29. if (SUCCEEDED(hr)) {
  30. hr = RegisterTypeLib(ptLib, wszFilename, NULL);
  31. if (SUCCEEDED(hr)) {
  32. hr = RPCProxyDllRegisterServer();
  33. }
  34. ptLib->Release();
  35. }
  36. return hr;
  37. }
  38. HRESULT STDAPICALLTYPE DllUnregisterServer()
  39. {
  40. HRESULT hr;
  41. WCHAR wszFilename[MAX_PATH];
  42. // load the type library from our module
  43. wszFilename[MAX_PATH - 1] = L'\0';
  44. if (GetModuleFileNameW(g_hInst, wszFilename, MAX_PATH - 1) <= 0) {
  45. return HRESULT_FROM_WIN32(GetLastError());
  46. }
  47. ITypeLib *ptLib;
  48. hr = LoadTypeLib(wszFilename, &ptLib);
  49. if (SUCCEEDED(hr)) {
  50. // get the type library properties
  51. TLIBATTR *pTLAttributes;
  52. hr = ptLib->GetLibAttr(&pTLAttributes);
  53. if (SUCCEEDED(hr)) {
  54. // unregister the type library using those properties
  55. hr = UnRegisterTypeLib(pTLAttributes->guid,
  56. pTLAttributes->wMajorVerNum,
  57. pTLAttributes->wMinorVerNum,
  58. pTLAttributes->lcid,
  59. pTLAttributes->syskind);
  60. if (SUCCEEDED(hr)) {
  61. hr = RPCProxyDllRegisterServer();
  62. if (SUCCEEDED(hr)) {
  63. hr = RPCProxyDllUnregisterServer();
  64. }
  65. }
  66. }
  67. ptLib->Release();
  68. }
  69. return hr;
  70. }
  71. HRESULT STDAPICALLTYPE DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv) {
  72. return RPCProxyDllGetClassObject(rclsid, riid, ppv);
  73. }
  74. HRESULT STDAPICALLTYPE DllCanUnloadNow() {
  75. return RPCProxyDllCanUnloadNow();
  76. }