1 /*++ 2 3 Copyright (c) Microsoft Corporation 4 5 Module Name: 6 7 FxStringApi.cpp 8 9 Abstract: 10 11 This module implements the "C" interface to the collection object. 12 13 Author: 14 15 16 17 Environment: 18 19 Both kernel and user mode 20 21 Revision History: 22 23 --*/ 24 25 #include "fxsupportpch.hpp" 26 27 extern "C" { 28 // #include "FxStringAPI.tmh" 29 } 30 31 extern "C" { 32 33 _Must_inspect_result_ 34 __drv_maxIRQL(PASSIVE_LEVEL) 35 NTSTATUS 36 STDCALL 37 WDFEXPORT(WdfStringCreate)( 38 __in 39 PWDF_DRIVER_GLOBALS DriverGlobals, 40 __in_opt 41 PCUNICODE_STRING UnicodeString, 42 __in_opt 43 PWDF_OBJECT_ATTRIBUTES StringAttributes, 44 __out 45 WDFSTRING* String 46 ) 47 { 48 DDI_ENTRY(); 49 50 PFX_DRIVER_GLOBALS pFxDriverGlobals; 51 FxString* pString; 52 NTSTATUS status; 53 54 pFxDriverGlobals = GetFxDriverGlobals(DriverGlobals); 55 56 // 57 // Get the parent's globals if it is present 58 // 59 if (NT_SUCCESS(FxValidateObjectAttributesForParentHandle(pFxDriverGlobals, 60 StringAttributes))) { 61 FxObject* pParent; 62 63 FxObjectHandleGetPtrAndGlobals(pFxDriverGlobals, 64 StringAttributes->ParentObject, 65 FX_TYPE_OBJECT, 66 (PVOID*)&pParent, 67 &pFxDriverGlobals); 68 } 69 70 FxPointerNotNull(pFxDriverGlobals, String); 71 72 *String = NULL; 73 74 status = FxVerifierCheckIrqlLevel(pFxDriverGlobals, PASSIVE_LEVEL); 75 if (!NT_SUCCESS(status)) { 76 return status; 77 } 78 79 status = FxValidateObjectAttributes(pFxDriverGlobals, StringAttributes); 80 if (!NT_SUCCESS(status)) { 81 return status; 82 } 83 84 if (UnicodeString != NULL) { 85 status = FxValidateUnicodeString(pFxDriverGlobals, UnicodeString); 86 if (!NT_SUCCESS(status)) { 87 return status; 88 } 89 } 90 91 pString = new (pFxDriverGlobals, StringAttributes) FxString(pFxDriverGlobals); 92 93 if (pString != NULL) { 94 if (UnicodeString != NULL) { 95 status = pString->Assign(UnicodeString); 96 } 97 98 if (NT_SUCCESS(status)) { 99 status = pString->Commit(StringAttributes, (WDFOBJECT*)String); 100 } 101 102 if (!NT_SUCCESS(status)) { 103 pString->DeleteFromFailedCreate(); 104 pString = NULL; 105 } 106 } 107 else { 108 status = STATUS_INSUFFICIENT_RESOURCES; 109 110 DoTraceLevelMessage( 111 pFxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGERROR, 112 "Could not allocate WDFSTRING handle, %!STATUS!", status); 113 } 114 115 return status; 116 } 117 118 __drv_maxIRQL(PASSIVE_LEVEL) 119 VOID 120 STDCALL 121 WDFEXPORT(WdfStringGetUnicodeString)( 122 __in 123 PWDF_DRIVER_GLOBALS DriverGlobals, 124 __in 125 WDFSTRING String, 126 __out 127 PUNICODE_STRING UnicodeString 128 ) 129 { 130 DDI_ENTRY(); 131 132 PFX_DRIVER_GLOBALS pFxDriverGlobals; 133 FxString* pString; 134 NTSTATUS status; 135 136 FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), 137 String, 138 FX_TYPE_STRING, 139 (PVOID*) &pString, 140 &pFxDriverGlobals); 141 142 FxPointerNotNull(pFxDriverGlobals, UnicodeString); 143 144 status = FxVerifierCheckIrqlLevel(pFxDriverGlobals, PASSIVE_LEVEL); 145 if (!NT_SUCCESS(status)) { 146 return; 147 } 148 149 RtlCopyMemory(UnicodeString, 150 pString->GetUnicodeString(), 151 sizeof(UNICODE_STRING)); 152 } 153 154 } // extern "C" 155