f9a523b8fd24178e32f6822607aea22112189fd3
[reactos.git] / reactos / lib / smdll / execpgm.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/smdll/execpgm.c
6 * PURPOSE: Call SM API SM_API_EXECPGM
7 */
8 #define NTOS_MODE_USER
9 #include <ntos.h>
10 #include <sm/api.h>
11 #include <sm/helper.h>
12 #include <string.h>
13
14 NTSTATUS STDCALL
15 SmExecPgm (HANDLE hSmApiPort, PUNICODE_STRING Pgm)
16 {
17 NTSTATUS Status;
18 SM_PORT_MESSAGE SmReqMsg;
19
20
21 /* Check Pgm's length */
22 if (Pgm->Length > (sizeof (Pgm->Buffer[0]) * SM_EXEXPGM_MAX_LENGTH))
23 {
24 return STATUS_INVALID_PARAMETER;
25 }
26 /* Marshal Pgm in the LPC message */
27 RtlZeroMemory (& SmReqMsg, sizeof SmReqMsg);
28 SmReqMsg.ExecPgm.NameLength = Pgm->Length;
29 RtlCopyMemory (SmReqMsg.ExecPgm.Name, Pgm->Buffer, Pgm->Length);
30
31 /* SM API to invoke */
32 SmReqMsg.ApiIndex = SM_API_EXECUTE_PROGRAMME;
33
34 /* LPC message */
35 SmReqMsg.Header.MessageType = LPC_NEW_MESSAGE;
36 SmReqMsg.Header.DataSize = SM_PORT_DATA_SIZE(SmReqMsg.ExecPgm);
37 SmReqMsg.Header.MessageSize = SM_PORT_MESSAGE_SIZE;
38
39 /* Call SM and wait for a reply */
40 Status = NtRequestWaitReplyPort (hSmApiPort, (PLPC_MESSAGE) & SmReqMsg, (PLPC_MESSAGE) & SmReqMsg);
41 if (NT_SUCCESS(Status))
42 {
43 return SmReqMsg.Status;
44 }
45 DbgPrint ("%s failed (Status=0x%08lx)\n", __FUNCTION__, Status);
46 return Status;
47 }
48
49 /* EOF */