4 * Copyright 2008 Magnus Olsen and Dmitry Chapyshev
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 NTSTATUS NTAPI
KsiCreateObjectType( HANDLE hHandle
, PVOID guidstr
, PVOID Buffer
, ULONG BufferSize
, ACCESS_MASK DesiredAccess
, PHANDLE phHandle
);
30 KsiCreateObjectType( HANDLE hHandle
,
34 ACCESS_MASK DesiredAccess
,
41 UNICODE_STRING ObjectName
;
42 OBJECT_ATTRIBUTES ObjectAttributes
;
43 IO_STATUS_BLOCK IoStatusBlock
;
47 TotalSize
= (Length
* sizeof(WCHAR
)) + BufferSize
+ 4 * sizeof(WCHAR
);
49 pStr
= HeapAlloc(GetProcessHeap(), 0, TotalSize
);
51 return STATUS_INSUFFICIENT_RESOURCES
;
53 wcscpy(&pStr
[1], (LPWSTR
)IID
);
54 pStr
[Length
+1] = L
'\\';
55 memcpy(&pStr
[Length
+2], Buffer
, BufferSize
);
56 pStr
[Length
+3+(BufferSize
/sizeof(WCHAR
))] = L
'\0';
58 RtlInitUnicodeString(&ObjectName
, pStr
);
59 ObjectName
.Length
= ObjectName
.MaximumLength
= TotalSize
;
61 InitializeObjectAttributes(&ObjectAttributes
, &ObjectName
, OBJ_CASE_INSENSITIVE
, hHandle
, NULL
);
63 Status
= NtCreateFile(phHandle
, DesiredAccess
, &ObjectAttributes
, &IoStatusBlock
, NULL
, FILE_ATTRIBUTE_NORMAL
, 0, 1, 0, NULL
, 0);
64 HeapFree(GetProcessHeap(), 0, pStr
);
65 if (!NT_SUCCESS(Status
))
67 *phHandle
= INVALID_HANDLE_VALUE
;
68 Status
= RtlNtStatusToDosError(Status
);
74 * @name KsCreateAllocator
76 * The function KsCreateAllocator creates a handle to an allocator for the given sink connection handle
78 * @param HANDLE ConnectionHandle
79 * Handle to the sink connection on which to create the allocator
81 * @param PKSALLOCATOR_FRAMING AllocatorFraming
82 * the input param we using to alloc our framing
84 * @param PHANDLE AllocatorHandle
85 * Our new handle that we have alloc
88 * Return NTSTATUS error code or sussess code.
97 KsCreateAllocator(HANDLE ConnectionHandle
,
98 PKSALLOCATOR_FRAMING AllocatorFraming
,
99 PHANDLE AllocatorHandle
)
102 return KsiCreateObjectType( ConnectionHandle
,
104 (PVOID
) AllocatorFraming
,
105 sizeof(KSALLOCATOR_FRAMING
),
111 * @name KsCreateClock
114 * The function KsCreateClock creates handle to clock instance
116 * @param HANDLE ConnectionHandle
117 * Handle to use to create the clock
119 * @param PKSCLOCK_CREATE ClockCreate
120 * paramenter to use to create the clock
122 * @param PHANDLE ClockHandle
126 * Return NTSTATUS error code or sussess code.
135 KsCreateClock(HANDLE ConnectionHandle
,
136 PKSCLOCK_CREATE ClockCreate
,
139 return KsiCreateObjectType( ConnectionHandle
,
142 sizeof(KSCLOCK_CREATE
),
151 * The function KsCreatePin passes a connection request to device and create pin instance
153 * @param HANDLE FilterHandle
154 * handle of the filter initiating the create request
156 * @param PKSPIN_CONNECT Connect
157 * Pointer to a KSPIN_CONNECT structure that contains parameters for the requested connection.
158 * This should be followed in memory by a KSDATAFORMAT data structure, describing the data format
159 * requested for the connection.
161 * @param ACCESS_MASK DesiredAccess
164 * @param PHANDLE ConnectionHandle
165 * connection handle passed
168 * Return NTSTATUS error code or sussess code.
171 * The flag in PKSDATAFORMAT is not really document,
172 * to find it u need api mointor allot api and figout
173 * how it works, only flag I have found is the
174 * KSDATAFORMAT_ATTRIBUTES flag, it doing a Align
175 * of LONLONG size, it also round up it.
182 KsCreatePin(HANDLE FilterHandle
,
183 PKSPIN_CONNECT Connect
,
184 ACCESS_MASK DesiredAccess
,
185 PHANDLE ConnectionHandle
)
187 ULONG BufferSize
= sizeof(KSPIN_CONNECT
);
188 PKSDATAFORMAT DataFormat
= ((PKSDATAFORMAT
) ( ((ULONG
)Connect
) + ((ULONG
)sizeof(KSPIN_CONNECT
)) ) );
190 BufferSize
+= DataFormat
->FormatSize
;
192 return KsiCreateObjectType(FilterHandle
,
202 * @name KsCreateTopologyNode
205 * The function KsCreateTopologyNode creates a handle to a topology node instance
207 * @param HANDLE ParentHandle
208 * Handle to parent when want to use when we created the node on
211 * @param PKSNODE_CREATE NodeCreate
212 * topology node parameters to use when it is create
214 * @param ACCESS_MASK DesiredAccess
217 * @param PHANDLE NodeHandle
218 * Location for the topology node handle
221 * Return NTSTATUS error code or sussess code.
230 KsCreateTopologyNode(HANDLE ParentHandle
,
231 PKSNODE_CREATE NodeCreate
,
232 IN ACCESS_MASK DesiredAccess
,
233 OUT PHANDLE NodeHandle
)
235 return KsiCreateObjectType( ParentHandle
,
236 KSSTRING_TopologyNode
,
238 sizeof(KSNODE_CREATE
),
246 DllMain(HANDLE hModule
, DWORD ulreason
, LPVOID lpReserved
)
250 case DLL_PROCESS_ATTACH
:
251 case DLL_THREAD_ATTACH
:
252 case DLL_THREAD_DETACH
:
253 case DLL_PROCESS_DETACH
: