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
+ 2 * sizeof(WCHAR
);
49 pStr
= HeapAlloc(GetProcessHeap(), 0, TotalSize
);
51 return STATUS_INSUFFICIENT_RESOURCES
;
53 wcscpy(pStr
, (LPWSTR
)IID
);
55 memcpy(&pStr
[Length
+1], Buffer
, BufferSize
);
56 pStr
[Length
+1+BufferSize
] = L
'\0';
58 RtlInitUnicodeString(&ObjectName
, pStr
);
60 InitializeObjectAttributes(&ObjectAttributes
, &ObjectName
, OBJ_CASE_INSENSITIVE
, hHandle
, NULL
);
62 Status
= NtCreateFile(phHandle
, DesiredAccess
, &ObjectAttributes
, &IoStatusBlock
, NULL
, FILE_ATTRIBUTE_NORMAL
, 0, 1, 0, NULL
, 0);
63 HeapFree(GetProcessHeap(), 0, pStr
);
64 if (!NT_SUCCESS(Status
))
66 *phHandle
= INVALID_HANDLE_VALUE
;
67 Status
= RtlNtStatusToDosError(Status
);
73 * @name KsCreateAllocator
75 * The function KsCreateAllocator creates a handle to an allocator for the given sink connection handle
77 * @param HANDLE ConnectionHandle
78 * Handle to the sink connection on which to create the allocator
80 * @param PKSALLOCATOR_FRAMING AllocatorFraming
81 * the input param we using to alloc our framing
83 * @param PHANDLE AllocatorHandle
84 * Our new handle that we have alloc
87 * Return NTSTATUS error code or sussess code.
96 KsCreateAllocator(HANDLE ConnectionHandle
,
97 PKSALLOCATOR_FRAMING AllocatorFraming
,
98 PHANDLE AllocatorHandle
)
101 return KsiCreateObjectType( ConnectionHandle
,
103 (PVOID
) AllocatorFraming
,
104 sizeof(KSALLOCATOR_FRAMING
),
110 * @name KsCreateClock
113 * The function KsCreateClock creates handle to clock instance
115 * @param HANDLE ConnectionHandle
116 * Handle to use to create the clock
118 * @param PKSCLOCK_CREATE ClockCreate
119 * paramenter to use to create the clock
121 * @param PHANDLE ClockHandle
125 * Return NTSTATUS error code or sussess code.
134 KsCreateClock(HANDLE ConnectionHandle
,
135 PKSCLOCK_CREATE ClockCreate
,
138 return KsiCreateObjectType( ConnectionHandle
,
141 sizeof(KSCLOCK_CREATE
),
150 * The function KsCreatePin passes a connection request to device and create pin instance
152 * @param HANDLE FilterHandle
153 * handle of the filter initiating the create request
155 * @param PKSPIN_CONNECT Connect
156 * Pointer to a KSPIN_CONNECT structure that contains parameters for the requested connection.
157 * This should be followed in memory by a KSDATAFORMAT data structure, describing the data format
158 * requested for the connection.
160 * @param ACCESS_MASK DesiredAccess
163 * @param PHANDLE ConnectionHandle
164 * connection handle passed
167 * Return NTSTATUS error code or sussess code.
170 * The flag in PKSDATAFORMAT is not really document,
171 * to find it u need api mointor allot api and figout
172 * how it works, only flag I have found is the
173 * KSDATAFORMAT_ATTRIBUTES flag, it doing a Align
174 * of LONLONG size, it also round up it.
181 KsCreatePin(HANDLE FilterHandle
,
182 PKSPIN_CONNECT Connect
,
183 ACCESS_MASK DesiredAccess
,
184 PHANDLE ConnectionHandle
)
186 ULONG BufferSize
= sizeof(KSPIN_CONNECT
);
187 PKSDATAFORMAT DataFormat
= ((PKSDATAFORMAT
) ( ((ULONG
)Connect
) + ((ULONG
)sizeof(KSPIN_CONNECT
)) ) );
189 if (DataFormat
->Flags
& KSDATAFORMAT_ATTRIBUTES
)
191 BufferSize
+= (ROUND_UP(DataFormat
->FormatSize
,sizeof(LONGLONG
)) + DataFormat
->FormatSize
);
194 return KsiCreateObjectType(FilterHandle
,
204 * @name KsCreateTopologyNode
207 * The function KsCreateTopologyNode creates a handle to a topology node instance
209 * @param HANDLE ParentHandle
210 * Handle to parent when want to use when we created the node on
213 * @param PKSNODE_CREATE NodeCreate
214 * topology node parameters to use when it is create
216 * @param ACCESS_MASK DesiredAccess
219 * @param PHANDLE NodeHandle
220 * Location for the topology node handle
223 * Return NTSTATUS error code or sussess code.
232 KsCreateTopologyNode(HANDLE ParentHandle
,
233 PKSNODE_CREATE NodeCreate
,
234 IN ACCESS_MASK DesiredAccess
,
235 OUT PHANDLE NodeHandle
)
237 return KsiCreateObjectType( ParentHandle
,
238 KSSTRING_TopologyNode
,
240 sizeof(KSNODE_CREATE
),
248 DllMain(HANDLE hModule
, DWORD ulreason
, LPVOID lpReserved
)
252 case DLL_PROCESS_ATTACH
:
253 case DLL_THREAD_ATTACH
:
254 case DLL_THREAD_DETACH
:
255 case DLL_PROCESS_DETACH
: