1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7     framework.cpp
8 
9 Abstract:
10 
11 Environment:
12 
13     User mode only
14 
15 Revision History:
16 
17 
18 --*/
19 
20 #include <ntverp.h>
21 #include <strsafe.h>
22 #include <driverspecs.h>
23 
24 #include "fxmin.hpp"
25 #include "FxFrameworkStubUm.h"
26 
27 extern "C" {
28 #include "FxDynamics.h"
29 #include "..\librarycommon\FxLibraryCommon.h"
30 extern WDF_LIBRARY_INFO  WdfLibraryInfo;
31 
32 #if !(NO_UMDF_VERSION_EXPORT)
33 DECLSPEC_EXPORT
34 DECLSPEC_SELECTANY
35 
36 UMDF_VERSION_DATA Microsoft_WDF_UMDF_Version = {__WUDF_MAJOR_VERSION,
37 
38                                                 __WUDF_MINOR_VERSION,
39 
40                                                 __WUDF_SERVICE_VERSION};
41 
42 #endif
43 
44 //
45 // Pointer to the platform interface supplied by the host
46 //
47 IUMDFPlatform *g_IUMDFPlatform = NULL;
48 IWudfHost2 *g_IWudfHost2 = NULL;
49 
50 
51 // ***********************************************************************************
52 // DLL Entry Point
53 BOOL
54 WINAPI DllMain(
55     __in HINSTANCE hInstance,
56     __in DWORD dwReason,
57     __in LPVOID lpReserved
58     )
59 {
60     UNREFERENCED_PARAMETER(lpReserved);
61 
62     hInstance;
63 
64     if (DLL_PROCESS_ATTACH == dwReason)
65     {
66         DisableThreadLibraryCalls(hInstance);
67     }
68     else if (DLL_PROCESS_DETACH == dwReason)
69     {
70         DO_NOTHING();
71     }
72 
73     return TRUE;
74 }
75 
76 __control_entrypoint(DllExport)
77 NTSTATUS
78 FxFrameworkEntryUm(
79     __in PWUDF_LOADER_FX_INTERFACE LoaderInterface,
80     __in PVOID Context
81     )
82 {
83     NTSTATUS status;
84 
85     //
86     // Basic validation.
87     //
88     if (LoaderInterface == NULL ||
89         LoaderInterface->Size < sizeof(WUDF_LOADER_FX_INTERFACE) ||
90         LoaderInterface->pUMDFPlatform == NULL) {
91         status = STATUS_INVALID_PARAMETER;
92         __Print(("Failed to validate loader interface parameters, "
93             "status 0x%x\n", status));
94         goto Done;
95     }
96 
97     //
98     // Store platform interface.
99     //
100     g_IUMDFPlatform = LoaderInterface->pUMDFPlatform;
101 
102     //
103     // Get the IWudfHost * from LoaderInterface.
104     //
105     FX_VERIFY(INTERNAL, CHECK_NOT_NULL(LoaderInterface->pIWudfHost));
106     HRESULT hrQI = LoaderInterface->pIWudfHost->QueryInterface(
107                                     IID_IWudfHost2,
108                                     (PVOID*)&g_IWudfHost2
109                                     );
110 
111     FX_VERIFY(INTERNAL, CHECK_QI(hrQI, g_IWudfHost2));
112     g_IWudfHost2->Release();
113 
114     //
115     // Do first time init of this v2.x framework module.
116     // In framework v1.x this is done as a side effect of invoking the
117     // IUMDFramework->Initialize method.
118     //
119     status = LoaderInterface->RegisterLibrary(Context, &WdfLibraryInfo);
120     if (!NT_SUCCESS(status)) {
121         __Print(("RegisterLibrary failed, status 0x%x\n", status));
122         goto Done;
123     }
124 
125     status = STATUS_SUCCESS;
126 
127 Done:
128 
129     return status;
130 }
131 
132 }
133