[NTVDM]
authorAleksandar Andrejevic <aandrejevic@reactos.org>
Mon, 12 Aug 2013 19:31:54 +0000 (19:31 +0000)
committerAleksandar Andrejevic <aandrejevic@reactos.org>
Mon, 12 Aug 2013 19:31:54 +0000 (19:31 +0000)
Synchronize with trunk again for SetConsolePalette.
Implement VGA palettes for graphics mode and DAC register access.

svn path=/branches/ntvdm/; revision=59713

34 files changed:
CMakeLists.txt
base/services/umpnpmgr/umpnpmgr.c
dll/win32/kernel32/client/console/console.c
dll/win32/netapi32/access.c
dll/win32/netapi32/netapi32.spec
dll/win32/netapi32/user.c
dll/win32/setupapi/cfgmgr.c
dll/win32/setupapi/devinst.c
drivers/network/lan/include/net_wh.h
drivers/network/tcpip/include/fileobjs.h
drivers/network/tcpip/include/tcp.h
drivers/network/tcpip/include/tcpip.h
drivers/network/tcpip/include/titypes.h
drivers/network/tcpip/tcpip/fileobjs.c
include/crt/mingw32/intrin_x86.h
include/crt/sec_api/tchar_s.h
include/psdk/mmsystem.h
include/psdk/vfw.h
include/psdk/wincon.h
include/psdk/winnls.h
include/reactos/subsys/win/conmsg.h
lib/drivers/ip/network/ip.c
lib/drivers/ip/network/neighbor.c
lib/drivers/ip/transport/tcp/event.c
lib/drivers/lwip/src/rostcp.c
subsystems/ntvdm/CMakeLists.txt
subsystems/ntvdm/bios.c
subsystems/ntvdm/vga.c
subsystems/ntvdm/vga.h
win32ss/user/winsrv/consrv/api.h
win32ss/user/winsrv/consrv/condrv/conoutput.c
win32ss/user/winsrv/consrv/conoutput.c
win32ss/user/winsrv/consrv/frontendctl.c
win32ss/user/winsrv/consrv/init.c

index d0c83d7..861e595 100644 (file)
@@ -142,7 +142,7 @@ else()
 
     # Arch Options
     if(ARCH STREQUAL "i386")
-        add_definitions(-D_M_IX86 -D_X86_ -D__i386__)
+        add_definitions(-D_M_IX86 -D_X86_ -D__i386__ -Di386)
     elseif(ARCH STREQUAL "amd64")
         add_definitions(-D_M_AMD64 -D_AMD64_ -D__x86_64__ -D_WIN64)
     elseif(ARCH STREQUAL "arm")
index 1225426..c821105 100644 (file)
@@ -1613,16 +1613,42 @@ DWORD PNP_CreateDevInst(
 
     if (ulFlags & CM_CREATE_DEVNODE_GENERATE_ID)
     {
-        /* FIXME */
-        DPRINT1("CM_CREATE_DEVNODE_GENERATE_ID support not implemented yet!\n", ret);
-        ret = CR_CALL_NOT_IMPLEMENTED;
-        goto done;
-    }
+        WCHAR szGeneratedInstance[MAX_DEVICE_ID_LEN];
+        DWORD dwInstanceNumber;
 
-    /* Create the device instance */
-    ret = CreateDeviceInstance(pszDeviceID);
+        /* Generated ID is: Root\<Device ID>\<Instance number> */
+        dwInstanceNumber = 0;
+        do
+        {
+            swprintf(szGeneratedInstance, L"Root\\%ls\\%04d",
+                     pszDeviceID, dwInstanceNumber);
+
+            /* Try to create a device instance with this ID */
+            ret = CreateDeviceInstance(szGeneratedInstance);
+
+            dwInstanceNumber++;
+        }
+        while (ret == CR_ALREADY_SUCH_DEVINST);
+        
+        if (ret == CR_SUCCESS)
+        {
+            /* pszDeviceID is an out parameter too for generated IDs */
+            if (wcslen(szGeneratedInstance) > ulLength)
+            {
+                ret = CR_BUFFER_SMALL;
+            }
+            else
+            {
+                wcscpy(pszDeviceID, szGeneratedInstance);
+            }
+        }
+    }
+    else
+    {
+        /* Create the device instance */
+        ret = CreateDeviceInstance(pszDeviceID);
+    }
 
-done:;
     DPRINT("PNP_CreateDevInst() done (returns %lx)\n", ret);
 
     return ret;
index ddb7bdf..8e76da6 100644 (file)
@@ -711,17 +711,35 @@ SetConsoleMenuClose(BOOL bEnable)
 
 
 /*
- * @unimplemented (Undocumented)
+ * @implemented (Undocumented)
+ * @note See http://comments.gmane.org/gmane.comp.lang.harbour.devel/27844
+ *       Usage example: https://github.com/harbour/core/commit/d79a1b7b812cbde6ddf718ebfd6939a24f633e52
  */
 BOOL
 WINAPI
-SetConsolePalette(DWORD Unknown0,
-                  DWORD Unknown1,
-                  DWORD Unknown2)
+SetConsolePalette(HANDLE hConsoleOutput,
+                  HPALETTE hPalette,
+                  UINT dwUsage)
 {
-    DPRINT1("SetConsolePalette(0x%x, 0x%x, 0x%x) UNIMPLEMENTED!\n", Unknown0, Unknown1, Unknown2);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return FALSE;
+    NTSTATUS Status;
+    CONSOLE_API_MESSAGE ApiMessage;
+    PCONSOLE_SETPALETTE SetPaletteRequest = &ApiMessage.Data.SetPaletteRequest;
+
+    SetPaletteRequest->OutputHandle  = hConsoleOutput;
+    SetPaletteRequest->PaletteHandle = hPalette;
+    SetPaletteRequest->Usage         = dwUsage;
+
+    Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
+                                 NULL,
+                                 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepSetPalette),
+                                 sizeof(CONSOLE_SETPALETTE));
+    if (!NT_SUCCESS(Status))
+    {
+        BaseSetLastNTError(Status);
+        return FALSE;
+    }
+
+    return TRUE;
 }
 
 /*
index 117392e..968cd30 100644 (file)
@@ -262,130 +262,6 @@ NetGetDCName(LPCWSTR servername, LPCWSTR domainname, LPBYTE *bufptr)
   return NERR_DCNotFound; /* say we can't find a domain controller */  
 }
 
-/******************************************************************************
- * NetUserModalsGet  (NETAPI32.@)
- *
- * Retrieves global information for all users and global groups in the security
- * database.
- *
- * PARAMS
- *  szServer   [I] Specifies the DNS or the NetBIOS name of the remote server
- *                 on which the function is to execute.
- *  level      [I] Information level of the data.
- *     0   Return global passwords parameters. bufptr points to a
- *         USER_MODALS_INFO_0 struct.
- *     1   Return logon server and domain controller information. bufptr
- *         points to a USER_MODALS_INFO_1 struct.
- *     2   Return domain name and identifier. bufptr points to a 
- *         USER_MODALS_INFO_2 struct.
- *     3   Return lockout information. bufptr points to a USER_MODALS_INFO_3
- *         struct.
- *  pbuffer    [I] Buffer that receives the data.
- *
- * RETURNS
- *  Success: NERR_Success.
- *  Failure: 
- *     ERROR_ACCESS_DENIED - the user does not have access to the info.
- *     NERR_InvalidComputer - computer name is invalid.
- */
-NET_API_STATUS WINAPI NetUserModalsGet(
-    LPCWSTR szServer, DWORD level, LPBYTE *pbuffer)
-{
-    TRACE("(%s %d %p)\n", debugstr_w(szServer), level, pbuffer);
-    
-    switch (level)
-    {
-        case 0:
-            /* return global passwords parameters */
-            FIXME("level 0 not implemented!\n");
-            *pbuffer = NULL;
-            return NERR_InternalError;
-        case 1:
-            /* return logon server and domain controller info */
-            FIXME("level 1 not implemented!\n");
-            *pbuffer = NULL;
-            return NERR_InternalError;
-        case 2:
-        {
-            /* return domain name and identifier */
-            PUSER_MODALS_INFO_2 umi;
-            LSA_HANDLE policyHandle;
-            LSA_OBJECT_ATTRIBUTES objectAttributes;
-            PPOLICY_ACCOUNT_DOMAIN_INFO domainInfo;
-            NTSTATUS ntStatus;
-            PSID domainIdentifier = NULL;
-            int domainNameLen, domainIdLen;
-
-            ZeroMemory(&objectAttributes, sizeof(objectAttributes));
-            objectAttributes.Length = sizeof(objectAttributes);
-
-            ntStatus = LsaOpenPolicy(NULL, &objectAttributes,
-                                     POLICY_VIEW_LOCAL_INFORMATION,
-                                     &policyHandle);
-            if (ntStatus != STATUS_SUCCESS)
-            {
-                WARN("LsaOpenPolicy failed with NT status %x\n",
-                     LsaNtStatusToWinError(ntStatus));
-                return ntStatus;
-            }
-
-            ntStatus = LsaQueryInformationPolicy(policyHandle,
-                                                 PolicyAccountDomainInformation,
-                                                 (PVOID *)&domainInfo);
-            if (ntStatus != STATUS_SUCCESS)
-            {
-                WARN("LsaQueryInformationPolicy failed with NT status %x\n",
-                     LsaNtStatusToWinError(ntStatus));
-                LsaClose(policyHandle);
-                return ntStatus;
-            }
-
-            domainIdentifier = domainInfo->DomainSid;
-            domainIdLen = (domainIdentifier) ? GetLengthSid(domainIdentifier) : 0;
-            domainNameLen = lstrlenW(domainInfo->DomainName.Buffer) + 1;
-            LsaClose(policyHandle);
-
-            ntStatus = NetApiBufferAllocate(sizeof(USER_MODALS_INFO_2) +
-                                            domainIdLen +
-                                            domainNameLen * sizeof(WCHAR),
-                                            (LPVOID *)pbuffer);
-
-            if (ntStatus != NERR_Success)
-            {
-                WARN("NetApiBufferAllocate() failed\n");
-                LsaFreeMemory(domainInfo);
-                return ntStatus;
-            }
-
-            umi = (USER_MODALS_INFO_2 *) *pbuffer;
-            umi->usrmod2_domain_id = (domainIdLen > 0) ? (*pbuffer + sizeof(USER_MODALS_INFO_2)) : NULL;
-            umi->usrmod2_domain_name = (LPWSTR)(*pbuffer +
-                sizeof(USER_MODALS_INFO_2) + domainIdLen);
-
-            lstrcpynW(umi->usrmod2_domain_name,
-                      domainInfo->DomainName.Buffer,
-                      domainNameLen);
-            if (domainIdLen > 0)
-                CopySid(GetLengthSid(domainIdentifier), umi->usrmod2_domain_id,
-                        domainIdentifier);
-
-            LsaFreeMemory(domainInfo);
-
-            break;
-        } 
-        case 3:
-            /* return lockout information */
-            FIXME("level 3 not implemented!\n");
-            *pbuffer = NULL;
-            return NERR_InternalError;
-        default:
-            TRACE("Invalid level %d is specified\n", level);
-            *pbuffer = NULL;
-            return ERROR_INVALID_LEVEL;
-    }
-
-    return NERR_Success;
-}
 
 NET_API_STATUS WINAPI NetUseAdd(LMSTR servername, DWORD level, LPBYTE bufptr, LPDWORD parm_err)
 {
index 20ac5fe..2f518b5 100644 (file)
 @ stdcall NetUserGetInfo(wstr wstr long ptr)
 @ stdcall NetUserGetLocalGroups(wstr wstr long long ptr long ptr ptr)
 @ stdcall NetUserModalsGet(wstr long ptr)
-@ stub NetUserModalsSet
+@ stdcall NetUserModalsSet(wstr long ptr ptr)
 @ stdcall NetUserSetGroups(wstr wstr long ptr long)
 @ stdcall NetUserSetInfo(wstr wstr long ptr ptr)
 @ stdcall NetWkstaGetInfo(wstr long ptr)
index 7b5389a..dcd313d 100644 (file)
@@ -47,6 +47,24 @@ typedef struct _ENUM_CONTEXT
 } ENUM_CONTEXT, *PENUM_CONTEXT;
 
 
+static
+ULONG
+DeltaTimeToSeconds(LARGE_INTEGER DeltaTime)
+{
+    LARGE_INTEGER Seconds;
+
+    if (DeltaTime.QuadPart == 0)
+        return 0;
+
+    Seconds.QuadPart = -DeltaTime.QuadPart / 10000000;
+
+    if (Seconds.HighPart != 0)
+        return TIMEQ_FOREVER;
+
+    return Seconds.LowPart;
+}
+
+
 static
 ULONG
 GetAccountFlags(ULONG AccountControl)
@@ -3058,6 +3076,332 @@ done:
 }
 
 
+/******************************************************************************
+ * NetUserModalsGet  (NETAPI32.@)
+ *
+ * Retrieves global information for all users and global groups in the security
+ * database.
+ *
+ * PARAMS
+ *  servername [I] Specifies the DNS or the NetBIOS name of the remote server
+ *                 on which the function is to execute.
+ *  level      [I] Information level of the data.
+ *     0   Return global passwords parameters. bufptr points to a
+ *         USER_MODALS_INFO_0 struct.
+ *     1   Return logon server and domain controller information. bufptr
+ *         points to a USER_MODALS_INFO_1 struct.
+ *     2   Return domain name and identifier. bufptr points to a 
+ *         USER_MODALS_INFO_2 struct.
+ *     3   Return lockout information. bufptr points to a USER_MODALS_INFO_3
+ *         struct.
+ *  bufptr     [O] Buffer that receives the data.
+ *
+ * RETURNS
+ *  Success: NERR_Success.
+ *  Failure: 
+ *     ERROR_ACCESS_DENIED - the user does not have access to the info.
+ *     NERR_InvalidComputer - computer name is invalid.
+ */
+NET_API_STATUS
+WINAPI
+NetUserModalsGet(LPCWSTR servername,
+                 DWORD level,
+                 LPBYTE *bufptr)
+{
+    UNICODE_STRING ServerName;
+    SAM_HANDLE ServerHandle = NULL;
+    SAM_HANDLE DomainHandle = NULL;
+    PSID DomainSid = NULL;
+    PDOMAIN_PASSWORD_INFORMATION PasswordInfo = NULL;
+    PDOMAIN_LOGOFF_INFORMATION LogoffInfo = NULL;
+    PDOMAIN_SERVER_ROLE_INFORMATION ServerRoleInfo = NULL;
+    PDOMAIN_REPLICATION_INFORMATION ReplicationInfo = NULL;
+    PDOMAIN_NAME_INFORMATION NameInfo = NULL;
+    PDOMAIN_LOCKOUT_INFORMATION LockoutInfo = NULL;
+    ULONG DesiredAccess;
+    ULONG BufferSize;
+    PUSER_MODALS_INFO_0 umi0;
+    PUSER_MODALS_INFO_1 umi1;
+    PUSER_MODALS_INFO_2 umi2;
+    PUSER_MODALS_INFO_3 umi3;
+    NET_API_STATUS ApiStatus = NERR_Success;
+    NTSTATUS Status = STATUS_SUCCESS;
+
+    TRACE("(%s %d %p)\n", debugstr_w(servername), level, bufptr);
+
+    *bufptr = NULL;
+
+    if (servername != NULL)
+        RtlInitUnicodeString(&ServerName, servername);
+
+    /* Connect to the SAM Server */
+    Status = SamConnect((servername != NULL) ? &ServerName : NULL,
+                        &ServerHandle,
+                        SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
+                        NULL);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("SamConnect failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
+    }
+
+    /* Get the Account Domain SID */
+    Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
+                                 &DomainSid);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
+    }
+
+    switch (level)
+    {
+        case 0:
+            DesiredAccess = DOMAIN_READ_OTHER_PARAMETERS | DOMAIN_READ_PASSWORD_PARAMETERS;
+            break;
+
+        case 1:
+            DesiredAccess = DOMAIN_READ_OTHER_PARAMETERS;
+            break;
+
+        case 2:
+            DesiredAccess = DOMAIN_READ_OTHER_PARAMETERS;
+            break;
+
+        case 3:
+            DesiredAccess = DOMAIN_READ_PASSWORD_PARAMETERS;
+            break;
+
+        default:
+            ApiStatus = ERROR_INVALID_LEVEL;
+            goto done;
+    }
+
+    /* Open the Account Domain */
+    Status = SamOpenDomain(ServerHandle,
+                           DesiredAccess,
+                           DomainSid,
+                           &DomainHandle);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
+        ApiStatus = NetpNtStatusToApiStatus(Status);
+        goto done;
+    }
+
+    switch (level)
+    {
+        case 0:
+            /* return global passwords parameters */
+            Status = SamQueryInformationDomain(DomainHandle,
+                                               DomainPasswordInformation,
+                                               (PVOID*)&PasswordInfo);
+            if (!NT_SUCCESS(Status))
+            {
+                ApiStatus = NetpNtStatusToApiStatus(Status);
+                goto done;
+            }
+
+            Status = SamQueryInformationDomain(DomainHandle,
+                                               DomainLogoffInformation,
+                                               (PVOID*)&LogoffInfo);
+            if (!NT_SUCCESS(Status))
+            {
+                ApiStatus = NetpNtStatusToApiStatus(Status);
+                goto done;
+            }
+
+            BufferSize = sizeof(USER_MODALS_INFO_0);
+            break;
+
+        case 1:
+            /* return logon server and domain controller info */
+            Status = SamQueryInformationDomain(DomainHandle,
+                                               DomainServerRoleInformation,
+                                               (PVOID*)&ServerRoleInfo);
+            if (!NT_SUCCESS(Status))
+            {
+                ApiStatus = NetpNtStatusToApiStatus(Status);
+                goto done;
+            }
+
+            Status = SamQueryInformationDomain(DomainHandle,
+                                               DomainReplicationInformation,
+                                               (PVOID*)&ReplicationInfo);
+            if (!NT_SUCCESS(Status))
+            {
+                ApiStatus = NetpNtStatusToApiStatus(Status);
+                goto done;
+            }
+
+            BufferSize = sizeof(USER_MODALS_INFO_1) +
+                         ReplicationInfo->ReplicaSourceNodeName.Length + sizeof(WCHAR);
+            break;
+
+        case 2:
+            /* return domain name and identifier */
+            Status = SamQueryInformationDomain(DomainHandle,
+                                               DomainNameInformation,
+                                               (PVOID*)&NameInfo);
+            if (!NT_SUCCESS(Status))
+            {
+                ApiStatus = NetpNtStatusToApiStatus(Status);
+                goto done;
+            }
+
+            BufferSize = sizeof( USER_MODALS_INFO_2 ) +
+                         NameInfo->DomainName.Length + sizeof(WCHAR) +
+                         RtlLengthSid(DomainSid);
+            break;
+
+        case 3:
+            /* return lockout information */
+            Status = SamQueryInformationDomain(DomainHandle,
+                                               DomainLockoutInformation,
+                                               (PVOID*)&LockoutInfo);
+            if (!NT_SUCCESS(Status))
+            {
+                ApiStatus = NetpNtStatusToApiStatus(Status);
+                goto done;
+            }
+
+            BufferSize = sizeof(USER_MODALS_INFO_3);
+            break;
+
+        default:
+            TRACE("Invalid level %d is specified\n", level);
+            ApiStatus = ERROR_INVALID_LEVEL;
+            goto done;
+    }
+
+
+    ApiStatus = NetApiBufferAllocate(BufferSize,
+                                     (LPVOID *)bufptr);
+    if (ApiStatus != NERR_Success)
+    {
+        WARN("NetApiBufferAllocate() failed\n");
+        goto done;
+    }
+
+    switch (level)
+    {
+        case 0:
+            umi0 = (PUSER_MODALS_INFO_0)*bufptr;
+
+            umi0->usrmod0_min_passwd_len = PasswordInfo->MinPasswordLength;
+            umi0->usrmod0_max_passwd_age = (ULONG)(PasswordInfo->MaxPasswordAge.QuadPart / 10000000);
+            umi0->usrmod0_min_passwd_age =
+                DeltaTimeToSeconds(PasswordInfo->MinPasswordAge);
+            umi0->usrmod0_force_logoff =
+                DeltaTimeToSeconds(LogoffInfo->ForceLogoff);
+            umi0->usrmod0_password_hist_len = PasswordInfo->PasswordHistoryLength;
+            break;
+
+        case 1:
+            umi1 = (PUSER_MODALS_INFO_1)*bufptr;
+
+            switch (ServerRoleInfo->DomainServerRole)
+            {
+
+                    umi1->usrmod1_role = UAS_ROLE_STANDALONE;
+                    umi1->usrmod1_role = UAS_ROLE_MEMBER;
+
+                case DomainServerRolePrimary:
+                    umi1->usrmod1_role = UAS_ROLE_PRIMARY;
+                    break;
+
+                case DomainServerRoleBackup:
+                    umi1->usrmod1_role = UAS_ROLE_BACKUP;
+                    break;
+
+                default:
+                    ApiStatus = NERR_InternalError;
+                    goto done;
+            }
+
+            umi1->usrmod1_primary = (LPWSTR)(*bufptr + sizeof(USER_MODALS_INFO_1));
+            RtlCopyMemory(umi1->usrmod1_primary,
+                          ReplicationInfo->ReplicaSourceNodeName.Buffer,
+                          ReplicationInfo->ReplicaSourceNodeName.Length);
+            umi1->usrmod1_primary[ReplicationInfo->ReplicaSourceNodeName.Length / sizeof(WCHAR)] = UNICODE_NULL;
+            break;
+
+        case 2:
+            umi2 = (PUSER_MODALS_INFO_2)*bufptr;
+
+            umi2->usrmod2_domain_name = (LPWSTR)(*bufptr + sizeof(USER_MODALS_INFO_2));
+            RtlCopyMemory(umi2->usrmod2_domain_name,
+                          NameInfo->DomainName.Buffer,
+                          NameInfo->DomainName.Length);
+            umi2->usrmod2_domain_name[NameInfo->DomainName.Length / sizeof(WCHAR)] = UNICODE_NULL;
+
+            umi2->usrmod2_domain_id = *bufptr +
+                                      sizeof(USER_MODALS_INFO_2) +
+                                      NameInfo->DomainName.Length + sizeof(WCHAR);
+            RtlCopyMemory(umi2->usrmod2_domain_id,
+                          DomainSid,
+                          RtlLengthSid(DomainSid));
+            break;
+
+        case 3:
+            umi3 = (PUSER_MODALS_INFO_3)*bufptr;
+            umi3->usrmod3_lockout_duration =
+                DeltaTimeToSeconds(LockoutInfo->LockoutDuration);
+            umi3->usrmod3_lockout_observation_window =
+                DeltaTimeToSeconds(LockoutInfo->LockoutObservationWindow );
+            umi3->usrmod3_lockout_threshold = LockoutInfo->LockoutThreshold;
+            break;
+    }
+
+done:
+    if (LockoutInfo != NULL)
+        SamFreeMemory(LockoutInfo);
+
+    if (NameInfo != NULL)
+        SamFreeMemory(NameInfo);
+
+    if (ReplicationInfo != NULL)
+        SamFreeMemory(ReplicationInfo);
+
+    if (ServerRoleInfo != NULL)
+        SamFreeMemory(ServerRoleInfo);
+
+    if (LogoffInfo != NULL)
+        SamFreeMemory(LogoffInfo);
+
+    if (PasswordInfo != NULL)
+        SamFreeMemory(PasswordInfo);
+
+    if (DomainSid != NULL)
+        RtlFreeHeap(RtlGetProcessHeap(), 0, DomainSid);
+
+    if (DomainHandle != NULL)
+        SamCloseHandle(DomainHandle);
+
+    if (ServerHandle != NULL)
+        SamCloseHandle(ServerHandle);
+
+    return ApiStatus;
+}
+
+
+/******************************************************************************
+ * NetUserModalsSet  (NETAPI32.@)
+ */
+NET_API_STATUS
+WINAPI
+NetUserModalsSet(IN LPCWSTR servername,
+                 IN DWORD level,
+                 IN LPBYTE buf,
+                 OUT LPDWORD parm_err)
+{
+    FIXME("(%s %d %p %p)\n", debugstr_w(servername), level, buf, parm_err);
+    return ERROR_ACCESS_DENIED;
+}
+
+
 /******************************************************************************
  * NetUserSetGroups  (NETAPI32.@)
  */
index d6beff2..b6bacb0 100644 (file)
@@ -681,7 +681,9 @@ CONFIGRET WINAPI CM_Create_DevNode_ExW(
 
     if (ret == CR_SUCCESS)
     {
-        *pdnDevInst = pSetupStringTableAddString(StringTable, pDeviceID, 1);
+        /* If CM_CREATE_DEVINST_GENERATE_ID was passed in, PNP_CreateDevInst
+         * will return the generated device ID in szLocalDeviceID */
+        *pdnDevInst = pSetupStringTableAddString(StringTable, szLocalDeviceID, 1);
         if (*pdnDevInst == 0)
             ret = CR_NO_SUCH_DEVNODE;
     }
index 05a1c24..3256dbc 100644 (file)
@@ -1727,6 +1727,7 @@ BOOL WINAPI SetupDiCreateDeviceInfoW(
     CONFIGRET cr;
     DEVINST RootDevInst;
     DEVINST DevInst;
+    WCHAR GenInstanceId[MAX_DEVICE_ID_LEN];
 
     TRACE("%p %s %s %s %p %x %p\n", DeviceInfoSet, debugstr_w(DeviceName),
         debugstr_guid(ClassGuid), debugstr_w(DeviceDescription),
@@ -1780,7 +1781,8 @@ BOOL WINAPI SetupDiCreateDeviceInfoW(
     cr = CM_Create_DevInst_ExW(&DevInst,
                                (DEVINSTID)DeviceName,
                                RootDevInst,
-                               0,
+                               (CreationFlags & DICD_GENERATE_ID) ?
+                                     CM_CREATE_DEVINST_GENERATE_ID : 0,
                                set->hMachine);
     if (cr != CR_SUCCESS)
     {
@@ -1788,6 +1790,24 @@ BOOL WINAPI SetupDiCreateDeviceInfoW(
         return FALSE;
     }
 
+    if (CreationFlags & DICD_GENERATE_ID)
+    {
+        /* Grab the actual instance ID that was created */
+        cr = CM_Get_Device_ID_Ex(DevInst,
+                                 GenInstanceId,
+                                 MAX_DEVICE_ID_LEN,
+                                 0,
+                                 set->hMachine);
+        if (cr != CR_SUCCESS)
+        {
+            SetLastError(GetErrorCodeFromCrCode(cr));
+            return FALSE;
+        }
+
+        DeviceName = GenInstanceId;
+        TRACE("Using generated instance ID: %s\n", debugstr_w(DeviceName));
+    }
+
     if (CreateDeviceInfo(set, DeviceName, ClassGuid, &deviceInfo))
     {
         InsertTailList(&set->ListHead, &deviceInfo->ListEntry);
@@ -1891,7 +1911,8 @@ BOOL WINAPI SetupDiRegisterDeviceInfo(
                               ParentDevInst,
                               CM_CREATE_DEVINST_NORMAL | CM_CREATE_DEVINST_DO_NOT_INSTALL,
                               set->hMachine);
-    if (cr != CR_SUCCESS)
+    if (cr != CR_SUCCESS &&
+        cr != CR_ALREADY_SUCH_DEVINST)
     {
         dwError = ERROR_NO_SUCH_DEVINST;
     }
index b473613..d6bd215 100644 (file)
@@ -1,6 +1,6 @@
 #pragma once
 
-#ifdef i386
+#if defined(i386) || defined(_AMD64_) || defined(_ARM_)
 
 /* DWORD network to host byte order conversion for i386 */
 #define DN2H(dw) \
@@ -26,7 +26,7 @@
        ((((w) & 0xFF00) >> 8) | \
         (((w) & 0x00FF) << 8))
 
-#else /* i386 */
+#else /* defined(i386) || defined(_AMD64_) || defined(_ARM_) */
 
 /* DWORD network to host byte order conversion for other architectures */
 #define DN2H(dw) \
@@ -44,4 +44,4 @@
 #define WH2N(w) \
     (w)
 
-#endif /* i386 */
+#endif /* defined(i386) || defined(_AMD64_) || defined(_ARM_) */
index 33acb9c..5283ccd 100644 (file)
@@ -35,4 +35,6 @@ NTSTATUS FileOpenControlChannel(
 NTSTATUS FileCloseControlChannel(
   PTDI_REQUEST Request);
 
+VOID LogActiveObjects(VOID);
+
 /* EOF */
index ce6f84b..c31293c 100644 (file)
@@ -211,3 +211,6 @@ VOID
 FlushAllQueues(PCONNECTION_ENDPOINT Connection, NTSTATUS Status);
 
 VOID CompleteBucket(PCONNECTION_ENDPOINT Connection, PTDI_BUCKET Bucket, const BOOLEAN Synchronous);
+
+void
+LibTCPDumpPcb(PVOID SocketContext);
index 9b07784..88c7e06 100644 (file)
@@ -65,7 +65,7 @@
 #define NDIS_BUFFER_TAG FOURCC('n','b','u','f')
 #define NDIS_PACKET_TAG FOURCC('n','p','k','t')
 
-#ifdef i386
+#if defined(i386) || defined(_AMD64_) || defined(_ARM_)
 
 /* DWORD network to host byte order conversion for i386 */
 #define DN2H(dw) \
@@ -91,7 +91,9 @@
        ((((w) & 0xFF00) >> 8) | \
         (((w) & 0x00FF) << 8))
 
-#else /* i386 */
+#else /* defined(i386) || defined(_AMD64_) || defined(_ARM_) */
+
+#error Unsupported architecture
 
 /* DWORD network to host byte order conversion for other architectures */
 #define DN2H(dw) \
 #define WH2N(w) \
     (w)
 
-#endif /* i386 */
+#endif /* defined(i386) || defined(_AMD64_) || defined(_ARM_) */
 
 /* AF_INET and other things Arty likes to use ;) */
 #define AF_INET 2
@@ -148,7 +150,7 @@ typedef struct {
 } TDIEntityInfo;
 
 #ifndef htons
-#define htons(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff))
+#define htons(x) WH2N(x)
 #endif
 
 /* Global variable */
index e9380ff..70ba4ea 100644 (file)
@@ -281,6 +281,7 @@ typedef struct _CONNECTION_ENDPOINT {
     BOOLEAN SendShutdown;
     BOOLEAN ReceiveShutdown;
     NTSTATUS ReceiveShutdownStatus;
+    BOOLEAN Closing;
 
     struct _CONNECTION_ENDPOINT *Next; /* Next connection in address file list */
 } CONNECTION_ENDPOINT, *PCONNECTION_ENDPOINT;
index 7ef8c7d..bd696b7 100644 (file)
@@ -10,6 +10,8 @@
 
 #include "precomp.h"
 
+/* Uncomment for logging of connections and address files every 10 seconds */
+//#define LOG_OBJECTS
 
 /* List of all address file objects managed by this driver */
 LIST_ENTRY AddressFileListHead;
@@ -99,6 +101,88 @@ BOOLEAN AddrReceiveMatch(
    return FALSE;
 }
 
+VOID
+LogActiveObjects(VOID)
+{
+#ifdef LOG_OBJECTS
+    PLIST_ENTRY CurrentEntry;
+    KIRQL OldIrql;
+    PADDRESS_FILE AddrFile;
+    PCONNECTION_ENDPOINT Conn;
+
+    DbgPrint("----------- TCP/IP Active Object Dump -------------\n");
+    
+    TcpipAcquireSpinLock(&AddressFileListLock, &OldIrql);
+
+    CurrentEntry = AddressFileListHead.Flink;
+    while (CurrentEntry != &AddressFileListHead)
+    {
+        AddrFile = CONTAINING_RECORD(CurrentEntry, ADDRESS_FILE, ListEntry);
+
+        DbgPrint("Address File (%s, %d, %d) @ 0x%p | Ref count: %d | Sharers: %d\n",
+                 A2S(&AddrFile->Address), WN2H(AddrFile->Port), AddrFile->Protocol,
+                 AddrFile, AddrFile->RefCount, AddrFile->Sharers);
+        DbgPrint("\tListener: ");
+        if (AddrFile->Listener == NULL)
+            DbgPrint("<None>\n");
+        else
+            DbgPrint("0x%p\n", AddrFile->Listener);
+        DbgPrint("\tAssociated endpoints: ");
+        if (AddrFile->Connection == NULL)
+            DbgPrint("<None>\n");
+        else
+        {
+            Conn = AddrFile->Connection;
+            while (Conn)
+            {
+                DbgPrint("0x%p ", Conn);
+                Conn = Conn->Next;
+            }
+            DbgPrint("\n");
+        }
+        
+        CurrentEntry = CurrentEntry->Flink;
+    }
+    
+    TcpipReleaseSpinLock(&AddressFileListLock, OldIrql);
+    
+    TcpipAcquireSpinLock(&ConnectionEndpointListLock, &OldIrql);
+    
+    CurrentEntry = ConnectionEndpointListHead.Flink;
+    while (CurrentEntry != &ConnectionEndpointListHead)
+    {
+        Conn = CONTAINING_RECORD(CurrentEntry, CONNECTION_ENDPOINT, ListEntry);
+        
+        DbgPrint("Connection @ 0x%p | Ref count: %d\n", Conn, Conn->RefCount);
+        DbgPrint("\tPCB: ");
+        if (Conn->SocketContext == NULL)
+            DbgPrint("<None>\n");
+        else
+        {
+            DbgPrint("0x%p\n", Conn->SocketContext);
+            LibTCPDumpPcb(Conn->SocketContext);
+        }
+        DbgPrint("\tPacket queue status: %s\n", IsListEmpty(&Conn->PacketQueue) ? "Empty" : "Not Empty");
+        DbgPrint("\tRequest lists: Connect: %s | Recv: %s | Send: %s | Shutdown: %s | Listen: %s\n",
+                 IsListEmpty(&Conn->ConnectRequest) ? "Empty" : "Not Empty",
+                 IsListEmpty(&Conn->ReceiveRequest) ? "Empty" : "Not Empty",
+                 IsListEmpty(&Conn->SendRequest) ? "Empty" : "Not Empty",
+                 IsListEmpty(&Conn->ShutdownRequest) ? "Empty" : "Not Empty",
+                 IsListEmpty(&Conn->ListenRequest) ? "Empty" : "Not Empty");
+        DbgPrint("\tSend shutdown: %s\n", Conn->SendShutdown ? "Yes" : "No");
+        DbgPrint("\tReceive shutdown: %s\n", Conn->ReceiveShutdown ? "Yes" : "No");
+        if (Conn->ReceiveShutdown) DbgPrint("\tReceive shutdown status: 0x%x\n", Conn->ReceiveShutdownStatus);
+        DbgPrint("\tClosing: %s\n", Conn->Closing ? "Yes" : "No");
+        
+        CurrentEntry = CurrentEntry->Flink;
+    }
+    
+    TcpipReleaseSpinLock(&ConnectionEndpointListLock, OldIrql);
+
+    DbgPrint("---------------------------------------------------\n");
+#endif
+}
+
 PADDRESS_FILE AddrFindShared(
     PIP_ADDRESS BindAddress,
     USHORT Port,
index 60f5ea9..00ef94d 100644 (file)
@@ -88,6 +88,14 @@ __INTRIN_INLINE void* memcpy(void* dest, const void* source, size_t num)
 
 /*** Memory barriers ***/
 
+__INTRIN_INLINE void _ReadWriteBarrier(void);
+__INTRIN_INLINE void _mm_mfence(void);
+__INTRIN_INLINE void _mm_lfence(void);
+__INTRIN_INLINE void _mm_sfence(void);
+#ifdef __x86_64__
+__INTRIN_INLINE void __faststorefence(void);
+#endif
+
 __INTRIN_INLINE void _ReadWriteBarrier(void)
 {
        __asm__ __volatile__("" : : : "memory");
@@ -127,8 +135,47 @@ __INTRIN_INLINE void __faststorefence(void)
 
 /*** Atomic operations ***/
 
+__INTRIN_INLINE long _InterlockedAddLargeStatistic(volatile long long * const Addend, const long Value);
+__INTRIN_INLINE unsigned char _interlockedbittestandreset(volatile long * a, const long b);
+__INTRIN_INLINE unsigned char _interlockedbittestandset(volatile long * a, const long b);
+#if defined(_M_AMD64)
+__INTRIN_INLINE unsigned char _interlockedbittestandreset64(volatile long long * a, const long long b);
+__INTRIN_INLINE unsigned char _interlockedbittestandset64(volatile long long * a, const long long b);
+#endif
+
 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100
 
+__INTRIN_INLINE char _InterlockedCompareExchange8(volatile char * const Destination, const char Exchange, const char Comperand);
+__INTRIN_INLINE short _InterlockedCompareExchange16(volatile short * const Destination, const short Exchange, const short Comperand);
+__INTRIN_INLINE long _InterlockedCompareExchange(volatile long * const Destination, const long Exchange, const long Comperand);
+__INTRIN_INLINE void * _InterlockedCompareExchangePointer(void * volatile * const Destination, void * const Exchange, void * const Comperand);
+__INTRIN_INLINE long _InterlockedExchange(volatile long * const Target, const long Value);
+__INTRIN_INLINE void * _InterlockedExchangePointer(void * volatile * const Target, void * const Value);
+__INTRIN_INLINE long _InterlockedExchangeAdd16(volatile short * const Addend, const short Value);
+__INTRIN_INLINE long _InterlockedExchangeAdd(volatile long * const Addend, const long Value);
+__INTRIN_INLINE char _InterlockedAnd8(volatile char * const value, const char mask);
+__INTRIN_INLINE short _InterlockedAnd16(volatile short * const value, const short mask);
+__INTRIN_INLINE long _InterlockedAnd(volatile long * const value, const long mask);
+__INTRIN_INLINE char _InterlockedOr8(volatile char * const value, const char mask);
+__INTRIN_INLINE short _InterlockedOr16(volatile short * const value, const short mask);
+__INTRIN_INLINE long _InterlockedOr(volatile long * const value, const long mask);
+__INTRIN_INLINE char _InterlockedXor8(volatile char * const value, const char mask);
+__INTRIN_INLINE short _InterlockedXor16(volatile short * const value, const short mask);
+__INTRIN_INLINE long _InterlockedXor(volatile long * const value, const long mask);
+__INTRIN_INLINE long _InterlockedDecrement(volatile long * const lpAddend);
+__INTRIN_INLINE long _InterlockedIncrement(volatile long * const lpAddend);
+__INTRIN_INLINE short _InterlockedDecrement16(volatile short * const lpAddend);
+__INTRIN_INLINE short _InterlockedIncrement16(volatile short * const lpAddend);
+#if defined(_M_AMD64)
+__INTRIN_INLINE long long _InterlockedExchange64(volatile long long * const Target, const long long Value);
+__INTRIN_INLINE long long _InterlockedExchangeAdd64(volatile long long * const Addend, const long long Value);
+__INTRIN_INLINE long long _InterlockedAnd64(volatile long long * const value, const long long mask);
+__INTRIN_INLINE long long _InterlockedOr64(volatile long long * const value, const long long mask);
+__INTRIN_INLINE long long _InterlockedXor64(volatile long long * const value, const long long mask);
+__INTRIN_INLINE long long _InterlockedDecrement64(volatile long long * const lpAddend);
+__INTRIN_INLINE long long _InterlockedIncrement64(volatile long long * const lpAddend);
+#endif
+
 __INTRIN_INLINE char _InterlockedCompareExchange8(volatile char * const Destination, const char Exchange, const char Comperand)
 {
        return __sync_val_compare_and_swap(Destination, Comperand, Exchange);
@@ -287,7 +334,33 @@ __INTRIN_INLINE long long _InterlockedIncrement64(volatile long long * const lpA
 }
 #endif
 
-#else
+#else /* (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100 */
+
+__INTRIN_INLINE char _InterlockedCompareExchange8(volatile char * const Destination, const char Exchange, const char Comperand);
+__INTRIN_INLINE short _InterlockedCompareExchange16(volatile short * const Destination, const short Exchange, const short Comperand);
+__INTRIN_INLINE long _InterlockedCompareExchange(volatile long * const Destination, const long Exchange, const long Comperand);
+__INTRIN_INLINE void * _InterlockedCompareExchangePointer(void * volatile * const Destination, void * const Exchange, void * const Comperand);
+__INTRIN_INLINE long _InterlockedExchange(volatile long * const Target, const long Value);
+__INTRIN_INLINE void * _InterlockedExchangePointer(void * volatile * const Target, void * const Value);
+__INTRIN_INLINE long _InterlockedExchangeAdd16(volatile short * const Addend, const short Value);
+__INTRIN_INLINE long _InterlockedExchangeAdd(volatile long * const Addend, const long Value);
+__INTRIN_INLINE char _InterlockedAnd8(volatile char * const value, const char mask);
+__INTRIN_INLINE short _InterlockedAnd16(volatile short * const value, const short mask);
+__INTRIN_INLINE long _InterlockedAnd(volatile long * const value, const long mask);
+__INTRIN_INLINE char _InterlockedOr8(volatile char * const value, const char mask);
+__INTRIN_INLINE short _InterlockedOr16(volatile short * const value, const short mask);
+__INTRIN_INLINE long _InterlockedOr(volatile long * const value, const long mask);
+__INTRIN_INLINE char _InterlockedXor8(volatile char * const value, const char mask);
+__INTRIN_INLINE short _InterlockedXor16(volatile short * const value, const short mask);
+__INTRIN_INLINE long _InterlockedXor(volatile long * const value, const long mask);
+__INTRIN_INLINE long _InterlockedDecrement(volatile long * const lpAddend);
+__INTRIN_INLINE long _InterlockedIncrement(volatile long * const lpAddend);
+__INTRIN_INLINE short _InterlockedDecrement16(volatile short * const lpAddend);
+__INTRIN_INLINE short _InterlockedIncrement16(volatile short * const lpAddend);
+#if defined(_M_AMD64)
+__INTRIN_INLINE long long _InterlockedDecrement64(volatile long long * const lpAddend);
+__INTRIN_INLINE long long _InterlockedIncrement64(volatile long long * const lpAddend);
+#endif
 
 __INTRIN_INLINE char _InterlockedCompareExchange8(volatile char * const Destination, const char Exchange, const char Comperand)
 {
@@ -530,10 +603,11 @@ __INTRIN_INLINE long long _InterlockedIncrement64(volatile long long * const lpA
 }
 #endif
 
-#endif
+#endif /* (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100 */
 
 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100 && defined(__x86_64__)
 
+__INTRIN_INLINE long long _InterlockedCompareExchange64(volatile long long * const Destination, const long long Exchange, const long long Comperand);
 __INTRIN_INLINE long long _InterlockedCompareExchange64(volatile long long * const Destination, const long long Exchange, const long long Comperand)
 {
        return __sync_val_compare_and_swap(Destination, Comperand, Exchange);
@@ -541,6 +615,7 @@ __INTRIN_INLINE long long _InterlockedCompareExchange64(volatile long long * con
 
 #else
 
+__INTRIN_INLINE long long _InterlockedCompareExchange64(volatile long long * const Destination, const long long Exchange, const long long Comperand);
 __INTRIN_INLINE long long _InterlockedCompareExchange64(volatile long long * const Destination, const long long Exchange, const long long Comperand)
 {
        long long retval = Comperand;
@@ -609,6 +684,19 @@ __INTRIN_INLINE unsigned char _interlockedbittestandset64(volatile long long * a
 #endif
 
 /*** String operations ***/
+
+__INTRIN_INLINE void __stosb(unsigned char * Dest, const unsigned char Data, size_t Count);
+__INTRIN_INLINE void __stosw(unsigned short * Dest, const unsigned short Data, size_t Count);
+__INTRIN_INLINE void __stosd(unsigned long * Dest, const unsigned long Data, size_t Count);
+__INTRIN_INLINE void __movsb(unsigned char * Destination, const unsigned char * Source, size_t Count);
+__INTRIN_INLINE void __movsw(unsigned short * Destination, const unsigned short * Source, size_t Count);
+__INTRIN_INLINE void __movsd(unsigned long * Destination, const unsigned long * Source, size_t Count);
+#ifdef _M_AMD64
+__INTRIN_INLINE void __stosq(unsigned __int64 * Dest, const unsigned __int64 Data, size_t Count);
+__INTRIN_INLINE void __movsq(unsigned long * Destination, const unsigned long * Source, size_t Count);
+#endif
+
+
 /* NOTE: we don't set a memory clobber in the __stosX functions because Visual C++ doesn't */
 __INTRIN_INLINE void __stosb(unsigned char * Dest, const unsigned char Data, size_t Count)
 {
@@ -695,8 +783,26 @@ __INTRIN_INLINE void __movsq(unsigned long * Destination, const unsigned long *
 #endif
 
 #if defined(_M_AMD64)
+
 /*** GS segment addressing ***/
 
+__INTRIN_INLINE void __writegsbyte(const unsigned long Offset, const unsigned char Data);
+__INTRIN_INLINE void __writegsword(const unsigned long Offset, const unsigned short Data);
+__INTRIN_INLINE void __writegsdword(const unsigned long Offset, const unsigned long Data);
+__INTRIN_INLINE void __writegsqword(const unsigned long Offset, const unsigned __int64 Data);
+__INTRIN_INLINE unsigned char __readgsbyte(const unsigned long Offset);
+__INTRIN_INLINE unsigned short __readgsword(const unsigned long Offset);
+__INTRIN_INLINE unsigned long __readgsdword(const unsigned long Offset);
+__INTRIN_INLINE unsigned __int64 __readgsqword(const unsigned long Offset);
+__INTRIN_INLINE void __incgsbyte(const unsigned long Offset);
+__INTRIN_INLINE void __incgsword(const unsigned long Offset);
+__INTRIN_INLINE void __incgsdword(const unsigned long Offset);
+__INTRIN_INLINE void __addgsbyte(const unsigned long Offset, const unsigned char Data);
+__INTRIN_INLINE void __addgsword(const unsigned long Offset, const unsigned short Data);
+__INTRIN_INLINE void __addgsdword(const unsigned long Offset, const unsigned int Data);
+__INTRIN_INLINE void __addgsqword(const unsigned long Offset, const unsigned __int64 Data);
+
+
 __INTRIN_INLINE void __writegsbyte(const unsigned long Offset, const unsigned char Data)
 {
        __asm__ __volatile__("movb %b[Data], %%gs:%a[Offset]" : : [Offset] "ir" (Offset), [Data] "ir" (Data) : "memory");
@@ -780,8 +886,24 @@ __INTRIN_INLINE void __addgsqword(const unsigned long Offset, const unsigned __i
        __asm__ __volatile__("addq %k[Data], %%gs:%a[Offset]" : : [Offset] "ir" (Offset), [Data] "ir" (Data) : "memory");
 }
 
-#else
+#else /* defined(_M_AMD64) */
+
 /*** FS segment addressing ***/
+
+__INTRIN_INLINE void __writefsbyte(const unsigned long Offset, const unsigned char Data);
+__INTRIN_INLINE void __writefsword(const unsigned long Offset, const unsigned short Data);
+__INTRIN_INLINE void __writefsdword(const unsigned long Offset, const unsigned long Data);
+__INTRIN_INLINE unsigned char __readfsbyte(const unsigned long Offset);
+__INTRIN_INLINE unsigned short __readfsword(const unsigned long Offset);
+__INTRIN_INLINE unsigned long __readfsdword(const unsigned long Offset);
+__INTRIN_INLINE void __incfsbyte(const unsigned long Offset);
+__INTRIN_INLINE void __incfsword(const unsigned long Offset);
+__INTRIN_INLINE void __incfsdword(const unsigned long Offset);
+__INTRIN_INLINE void __addfsbyte(const unsigned long Offset, const unsigned char Data);
+__INTRIN_INLINE void __addfsword(const unsigned long Offset, const unsigned short Data);
+__INTRIN_INLINE void __addfsdword(const unsigned long Offset, const unsigned int Data);
+
+
 __INTRIN_INLINE void __writefsbyte(const unsigned long Offset, const unsigned char Data)
 {
        __asm__ __volatile__("movb %b[Data], %%fs:%a[Offset]" : : [Offset] "ir" (Offset), [Data] "iq" (Data) : "memory");
@@ -857,10 +979,39 @@ __INTRIN_INLINE void __addfsdword(const unsigned long Offset, const unsigned int
        else
                __asm__ __volatile__("addl %k[Data], %%fs:%a[Offset]" : : [Offset] "ir" (Offset), [Data] "iq" (Data) : "memory");
 }
-#endif
+
+#endif /* defined(_M_AMD64) */
 
 
 /*** Bit manipulation ***/
+
+__INTRIN_INLINE unsigned char _BitScanForward(unsigned long * const Index, const unsigned long Mask);
+__INTRIN_INLINE unsigned char _BitScanReverse(unsigned long * const Index, const unsigned long Mask);
+__INTRIN_INLINE unsigned char _bittest(const long * const a, const long b);
+#ifdef _M_AMD64
+__INTRIN_INLINE unsigned char _bittest64(const __int64 * const a, const __int64 b);
+#endif
+__INTRIN_INLINE unsigned char _bittestandcomplement(long * const a, const long b);
+__INTRIN_INLINE unsigned char _bittestandreset(long * const a, const long b);
+__INTRIN_INLINE unsigned char _bittestandset(long * const a, const long b);
+__INTRIN_INLINE unsigned char _rotl8(unsigned char value, unsigned char shift);
+__INTRIN_INLINE unsigned short _rotl16(unsigned short value, unsigned char shift);
+__INTRIN_INLINE unsigned int _rotl(unsigned int value, int shift);
+__INTRIN_INLINE unsigned int _rotr(unsigned int value, int shift);
+__INTRIN_INLINE unsigned char _rotr8(unsigned char value, unsigned char shift);
+__INTRIN_INLINE unsigned short _rotr16(unsigned short value, unsigned char shift);
+__INTRIN_INLINE unsigned long long __ll_lshift(const unsigned long long Mask, const int Bit);
+__INTRIN_INLINE long long __ll_rshift(const long long Mask, const int Bit);
+__INTRIN_INLINE unsigned long long __ull_rshift(const unsigned long long Mask, int Bit);
+__INTRIN_INLINE unsigned short _byteswap_ushort(unsigned short value);
+__INTRIN_INLINE unsigned long _byteswap_ulong(unsigned long value);
+#ifdef _M_AMD64
+__INTRIN_INLINE unsigned __int64 _byteswap_uint64(unsigned __int64 value);
+#else
+__INTRIN_INLINE unsigned __int64 _byteswap_uint64(unsigned __int64 value);
+#endif
+
+
 __INTRIN_INLINE unsigned char _BitScanForward(unsigned long * const Index, const unsigned long Mask)
 {
        __asm__("bsfl %[Mask], %[Index]" : [Index] "=r" (*Index) : [Mask] "mr" (Mask));
@@ -1001,11 +1152,11 @@ __INTRIN_INLINE unsigned long long __ll_lshift(const unsigned long long Mask, co
 
 __INTRIN_INLINE long long __ll_rshift(const long long Mask, const int Bit)
 {
-       unsigned long long retval = Mask;
+       long long retval = Mask;
 
        __asm__
        (
-               "shldl %b[Bit], %%eax, %%edx; sarl %b[Bit], %%eax" :
+               "shrdl %b[Bit], %%edx, %%eax; sarl %b[Bit], %%edx" :
                "+A" (retval) :
                [Bit] "Nc" ((unsigned char)((unsigned long)Bit) & 0xFF)
        );
@@ -1019,7 +1170,7 @@ __INTRIN_INLINE unsigned long long __ull_rshift(const unsigned long long Mask, i
 
        __asm__
        (
-               "shrdl %b[Bit], %%eax, %%edx; shrl %b[Bit], %%eax" :
+               "shrdl %b[Bit], %%edx, %%eax; shrl %b[Bit], %%edx" :
                "+A" (retval) :
                [Bit] "Nc" ((unsigned char)((unsigned long)Bit) & 0xFF)
        );
@@ -1052,7 +1203,7 @@ __INTRIN_INLINE unsigned __int64 _byteswap_uint64(unsigned __int64 value)
 __INTRIN_INLINE unsigned __int64 _byteswap_uint64(unsigned __int64 value)
 {
        union {
-               __int64 int64part;
+               unsigned __int64 int64part;
                struct {
                        unsigned long lowpart;
                        unsigned long hipart;
@@ -1067,6 +1218,15 @@ __INTRIN_INLINE unsigned __int64 _byteswap_uint64(unsigned __int64 value)
 #endif
 
 /*** 64-bit math ***/
+
+__INTRIN_INLINE long long __emul(const int a, const int b);
+__INTRIN_INLINE unsigned long long __emulu(const unsigned int a, const unsigned int b);
+#ifdef _M_AMD64
+__INTRIN_INLINE __int64 __mulh(__int64 a, __int64 b);
+__INTRIN_INLINE unsigned __int64 __umulh(unsigned __int64 a, unsigned __int64 b);
+#endif
+
+
 __INTRIN_INLINE long long __emul(const int a, const int b)
 {
        long long retval;
@@ -1100,6 +1260,27 @@ __INTRIN_INLINE unsigned __int64 __umulh(unsigned __int64 a, unsigned __int64 b)
 #endif
 
 /*** Port I/O ***/
+
+__INTRIN_INLINE unsigned char __inbyte(const unsigned short Port);
+__INTRIN_INLINE unsigned short __inword(const unsigned short Port);
+__INTRIN_INLINE unsigned long __indword(const unsigned short Port);
+__INTRIN_INLINE void __inbytestring(unsigned short Port, unsigned char * Buffer, unsigned long Count);
+__INTRIN_INLINE void __inwordstring(unsigned short Port, unsigned short * Buffer, unsigned long Count);
+__INTRIN_INLINE void __indwordstring(unsigned short Port, unsigned long * Buffer, unsigned long Count);
+__INTRIN_INLINE void __outbyte(unsigned short const Port, const unsigned char Data);
+__INTRIN_INLINE void __outword(unsigned short const Port, const unsigned short Data);
+__INTRIN_INLINE void __outdword(unsigned short const Port, const unsigned long Data);
+__INTRIN_INLINE void __outbytestring(unsigned short const Port, const unsigned char * const Buffer, const unsigned long Count);
+__INTRIN_INLINE void __outwordstring(unsigned short const Port, const unsigned short * const Buffer, const unsigned long Count);
+__INTRIN_INLINE void __outdwordstring(unsigned short const Port, const unsigned long * const Buffer, const unsigned long Count);
+__INTRIN_INLINE int _inp(unsigned short Port);
+__INTRIN_INLINE unsigned short _inpw(unsigned short Port);
+__INTRIN_INLINE unsigned long _inpd(unsigned short Port);
+__INTRIN_INLINE int _outp(unsigned short Port, int databyte);
+__INTRIN_INLINE unsigned short _outpw(unsigned short Port, unsigned short dataword);
+__INTRIN_INLINE unsigned long _outpd(unsigned short Port, unsigned long dataword);
+
+
 __INTRIN_INLINE unsigned char __inbyte(const unsigned short Port)
 {
        unsigned char byte;
@@ -1201,7 +1382,7 @@ __INTRIN_INLINE unsigned long _inpd(unsigned short Port)
 
 __INTRIN_INLINE int _outp(unsigned short Port, int databyte)
 {
-       __outbyte(Port, databyte);
+       __outbyte(Port, (unsigned char)databyte);
        return databyte;
 }
 
@@ -1219,6 +1400,13 @@ __INTRIN_INLINE unsigned long _outpd(unsigned short Port, unsigned long dataword
 
 
 /*** System information ***/
+
+__INTRIN_INLINE void __cpuid(int CPUInfo [], const int InfoType);
+__INTRIN_INLINE unsigned long long __rdtsc(void);
+__INTRIN_INLINE void __writeeflags(uintptr_t Value);
+__INTRIN_INLINE uintptr_t __readeflags(void);
+
+
 __INTRIN_INLINE void __cpuid(int CPUInfo[], const int InfoType)
 {
        __asm__ __volatile__("cpuid" : "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) : "a" (InfoType));
@@ -1250,9 +1438,16 @@ __INTRIN_INLINE uintptr_t __readeflags(void)
 }
 
 /*** Interrupts ***/
+
+__INTRIN_INLINE void __int2c(void);
+__INTRIN_INLINE void _disable(void);
+__INTRIN_INLINE void _enable(void);
+__INTRIN_INLINE void __halt(void);
+
 #ifdef __clang__
 #define __debugbreak() __asm__("int $3")
 #else
+__INTRIN_INLINE void __debugbreak(void);
 __INTRIN_INLINE void __debugbreak(void)
 {
        __asm__("int $3");
@@ -1281,7 +1476,34 @@ __INTRIN_INLINE void __halt(void)
 
 /*** Protected memory management ***/
 
+__INTRIN_INLINE void __invlpg(void * const Address);
+#ifdef _M_AMD64
+__INTRIN_INLINE void __writecr0(const unsigned __int64 Data);
+__INTRIN_INLINE void __writecr3(const unsigned __int64 Data);
+__INTRIN_INLINE void __writecr4(const unsigned __int64 Data);
+__INTRIN_INLINE void __writecr8(const unsigned __int64 Data);
+__INTRIN_INLINE unsigned __int64 __readcr0(void);
+__INTRIN_INLINE unsigned __int64 __readcr2(void);
+__INTRIN_INLINE unsigned __int64 __readcr3(void);
+__INTRIN_INLINE unsigned __int64 __readcr4(void);
+__INTRIN_INLINE unsigned __int64 __readcr8(void);
+__INTRIN_INLINE unsigned __int64 __readdr(unsigned int reg);
+__INTRIN_INLINE void __writedr(unsigned reg, unsigned __int64 value);
+#else /* _M_AMD64 */
+__INTRIN_INLINE void __writecr0(const unsigned int Data);
+__INTRIN_INLINE void __writecr3(const unsigned int Data);
+__INTRIN_INLINE void __writecr4(const unsigned int Data);
+__INTRIN_INLINE unsigned long __readcr0(void);
+__INTRIN_INLINE unsigned long __readcr2(void);
+__INTRIN_INLINE unsigned long __readcr3(void);
+__INTRIN_INLINE unsigned long __readcr4(void);
+__INTRIN_INLINE unsigned int __readdr(unsigned int reg);
+__INTRIN_INLINE void __writedr(unsigned reg, unsigned int value);
+#endif /* _M_AMD64 */
+
+
 #ifdef _M_AMD64
+
 __INTRIN_INLINE void __writecr0(const unsigned __int64 Data)
 {
        __asm__("mov %[Data], %%cr0" : : [Data] "r" (Data) : "memory");
@@ -1336,7 +1558,9 @@ __INTRIN_INLINE unsigned __int64 __readcr8(void)
        __asm__ __volatile__("movq %%cr8, %q[value]" : [value] "=r" (value));
        return value;
 }
-#else
+
+#else /* _M_AMD64 */
+
 __INTRIN_INLINE void __writecr0(const unsigned int Data)
 {
        __asm__("mov %[Data], %%cr0" : : [Data] "r" (Data) : "memory");
@@ -1379,9 +1603,11 @@ __INTRIN_INLINE unsigned long __readcr4(void)
        __asm__ __volatile__("mov %%cr4, %[value]" : [value] "=r" (value));
        return value;
 }
-#endif
+
+#endif /* _M_AMD64 */
 
 #ifdef _M_AMD64
+
 __INTRIN_INLINE unsigned __int64 __readdr(unsigned int reg)
 {
        unsigned __int64 value;
@@ -1445,7 +1671,9 @@ __INTRIN_INLINE void __writedr(unsigned reg, unsigned __int64 value)
                        break;
        }
 }
-#else
+
+#else /* _M_AMD64 */
+
 __INTRIN_INLINE unsigned int __readdr(unsigned int reg)
 {
        unsigned int value;
@@ -1509,7 +1737,8 @@ __INTRIN_INLINE void __writedr(unsigned reg, unsigned int value)
                        break;
        }
 }
-#endif
+
+#endif /* _M_AMD64 */
 
 __INTRIN_INLINE void __invlpg(void * const Address)
 {
@@ -1518,6 +1747,16 @@ __INTRIN_INLINE void __invlpg(void * const Address)
 
 
 /*** System operations ***/
+
+__INTRIN_INLINE unsigned long long __readmsr(const int reg);
+__INTRIN_INLINE void __writemsr(const unsigned long Register, const unsigned long long Value);
+__INTRIN_INLINE unsigned long long __readpmc(const int counter);
+__INTRIN_INLINE unsigned long __segmentlimit(const unsigned long a);
+__INTRIN_INLINE void __wbinvd(void);
+__INTRIN_INLINE void __lidt(void *Source);
+__INTRIN_INLINE void __sidt(void *Destination);
+
+
 __INTRIN_INLINE unsigned long long __readmsr(const int reg)
 {
 #ifdef _M_AMD64
@@ -1572,6 +1811,9 @@ __INTRIN_INLINE void __sidt(void *Destination)
 
 /*** Misc operations ***/
 
+__INTRIN_INLINE void _mm_pause(void);
+__INTRIN_INLINE void __nop(void);
+
 __INTRIN_INLINE void _mm_pause(void)
 {
        __asm__ __volatile__("pause" : : : "memory");
index 343d348..2b2077f 100644 (file)
@@ -3,6 +3,7 @@
  * This file is part of the w64 mingw-runtime package.
  * No warranty is given; refer to the file DISCLAIMER within this package.
  */
+
 #ifndef _INC_TCHAR_S
 #define _INC_TCHAR_S
 
@@ -107,7 +108,7 @@ extern "C" {
 #define _wcsnset_s_l(_Destination,_Destination_size_chars,_Value,_Count,_Locale) (_wcsnset_s(_Destination,_Destination_size_chars,_Value,_Count))
 #define _wcsset_s_l(_Destination,_Destination_size_chars,_Value,_Locale) (_wcsset_s(_Destination,_Destination_size_chars,_Value))
 
-#else
+#else /* _UNICODE */
 
 #define _tprintf_s printf_s
 #define _tprintf_s_l _printf_s_l
@@ -208,28 +209,156 @@ extern "C" {
 
 #define _tccpy_s _mbccpy_s
 #define _tccpy_s_l _mbccpy_s_l
-#else
-
-  _CRTIMP char *__cdecl _tcsncat_s(char *_Dst,size_t _DstSizeInChars,const char *_Src,size_t _MaxCount);
-  _CRTIMP char *__cdecl _tcsncat_s_l(char *_Dst,size_t _DstSizeInChars,const char *_Src,size_t _MaxCount,_locale_t _Locale);
-  _CRTIMP char *__cdecl _tcsncpy_s(char *_Dst,size_t _DstSizeInChars,const char *_Src,size_t _MaxCount);
-  _CRTIMP char *__cdecl _tcsncpy_s_l(char *_Dst,size_t _DstSizeInChars,const char *_Src,size_t _MaxCount,_locale_t _Locale);
-  _CRTIMP char *__cdecl _tcstok_s(char *_Str,const char *_Delim,char **_Context);
-  _CRTIMP char *__cdecl _tcstok_s_l(char *_Str,const char *_Delim,char **_Context,_locale_t _Locale);
-  _CRTIMP errno_t __cdecl _tcsset_s(char *_Str,size_t _SizeInChars,unsigned int _Val);
-  _CRTIMP errno_t __cdecl _tcsset_s_l(char *_Str,size_t _SizeInChars,unsigned int,_locale_t _Locale);
-  _CRTIMP char *__cdecl _tcsnccat_s(char *_Dst,size_t _DstSizeInChars,const char *_Src,size_t _MaxCount);
-  _CRTIMP char *__cdecl _tcsnccat_s_l(char *_Dst,size_t _DstSizeInChars,const char *_Src,size_t _MaxCount,_locale_t _Locale);
-  _CRTIMP char *__cdecl _tcsnccpy_s(char *_Dst,size_t _DstSizeInChars,const char *_Src,size_t _MaxCount);
-  _CRTIMP char *__cdecl _tcsnccpy_s_l(char *_Dst,size_t _DstSizeInChars,const char *_Src,size_t _MaxCount,_locale_t _Locale);
-  _CRTIMP char *__cdecl _tcslwr_s(char *_Str,size_t _SizeInChars);
-  _CRTIMP char *__cdecl _tcslwr_s_l(char *_Str,size_t _SizeInChars,_locale_t _Locale);
-  _CRTIMP char *__cdecl _tcsupr_s(char *_Str,size_t _SizeInChars);
-  _CRTIMP char *__cdecl _tcsupr_s_l(char *_Str,size_t _SizeInChars,_locale_t _Locale);
-
-#endif
 
-#else
+#else /* _MB_MAP_DIRECT */
+
+  _CRTIMP
+  char *
+  __cdecl
+  _tcsncat_s(
+    _Inout_updates_z_(_DstSizeInChars) char *_Dst,
+    _In_ size_t _DstSizeInChars,
+    _In_z_ const char *_Src,
+    _In_ size_t _MaxCount);
+
+  _CRTIMP
+  char *
+  __cdecl
+  _tcsncat_s_l(
+    _Inout_updates_z_(_DstSizeInChars) char *_Dst,
+    _In_ size_t _DstSizeInChars,
+    _In_z_ const char *_Src,
+    _In_ size_t _MaxCount,
+    _In_opt_ _locale_t _Locale);
+
+  _CRTIMP
+  char *
+  __cdecl
+  _tcsncpy_s(
+    _Out_writes_(_DstSizeInChars) char *_Dst,
+    _In_ size_t _DstSizeInChars,
+    _In_z_ const char *_Src,
+    _In_ size_t _MaxCount);
+
+  _CRTIMP
+  char *
+  __cdecl
+  _tcsncpy_s_l(
+    _Out_writes_(_DstSizeInChars) char *_Dst,
+    _In_ size_t _DstSizeInChars,
+    _In_z_ const char *_Src,
+    _In_ size_t _MaxCount,
+    _In_opt_ _locale_t _Locale);
+
+  _Check_return_
+  _CRTIMP
+  char *
+  __cdecl
+  _tcstok_s(
+    _Inout_opt_ char *_Str,
+    _In_z_ const char *_Delim,
+    _Inout_ _Deref_prepost_opt_z_ char **_Context);
+
+  _Check_return_
+  _CRTIMP
+  char *
+  __cdecl
+  _tcstok_s_l(
+    _Inout_opt_ char *_Str,
+    _In_z_ const char *_Delim,
+    _Inout_ _Deref_prepost_opt_z_ char **_Context,
+    _In_opt_ _locale_t _Locale);
+
+  _Check_return_wat_
+  _CRTIMP
+  errno_t
+  __cdecl
+  _tcsset_s(
+    _Inout_updates_z_(_SizeInChars) char *_Str,
+    _In_ size_t _SizeInChars,
+    _In_ unsigned int _Val);
+
+  _Check_return_wat_
+  _CRTIMP
+  errno_t
+  __cdecl
+  _tcsset_s_l(
+    _Inout_updates_z_(_SizeInChars) char *_Str,
+    _In_ size_t _SizeInChars,
+    _In_ unsigned int,
+    _In_opt_ _locale_t _Locale);
+
+  _CRTIMP
+  char *
+  __cdecl
+  _tcsnccat_s(
+    _Inout_updates_z_(_DstSizeInChars) char *_Dst,
+    _In_ size_t _DstSizeInChars,
+    _In_z_ const char *_Src,
+    _In_ size_t _MaxCount);
+
+  _CRTIMP
+  char *
+  __cdecl
+  _tcsnccat_s_l(
+    _Inout_updates_z_(_DstSizeInChars) char *_Dst,
+    _In_ size_t _DstSizeInChars,
+    _In_z_ const char *_Src,
+    _In_ size_t _MaxCount,
+    _In_opt_ _locale_t _Locale);
+
+  _CRTIMP
+  char *
+  __cdecl
+  _tcsnccpy_s(
+    _Out_writes_(_DstSizeInChars) char *_Dst,
+    _In_ size_t _DstSizeInChars,
+    _In_z_ const char *_Src,
+    _In_ size_t _MaxCount);
+
+  _CRTIMP
+  char *
+  __cdecl
+  _tcsnccpy_s_l(
+    _Out_writes_(_DstSizeInChars) char *_Dst,
+    _In_ size_t _DstSizeInChars,
+    _In_z_ const char *_Src,
+    _In_ size_t _MaxCount,
+    _In_opt_ _locale_t _Locale);
+
+  _CRTIMP
+  char *
+  __cdecl
+  _tcslwr_s(
+    _Inout_updates_z_(_SizeInChars) char *_Str,
+    _In_ size_t _SizeInChars);
+
+  _CRTIMP
+  char *
+  __cdecl
+  _tcslwr_s_l(
+    _Inout_updates_z_(_SizeInChars) char *_Str,
+    _In_ size_t _SizeInChars,
+    _In_opt_ _locale_t _Locale);
+
+  _CRTIMP
+  char *
+  __cdecl
+  _tcsupr_s(
+    _Inout_updates_z_(_SizeInChars) char *_Str,
+    _In_ size_t _SizeInChars);
+
+  _CRTIMP
+  char *
+  __cdecl
+  _tcsupr_s_l(
+    _Inout_updates_z_(_SizeInChars) char *_Str,
+    _In_ size_t _SizeInChars,
+    _In_opt_ _locale_t _Locale);
+
+#endif /* _MB_MAP_DIRECT */
+
+#else /* _MBCS */
 
 #define _tcsncat_s strncat_s
 #define _tcsncat_s_l _strncat_s_l
@@ -256,11 +385,15 @@ extern "C" {
 
 #define _strnset_s_l(_Destination,_Destination_size_chars,_Value,_Count,_Locale) (_strnset_s(_Destination,_Destination_size_chars,_Value,_Count))
 #define _strset_s_l(_Destination,_Destination_size_chars,_Value,_Locale) (_strset_s(_Destination,_Destination_size_chars,_Value))
-#endif
-#endif
+
+#endif /* _MBCS */
+
+#endif /* _UNICODE */
 
 #ifdef __cplusplus
 }
 #endif
-#endif
-#endif
+
+#endif /* MINGW_HAS_SECURE_API */
+
+#endif /* _INC_TCHAR_S */
index 3f0996e..f86b292 100644 (file)
@@ -1702,194 +1702,711 @@ typedef struct tagMCI_WAVE_SET_PARMS {
        WORD wReserved5;
 } MCI_WAVE_SET_PARMS,*PMCI_WAVE_SET_PARMS,*LPMCI_WAVE_SET_PARMS;
 
-LRESULT WINAPI CloseDriver(HDRVR,LPARAM,LPARAM);
-HDRVR WINAPI OpenDriver(LPCWSTR,LPCWSTR,LPARAM);
-LRESULT WINAPI SendDriverMessage(HDRVR,UINT,LPARAM,LPARAM);
-HMODULE WINAPI DrvGetModuleHandle(HDRVR);
-HMODULE WINAPI GetDriverModuleHandle(HDRVR);
-LRESULT WINAPI DefDriverProc(DWORD_PTR,HDRVR,UINT,LPARAM,LPARAM);
+LRESULT WINAPI CloseDriver(_In_ HDRVR, _In_ LPARAM, _In_ LPARAM);
+HDRVR WINAPI OpenDriver(_In_ LPCWSTR, _In_ LPCWSTR, _In_ LPARAM);
+LRESULT WINAPI SendDriverMessage(_In_ HDRVR, _In_ UINT, _In_ LPARAM, _In_ LPARAM);
+HMODULE WINAPI DrvGetModuleHandle(_In_ HDRVR);
+HMODULE WINAPI GetDriverModuleHandle(_In_ HDRVR);
+
+LRESULT
+WINAPI
+DefDriverProc(
+  _In_ DWORD_PTR,
+  _In_ HDRVR,
+  _In_ UINT,
+  _In_ LPARAM,
+  _In_ LPARAM);
+
 UINT WINAPI mmsystemGetVersion(void);
 #define OutputDebugStr OutputDebugString
-BOOL WINAPI sndPlaySoundA(LPCSTR,UINT);
-BOOL WINAPI sndPlaySoundW(LPCWSTR,UINT);
-BOOL WINAPI PlaySoundA(LPCSTR,HMODULE,DWORD);
-BOOL WINAPI PlaySoundW(LPCWSTR,HMODULE,DWORD);
+BOOL WINAPI sndPlaySoundA(_In_opt_ LPCSTR, _In_ UINT);
+BOOL WINAPI sndPlaySoundW(_In_opt_ LPCWSTR, _In_ UINT);
+BOOL WINAPI PlaySoundA(_In_opt_ LPCSTR, _In_opt_ HMODULE, _In_ DWORD);
+BOOL WINAPI PlaySoundW(_In_opt_ LPCWSTR, _In_opt_ HMODULE, _In_ DWORD);
 UINT WINAPI waveOutGetNumDevs(void);
-MMRESULT WINAPI waveOutGetDevCapsA(UINT_PTR,LPWAVEOUTCAPSA,UINT);
-MMRESULT WINAPI waveOutGetDevCapsW(UINT_PTR,LPWAVEOUTCAPSW,UINT);
-MMRESULT WINAPI waveOutGetVolume(HWAVEOUT,PDWORD);
-MMRESULT WINAPI waveOutSetVolume(HWAVEOUT,DWORD);
-MMRESULT WINAPI waveOutGetErrorTextA(MMRESULT,LPSTR,UINT);
-MMRESULT WINAPI waveOutGetErrorTextW(MMRESULT,LPWSTR,UINT);
-MMRESULT WINAPI waveOutOpen(LPHWAVEOUT,UINT,LPCWAVEFORMATEX,DWORD_PTR,DWORD_PTR,DWORD);
-MMRESULT WINAPI waveOutClose(HWAVEOUT);
-MMRESULT WINAPI waveOutPrepareHeader(HWAVEOUT,LPWAVEHDR,UINT);
-MMRESULT WINAPI waveOutUnprepareHeader(HWAVEOUT,LPWAVEHDR,UINT);
-MMRESULT WINAPI waveOutWrite(HWAVEOUT,LPWAVEHDR,UINT);
-MMRESULT WINAPI waveOutPause(HWAVEOUT);
-MMRESULT WINAPI waveOutRestart(HWAVEOUT);
-MMRESULT WINAPI waveOutReset(HWAVEOUT);
-MMRESULT WINAPI waveOutBreakLoop(HWAVEOUT);
-MMRESULT WINAPI waveOutGetPosition(HWAVEOUT,LPMMTIME,UINT);
-MMRESULT WINAPI waveOutGetPitch(HWAVEOUT,PDWORD);
-MMRESULT WINAPI waveOutSetPitch(HWAVEOUT,DWORD);
-MMRESULT WINAPI waveOutGetPlaybackRate(HWAVEOUT,PDWORD);
-MMRESULT WINAPI waveOutSetPlaybackRate(HWAVEOUT,DWORD);
-MMRESULT WINAPI waveOutGetID(HWAVEOUT,LPUINT);
+MMRESULT WINAPI waveOutGetDevCapsA(_In_ UINT_PTR, _Out_ LPWAVEOUTCAPSA, _In_ UINT);
+MMRESULT WINAPI waveOutGetDevCapsW(_In_ UINT_PTR, _Out_ LPWAVEOUTCAPSW, _In_ UINT);
+MMRESULT WINAPI waveOutGetVolume(_In_opt_ HWAVEOUT, _Out_ PDWORD);
+MMRESULT WINAPI waveOutSetVolume(_In_opt_ HWAVEOUT, _In_ DWORD);
+
+MMRESULT
+WINAPI
+waveOutGetErrorTextA(
+  _In_ MMRESULT mmrError,
+  _Out_writes_(cchText) LPSTR pszText,
+  _In_ UINT cchText);
+
+MMRESULT
+WINAPI
+waveOutGetErrorTextW(
+  _In_ MMRESULT mmrError,
+  _Out_writes_(cchText) LPWSTR pszText,
+  _In_ UINT cchText);
+
+MMRESULT
+WINAPI
+waveOutOpen(
+  _Out_opt_ LPHWAVEOUT,
+  _In_ UINT,
+  _In_ LPCWAVEFORMATEX,
+  _In_opt_ DWORD_PTR,
+  _In_opt_ DWORD_PTR,
+  _In_ DWORD);
+
+MMRESULT WINAPI waveOutClose(_In_ HWAVEOUT);
+
+MMRESULT
+WINAPI
+waveOutPrepareHeader(
+  _In_ HWAVEOUT hwo,
+  _Inout_updates_bytes_(cbwh) LPWAVEHDR pwh,
+  _In_ UINT cbwh);
+
+MMRESULT
+WINAPI
+waveOutUnprepareHeader(
+  _In_ HWAVEOUT hwo,
+  _Inout_updates_bytes_(cbwh) LPWAVEHDR pwh,
+  _In_ UINT cbwh);
+
+MMRESULT
+WINAPI
+waveOutWrite(
+  _In_ HWAVEOUT hwo,
+  _Inout_updates_bytes_(cbwh) LPWAVEHDR pwh,
+  _In_ UINT cbwh);
+
+MMRESULT WINAPI waveOutPause(_In_ HWAVEOUT);
+MMRESULT WINAPI waveOutRestart(_In_ HWAVEOUT);
+MMRESULT WINAPI waveOutReset(_In_ HWAVEOUT);
+MMRESULT WINAPI waveOutBreakLoop(_In_ HWAVEOUT);
+
+MMRESULT
+WINAPI
+waveOutGetPosition(
+  _In_ HWAVEOUT hwo,
+  _Inout_updates_bytes_(cbmmt) LPMMTIME pmmt,
+  _In_ UINT cbmmt);
+
+MMRESULT WINAPI waveOutGetPitch(_In_ HWAVEOUT, _Out_ PDWORD);
+MMRESULT WINAPI waveOutSetPitch(_In_ HWAVEOUT, _In_ DWORD);
+MMRESULT WINAPI waveOutGetPlaybackRate(_In_ HWAVEOUT, _Out_ PDWORD);
+MMRESULT WINAPI waveOutSetPlaybackRate(_In_ HWAVEOUT, _In_ DWORD);
+MMRESULT WINAPI waveOutGetID(_In_ HWAVEOUT, _Out_ LPUINT);
+
 #if (WINVER >= 0x030a)
 #ifdef _WIN32
-MMRESULT WINAPI waveOutMessage(HWAVEOUT,UINT,DWORD_PTR,DWORD_PTR);
+MMRESULT WINAPI waveOutMessage(_In_opt_ HWAVEOUT, _In_ UINT, _In_ DWORD_PTR, _In_ DWORD_PTR);
 #else
 DWORD WINAPI waveOutMessage(HWAVEOUT,UINT,DWORD,DWORD);
 #endif
 #endif
+
 UINT WINAPI waveInGetNumDevs(void);
-MMRESULT WINAPI waveInGetDevCapsA(UINT_PTR,LPWAVEINCAPSA,UINT);
-MMRESULT WINAPI waveInGetDevCapsW(UINT_PTR,LPWAVEINCAPSW,UINT);
-MMRESULT WINAPI waveInGetErrorTextA(MMRESULT,LPSTR,UINT);
-MMRESULT WINAPI waveInGetErrorTextW(MMRESULT,LPWSTR,UINT);
-MMRESULT WINAPI waveInOpen(LPHWAVEIN,UINT,LPCWAVEFORMATEX,DWORD_PTR,DWORD_PTR,DWORD);
-MMRESULT WINAPI waveInClose(HWAVEIN);
-MMRESULT WINAPI waveInPrepareHeader(HWAVEIN,LPWAVEHDR,UINT);
-MMRESULT WINAPI waveInUnprepareHeader(HWAVEIN,LPWAVEHDR,UINT);
-MMRESULT WINAPI waveInAddBuffer(HWAVEIN,LPWAVEHDR,UINT);
-MMRESULT WINAPI waveInStart(HWAVEIN);
-MMRESULT WINAPI waveInStop(HWAVEIN);
-MMRESULT WINAPI waveInReset(HWAVEIN);
-MMRESULT WINAPI waveInGetPosition(HWAVEIN,LPMMTIME,UINT);
-MMRESULT WINAPI waveInGetID(HWAVEIN,LPUINT);
+
+MMRESULT
+WINAPI
+waveInGetDevCapsA(
+  _In_ UINT_PTR uDeviceID,
+  _Out_writes_bytes_(cbwic) LPWAVEINCAPSA pwic,
+  _In_ UINT cbwic);
+
+MMRESULT
+WINAPI
+waveInGetDevCapsW(
+  _In_ UINT_PTR uDeviceID,
+  _Out_writes_bytes_(cbwic) LPWAVEINCAPSW pwic,
+  _In_ UINT cbwic);
+
+MMRESULT
+WINAPI
+waveInGetErrorTextA(
+  _In_ MMRESULT mmrError,
+  _Out_writes_(cchText) LPSTR pszText,
+  _In_ UINT cchText);
+
+MMRESULT
+WINAPI
+waveInGetErrorTextW(
+  _In_ MMRESULT mmrError,
+  _Out_writes_(cchText) LPWSTR pszText,
+  _In_ UINT cchText);
+
+MMRESULT
+WINAPI
+waveInOpen(
+  _Out_opt_ LPHWAVEIN,
+  _In_ UINT,
+  _In_ LPCWAVEFORMATEX,
+  _In_opt_ DWORD_PTR,
+  _In_opt_ DWORD_PTR,
+  _In_ DWORD);
+
+MMRESULT WINAPI waveInClose(_In_ HWAVEIN);
+
+MMRESULT
+WINAPI
+waveInPrepareHeader(
+  _In_ HWAVEIN hwi,
+  _Inout_updates_bytes_(cbwh) LPWAVEHDR pwh,
+  _In_ UINT cbwh);
+
+MMRESULT
+WINAPI
+waveInUnprepareHeader(
+  _In_ HWAVEIN hwi,
+  _Inout_updates_bytes_(cbwh) LPWAVEHDR pwh,
+  _In_ UINT cbwh);
+
+MMRESULT
+WINAPI
+waveInAddBuffer(
+  _In_ HWAVEIN hwi,
+  _Inout_updates_bytes_(cbwh) LPWAVEHDR pwh,
+  _In_ UINT cbwh);
+
+MMRESULT WINAPI waveInStart(_In_ HWAVEIN);
+MMRESULT WINAPI waveInStop(_In_ HWAVEIN);
+MMRESULT WINAPI waveInReset(_In_ HWAVEIN);
+
+MMRESULT
+WINAPI
+waveInGetPosition(
+  _In_ HWAVEIN hwi,
+  _Inout_updates_bytes_(cbmmt) LPMMTIME pmmt,
+  _In_ UINT cbmmt);
+
+MMRESULT WINAPI waveInGetID(_In_ HWAVEIN, _In_ LPUINT);
+
 #if (WINVER >= 0x030a)
 #ifdef _WIN32
-MMRESULT WINAPI waveInMessage(HWAVEIN,UINT,DWORD_PTR,DWORD_PTR);
+MMRESULT WINAPI waveInMessage(_In_opt_ HWAVEIN, _In_ UINT, _In_opt_ DWORD_PTR, _In_opt_ DWORD_PTR);
 #else
 DWORD WINAPI waveInMessage(HWAVEIN,UINT,DWORD,DWORD);
 #endif
 #endif
 UINT WINAPI midiOutGetNumDevs(void);
-MMRESULT WINAPI midiStreamOpen(LPHMIDISTRM,LPUINT,DWORD,DWORD_PTR,DWORD_PTR,DWORD);
-MMRESULT WINAPI midiStreamClose(HMIDISTRM);
-MMRESULT WINAPI midiStreamProperty(HMIDISTRM,LPBYTE,DWORD);
-MMRESULT WINAPI midiStreamPosition(HMIDISTRM,LPMMTIME,UINT);
-MMRESULT WINAPI midiStreamOut(HMIDISTRM,LPMIDIHDR,UINT);
-MMRESULT WINAPI midiStreamPause(HMIDISTRM);
-MMRESULT WINAPI midiStreamRestart(HMIDISTRM);
-MMRESULT WINAPI midiStreamStop(HMIDISTRM);
-MMRESULT WINAPI midiConnect(HMIDI,HMIDIOUT,PVOID);
-MMRESULT WINAPI midiDisconnect(HMIDI,HMIDIOUT,PVOID);
-MMRESULT WINAPI midiOutGetDevCapsA(UINT_PTR,LPMIDIOUTCAPSA,UINT);
-MMRESULT WINAPI midiOutGetDevCapsW(UINT_PTR,LPMIDIOUTCAPSW,UINT);
-MMRESULT WINAPI midiOutGetVolume(HMIDIOUT,PDWORD);
-MMRESULT WINAPI midiOutSetVolume(HMIDIOUT,DWORD);
-MMRESULT WINAPI midiOutGetErrorTextA(MMRESULT,LPSTR,UINT);
-MMRESULT WINAPI midiOutGetErrorTextW(MMRESULT,LPWSTR,UINT);
-MMRESULT WINAPI midiOutOpen(LPHMIDIOUT,UINT,DWORD_PTR,DWORD_PTR,DWORD);
-MMRESULT WINAPI midiOutClose(HMIDIOUT);
-MMRESULT WINAPI midiOutPrepareHeader(HMIDIOUT,LPMIDIHDR,UINT);
-MMRESULT WINAPI midiOutUnprepareHeader(HMIDIOUT,LPMIDIHDR,UINT);
-MMRESULT WINAPI midiOutShortMsg(HMIDIOUT,DWORD);
-MMRESULT WINAPI midiOutLongMsg(HMIDIOUT,LPMIDIHDR,UINT);
-MMRESULT WINAPI midiOutReset(HMIDIOUT);
-MMRESULT WINAPI midiOutCachePatches(HMIDIOUT,UINT,LPWORD,UINT);
-MMRESULT WINAPI midiOutCacheDrumPatches(HMIDIOUT,UINT,LPWORD,UINT);
-MMRESULT WINAPI midiOutGetID(HMIDIOUT,LPUINT);
+
+MMRESULT
+WINAPI
+midiStreamOpen(
+  _Out_ LPHMIDISTRM phms,
+  _Inout_updates_(cMidi) LPUINT puDeviceID,
+  _In_ DWORD cMidi,
+  _In_opt_ DWORD_PTR dwCallback,
+  _In_opt_ DWORD_PTR dwInstance,
+  _In_ DWORD fdwOpen);
+
+MMRESULT WINAPI midiStreamClose(_In_ HMIDISTRM);
+
+MMRESULT
+WINAPI
+midiStreamProperty(
+  _In_ HMIDISTRM hms,
+  _Inout_updates_bytes_(sizeof(DWORD) + sizeof(DWORD)) LPBYTE lppropdata,
+  _In_ DWORD dwProperty);
+
+MMRESULT
+WINAPI
+midiStreamPosition(
+  _In_ HMIDISTRM hms,
+  _Out_writes_bytes_(cbmmt) LPMMTIME lpmmt,
+  _In_ UINT cbmmt);
+
+MMRESULT
+WINAPI
+midiStreamOut(
+  _In_ HMIDISTRM hms,
+  _Out_writes_bytes_(cbmh) LPMIDIHDR pmh,
+  _In_ UINT cbmh);
+
+MMRESULT WINAPI midiStreamPause(_In_ HMIDISTRM);
+MMRESULT WINAPI midiStreamRestart(_In_ HMIDISTRM);
+MMRESULT WINAPI midiStreamStop(_In_ HMIDISTRM);
+MMRESULT WINAPI midiConnect(_In_ HMIDI, _In_ HMIDIOUT, _In_opt_ PVOID);
+MMRESULT WINAPI midiDisconnect(_In_ HMIDI, _In_ HMIDIOUT, _In_opt_ PVOID);
+
+MMRESULT
+WINAPI
+midiOutGetDevCapsA(
+  _In_ UINT_PTR uDeviceID,
+  _Out_writes_bytes_(cbmoc) LPMIDIOUTCAPSA pmoc,
+  _In_ UINT cbmoc);
+
+MMRESULT
+WINAPI
+midiOutGetDevCapsW(
+  _In_ UINT_PTR uDeviceID,
+  _Out_writes_bytes_(cbmoc) LPMIDIOUTCAPSW pmoc,
+  _In_ UINT cbmoc);
+
+MMRESULT WINAPI midiOutGetVolume(_In_opt_ HMIDIOUT, _Out_ PDWORD);
+MMRESULT WINAPI midiOutSetVolume(_In_opt_ HMIDIOUT, _In_ DWORD);
+
+MMRESULT
+WINAPI
+midiOutGetErrorTextA(
+  _In_ MMRESULT mmrError,
+  _Out_writes_(cchText) LPSTR pszText,
+  _In_ UINT cchText);
+
+MMRESULT
+WINAPI
+midiOutGetErrorTextW(
+  _In_ MMRESULT mmrError,
+  _Out_writes_(cchText) LPWSTR pszText,
+  _In_ UINT cchText);
+
+MMRESULT
+WINAPI
+midiOutOpen(
+  _Out_ LPHMIDIOUT,
+  _In_ UINT,
+  _In_opt_ DWORD_PTR,
+  _In_opt_ DWORD_PTR,
+  _In_ DWORD);
+
+MMRESULT WINAPI midiOutClose(_In_ HMIDIOUT);
+
+MMRESULT
+WINAPI
+midiOutPrepareHeader(
+  _In_ HMIDIOUT hmo,
+  _Inout_updates_bytes_(cbmh) LPMIDIHDR pmh,
+  _In_ UINT cbmh);
+
+MMRESULT
+WINAPI
+midiOutUnprepareHeader(
+  _In_ HMIDIOUT hmo,
+  _Inout_updates_bytes_(cbmh) LPMIDIHDR pmh,
+  _In_ UINT cbmh);
+
+MMRESULT WINAPI midiOutShortMsg(_In_ HMIDIOUT, _In_ DWORD);
+
+MMRESULT
+WINAPI
+midiOutLongMsg(
+  _In_ HMIDIOUT hmo,
+  _In_reads_bytes_(cbmh) LPMIDIHDR pmh,
+  _In_ UINT cbmh);
+
+MMRESULT WINAPI midiOutReset(_In_ HMIDIOUT);
+
+MMRESULT
+WINAPI
+midiOutCachePatches(
+  _In_ HMIDIOUT hmo,
+  _In_ UINT uBank,
+  _In_reads_(MIDIPATCHSIZE) LPWORD pwpa,
+  _In_ UINT fuCache);
+
+MMRESULT
+WINAPI
+midiOutCacheDrumPatches(
+  _In_ HMIDIOUT hmo,
+  _In_ UINT uPatch,
+  _In_reads_(MIDIPATCHSIZE) LPWORD pwkya,
+  _In_ UINT fuCache);
+
+MMRESULT WINAPI midiOutGetID(_In_ HMIDIOUT, _Out_ LPUINT);
+
 #if (WINVER >= 0x030a)
 #ifdef _WIN32
-MMRESULT WINAPI midiOutMessage(HMIDIOUT,UINT,DWORD_PTR,DWORD_PTR);
+MMRESULT WINAPI midiOutMessage(_In_opt_ HMIDIOUT, _In_ UINT, _In_opt_ DWORD_PTR, _In_opt_ DWORD_PTR);
 #else
 DWORD WINAPI midiOutMessage(HMIDIOUT,UINT,DWORD,DWORD);
 #endif
 #endif
+
 UINT WINAPI midiInGetNumDevs(void);
-MMRESULT WINAPI midiInGetDevCapsA(UINT_PTR,LPMIDIINCAPSA,UINT);
-MMRESULT WINAPI midiInGetDevCapsW(UINT_PTR,LPMIDIINCAPSW,UINT);
-MMRESULT WINAPI midiInGetErrorTextA(MMRESULT,LPSTR,UINT);
-MMRESULT WINAPI midiInGetErrorTextW(MMRESULT,LPWSTR,UINT);
-MMRESULT WINAPI midiInOpen(LPHMIDIIN,UINT,DWORD_PTR,DWORD_PTR,DWORD);
-MMRESULT WINAPI midiInClose(HMIDIIN);
-MMRESULT WINAPI midiInPrepareHeader(HMIDIIN,LPMIDIHDR,UINT);
-MMRESULT WINAPI midiInUnprepareHeader(HMIDIIN,LPMIDIHDR,UINT);
-MMRESULT WINAPI midiInAddBuffer(HMIDIIN,LPMIDIHDR,UINT);
-MMRESULT WINAPI midiInStart(HMIDIIN);
-MMRESULT WINAPI midiInStop(HMIDIIN);
-MMRESULT WINAPI midiInReset(HMIDIIN);
-MMRESULT WINAPI midiInGetID(HMIDIIN,LPUINT);
+
+MMRESULT
+WINAPI
+midiInGetDevCapsA(
+  _In_ UINT_PTR uDeviceID,
+  _Out_writes_bytes_(cbmic) LPMIDIINCAPSA pmic,
+  _In_ UINT cbmic);
+
+MMRESULT
+WINAPI
+midiInGetDevCapsW(
+  _In_ UINT_PTR uDeviceID,
+  _Out_writes_bytes_(cbmic) LPMIDIINCAPSW pmic,
+  _In_ UINT cbmic);
+
+MMRESULT
+WINAPI
+midiInGetErrorTextA(
+  _In_ MMRESULT mmrError,
+  _Out_writes_(cchText) LPSTR pszText,
+  _In_ UINT cchText);
+
+MMRESULT
+WINAPI
+midiInGetErrorTextW(
+  _In_ MMRESULT mmrError,
+  _Out_writes_(cchText) LPWSTR pszText,
+  _In_ UINT cchText);
+
+MMRESULT
+WINAPI
+midiInOpen(
+  _Out_ LPHMIDIIN,
+  _In_ UINT,
+  _In_opt_ DWORD_PTR,
+  _In_opt_ DWORD_PTR,
+  _In_ DWORD);
+
+MMRESULT WINAPI midiInClose(_In_ HMIDIIN);
+
+MMRESULT
+WINAPI
+midiInPrepareHeader(
+  _In_ HMIDIIN hmi,
+  _Inout_updates_bytes_(cbmh) LPMIDIHDR pmh,
+  _In_ UINT cbmh);
+
+MMRESULT
+WINAPI
+midiInUnprepareHeader(
+  _In_ HMIDIIN hmi,
+  _Inout_updates_bytes_(cbmh) LPMIDIHDR pmh,
+  _In_ UINT cbmh);
+
+MMRESULT
+WINAPI
+midiInAddBuffer(
+  _In_ HMIDIIN hmi,
+  _Out_writes_bytes_(cbmh) LPMIDIHDR pmh,
+  _In_ UINT cbmh);
+
+MMRESULT WINAPI midiInStart(_In_ HMIDIIN);
+MMRESULT WINAPI midiInStop(_In_ HMIDIIN);
+MMRESULT WINAPI midiInReset(_In_ HMIDIIN);
+MMRESULT WINAPI midiInGetID(_In_ HMIDIIN, _Out_ LPUINT);
+
 #if (WINVER >= 0x030a)
 #ifdef _WIN32
-MMRESULT WINAPI midiInMessage(HMIDIIN,UINT,DWORD_PTR,DWORD_PTR);
+MMRESULT WINAPI midiInMessage(_In_opt_ HMIDIIN, _In_ UINT, _In_opt_ DWORD_PTR, _In_opt_ DWORD_PTR);
 #else
 DWORD WINAPI midiInMessage(HMIDIIN,UINT,DWORD,DWORD);
 #endif
 #endif
+
 UINT WINAPI auxGetNumDevs(void);
-MMRESULT WINAPI auxGetDevCapsA(UINT_PTR,LPAUXCAPSA,UINT);
-MMRESULT WINAPI auxGetDevCapsW(UINT_PTR,LPAUXCAPSW,UINT);
-MMRESULT WINAPI auxSetVolume(UINT,DWORD);
-MMRESULT WINAPI auxGetVolume(UINT,PDWORD);
-MMRESULT WINAPI auxOutMessage(UINT,UINT,DWORD_PTR,DWORD_PTR);
+
+MMRESULT
+WINAPI
+auxGetDevCapsA(
+  _In_ UINT_PTR uDeviceID,
+  _Out_writes_bytes_(cbac) LPAUXCAPSA pac,
+  _In_ UINT cbac);
+
+MMRESULT
+WINAPI
+auxGetDevCapsW(
+  _In_ UINT_PTR uDeviceID,
+  _Out_writes_bytes_(cbac) LPAUXCAPSW pac,
+  _In_ UINT cbac);
+
+MMRESULT WINAPI auxSetVolume(_In_ UINT, _In_ DWORD);
+MMRESULT WINAPI auxGetVolume(_In_ UINT, _Out_ PDWORD);
+
+MMRESULT
+WINAPI
+auxOutMessage(
+  _In_ UINT,
+  _In_ UINT,
+  _In_opt_ DWORD_PTR,
+  _In_opt_ DWORD_PTR);
+
 UINT WINAPI mixerGetNumDevs(void);
-MMRESULT WINAPI mixerGetDevCapsA(UINT_PTR,LPMIXERCAPSA,UINT);
-MMRESULT WINAPI mixerGetDevCapsW(UINT_PTR,LPMIXERCAPSW,UINT);
-MMRESULT WINAPI mixerOpen(LPHMIXER,UINT,DWORD_PTR,DWORD_PTR,DWORD);
-MMRESULT WINAPI mixerClose(HMIXER);
-DWORD WINAPI mixerMessage(HMIXER,UINT,DWORD_PTR,DWORD_PTR);
-MMRESULT WINAPI mixerGetLineInfoA(HMIXEROBJ,LPMIXERLINEA,DWORD);
-MMRESULT WINAPI mixerGetLineInfoW(HMIXEROBJ,LPMIXERLINEW,DWORD);
-MMRESULT WINAPI mixerGetID(HMIXEROBJ,PUINT,DWORD);
-MMRESULT WINAPI mixerGetLineControlsA(HMIXEROBJ,LPMIXERLINECONTROLSA,DWORD);
-MMRESULT WINAPI mixerGetLineControlsW(HMIXEROBJ,LPMIXERLINECONTROLSW,DWORD);
-MMRESULT WINAPI mixerGetControlDetailsA(HMIXEROBJ,LPMIXERCONTROLDETAILS,DWORD);
-MMRESULT WINAPI mixerGetControlDetailsW(HMIXEROBJ,LPMIXERCONTROLDETAILS,DWORD);
-MMRESULT WINAPI mixerSetControlDetails(HMIXEROBJ,LPMIXERCONTROLDETAILS,DWORD);
-MMRESULT WINAPI timeGetSystemTime(LPMMTIME,UINT);
+
+MMRESULT
+WINAPI
+mixerGetDevCapsA(
+  _In_ UINT_PTR uMxId,
+  _Out_writes_bytes_(cbmxcaps) LPMIXERCAPSA pmxcaps,
+  _In_ UINT cbmxcaps);
+
+MMRESULT
+WINAPI
+mixerGetDevCapsW(
+  _In_ UINT_PTR uMxId,
+  _Out_writes_bytes_(cbmxcaps) LPMIXERCAPSW pmxcaps,
+  _In_ UINT cbmxcaps);
+
+MMRESULT
+WINAPI
+mixerOpen(
+  _Out_opt_ LPHMIXER,
+  _In_ UINT,
+  _In_opt_ DWORD_PTR,
+  _In_opt_ DWORD_PTR,
+  _In_ DWORD);
+
+MMRESULT WINAPI mixerClose(_In_ HMIXER);
+
+DWORD
+WINAPI
+mixerMessage(
+  _In_opt_ HMIXER,
+  _In_ UINT,
+  _In_opt_ DWORD_PTR,
+  _In_opt_ DWORD_PTR);
+
+MMRESULT
+WINAPI
+mixerGetLineInfoA(
+  _In_opt_ HMIXEROBJ,
+  _Inout_ LPMIXERLINEA,
+  _In_ DWORD);
+
+MMRESULT
+WINAPI
+mixerGetLineInfoW(
+  _In_opt_ HMIXEROBJ,
+  _Inout_ LPMIXERLINEW,
+  _In_ DWORD);
+
+MMRESULT WINAPI mixerGetID(_In_opt_ HMIXEROBJ, _Out_ PUINT, _In_ DWORD);
+
+MMRESULT
+WINAPI
+mixerGetLineControlsA(
+  _In_opt_ HMIXEROBJ,
+  _Inout_ LPMIXERLINECONTROLSA,
+  _In_ DWORD);
+
+MMRESULT
+WINAPI
+mixerGetLineControlsW(
+  _In_opt_ HMIXEROBJ,
+  _Inout_ LPMIXERLINECONTROLSW,
+  _In_ DWORD);
+
+MMRESULT
+WINAPI
+mixerGetControlDetailsA(
+  _In_opt_ HMIXEROBJ,
+  _Inout_ LPMIXERCONTROLDETAILS,
+  _In_ DWORD);
+
+MMRESULT
+WINAPI
+mixerGetControlDetailsW(
+  _In_opt_ HMIXEROBJ,
+  _Inout_ LPMIXERCONTROLDETAILS,
+  _In_ DWORD);
+
+MMRESULT
+WINAPI
+mixerSetControlDetails(
+  _In_opt_ HMIXEROBJ,
+  _In_ LPMIXERCONTROLDETAILS,
+  _In_ DWORD);
+
+MMRESULT
+WINAPI
+timeGetSystemTime(
+  _Out_writes_bytes_(cbmmt) LPMMTIME pmmt,
+  _In_ UINT cbmmt);
+
 DWORD WINAPI timeGetTime(void);
-MMRESULT WINAPI timeSetEvent(UINT,UINT,LPTIMECALLBACK,DWORD_PTR,UINT);
-MMRESULT WINAPI timeKillEvent(UINT);
-MMRESULT WINAPI timeGetDevCaps(LPTIMECAPS,UINT);
-MMRESULT WINAPI timeBeginPeriod(UINT);
-MMRESULT WINAPI timeEndPeriod(UINT);
+
+MMRESULT
+WINAPI
+timeSetEvent(
+  _In_ UINT,
+  _In_ UINT,
+  _In_ LPTIMECALLBACK,
+  _In_ DWORD_PTR,
+  _In_ UINT);
+
+MMRESULT WINAPI timeKillEvent(_In_ UINT);
+
+MMRESULT
+WINAPI
+timeGetDevCaps(
+  _Out_writes_bytes_(cbtc) LPTIMECAPS ptc,
+  _In_ UINT cbtc);
+
+MMRESULT WINAPI timeBeginPeriod(_In_ UINT);
+MMRESULT WINAPI timeEndPeriod(_In_ UINT);
 UINT WINAPI joyGetNumDevs(void);
-MMRESULT WINAPI joyGetDevCapsA(UINT_PTR,LPJOYCAPSA,UINT);
-MMRESULT WINAPI joyGetDevCapsW(UINT_PTR,LPJOYCAPSW,UINT);
-MMRESULT WINAPI joyGetPos(UINT,LPJOYINFO);
-MMRESULT WINAPI joyGetPosEx(UINT,LPJOYINFOEX);
-MMRESULT WINAPI joyGetThreshold(UINT,LPUINT);
-MMRESULT WINAPI joyReleaseCapture(UINT);
-MMRESULT WINAPI joySetCapture(HWND,UINT,UINT,BOOL);
-MMRESULT WINAPI joySetThreshold(UINT,UINT);
-FOURCC WINAPI mmioStringToFOURCCA(LPCSTR,UINT);
-FOURCC WINAPI mmioStringToFOURCCW(LPCWSTR,UINT);
-LPMMIOPROC WINAPI mmioInstallIOProcA(FOURCC,LPMMIOPROC,DWORD);
-LPMMIOPROC WINAPI mmioInstallIOProcW(FOURCC,LPMMIOPROC,DWORD);
-HMMIO WINAPI mmioOpenA(LPSTR,LPMMIOINFO,DWORD);
-HMMIO WINAPI mmioOpenW(LPWSTR,LPMMIOINFO,DWORD);
-MMRESULT WINAPI mmioRenameA(LPCSTR,LPCSTR,LPCMMIOINFO,DWORD);
-MMRESULT WINAPI mmioRenameW(LPCWSTR,LPCWSTR,LPCMMIOINFO,DWORD);
-MMRESULT WINAPI mmioClose(HMMIO,UINT);
-LONG WINAPI mmioRead(HMMIO,HPSTR,LONG);
-LONG WINAPI mmioWrite(HMMIO,LPCSTR,LONG);
-LONG WINAPI mmioSeek(HMMIO,LONG,int);
-MMRESULT WINAPI mmioGetInfo(HMMIO,LPMMIOINFO,UINT);
-MMRESULT WINAPI mmioSetInfo(HMMIO,LPCMMIOINFO,UINT);
-MMRESULT WINAPI mmioSetBuffer(HMMIO,LPSTR,LONG,UINT);
-MMRESULT WINAPI mmioFlush(HMMIO,UINT);
-MMRESULT WINAPI mmioAdvance(HMMIO,LPMMIOINFO,UINT);
-LRESULT WINAPI mmioSendMessage(HMMIO,UINT,LPARAM,LPARAM);
-MMRESULT WINAPI mmioDescend(HMMIO,LPMMCKINFO,const MMCKINFO*,UINT);
-MMRESULT WINAPI mmioAscend(HMMIO,LPMMCKINFO,UINT);
-MMRESULT WINAPI mmioCreateChunk(HMMIO,LPMMCKINFO,UINT);
-MCIERROR WINAPI mciSendCommandA(MCIDEVICEID,UINT,DWORD_PTR,DWORD_PTR);
-MCIERROR WINAPI mciSendCommandW(MCIDEVICEID,UINT,DWORD_PTR,DWORD_PTR);
-MCIERROR WINAPI mciSendStringA(LPCSTR,LPSTR,UINT,HWND);
-MCIERROR WINAPI mciSendStringW(LPCWSTR,LPWSTR,UINT,HWND);
-MCIDEVICEID WINAPI mciGetDeviceIDA(LPCSTR);
-MCIDEVICEID WINAPI mciGetDeviceIDW(LPCWSTR);
-MCIDEVICEID WINAPI mciGetDeviceIDFromElementIDA(DWORD,LPCSTR);
-MCIDEVICEID WINAPI mciGetDeviceIDFromElementIDW(DWORD,LPCWSTR);
-BOOL WINAPI mciGetErrorStringA(MCIERROR,LPSTR,UINT);
-BOOL WINAPI mciGetErrorStringW(MCIERROR,LPWSTR,UINT);
-BOOL WINAPI mciSetYieldProc(MCIDEVICEID,YIELDPROC,DWORD);
-HTASK WINAPI mciGetCreatorTask(MCIDEVICEID);
-YIELDPROC WINAPI mciGetYieldProc(MCIDEVICEID,PDWORD);
+
+MMRESULT
+WINAPI
+joyGetDevCapsA(
+  _In_ UINT_PTR uJoyID,
+  _Out_writes_bytes_(cbjc) LPJOYCAPSA pjc,
+  _In_ UINT cbjc);
+
+MMRESULT
+WINAPI
+joyGetDevCapsW(
+  _In_ UINT_PTR uJoyID,
+  _Out_writes_bytes_(cbjc) LPJOYCAPSW pjc,
+  _In_ UINT cbjc);
+
+MMRESULT WINAPI joyGetPos(_In_ UINT, _Out_ LPJOYINFO);
+MMRESULT WINAPI joyGetPosEx(_In_ UINT, _Out_ LPJOYINFOEX);
+MMRESULT WINAPI joyGetThreshold(_In_ UINT, _Out_ LPUINT);
+MMRESULT WINAPI joyReleaseCapture(_In_ UINT);
+MMRESULT WINAPI joySetCapture(_In_ HWND, _In_ UINT, _In_ UINT, _In_ BOOL);
+MMRESULT WINAPI joySetThreshold(_In_ UINT, _In_ UINT);
+FOURCC WINAPI mmioStringToFOURCCA(LPCSTR, _In_ UINT);
+FOURCC WINAPI mmioStringToFOURCCW(LPCWSTR, _In_ UINT);
+
+LPMMIOPROC
+WINAPI
+mmioInstallIOProcA(
+  _In_ FOURCC,
+  _In_opt_ LPMMIOPROC,
+  _In_ DWORD);
+
+LPMMIOPROC
+WINAPI
+mmioInstallIOProcW(
+  _In_ FOURCC,
+  _In_opt_ LPMMIOPROC,
+  _In_ DWORD);
+
+HMMIO
+WINAPI
+mmioOpenA(
+  _Inout_updates_bytes_opt_(128) LPSTR pszFileName,
+  _Inout_opt_ LPMMIOINFO pmmioinfo,
+  _In_ DWORD fdwOpen);
+
+HMMIO
+WINAPI
+mmioOpenW(
+  _Inout_updates_bytes_opt_(128) LPWSTR pszFileName,
+  _Inout_opt_ LPMMIOINFO pmmioinfo,
+  _In_ DWORD fdwOpen);
+
+MMRESULT
+WINAPI
+mmioRenameA(
+  _In_ LPCSTR,
+  _In_ LPCSTR,
+  _In_opt_ LPCMMIOINFO,
+  _In_ DWORD);
+
+MMRESULT
+WINAPI
+mmioRenameW(
+  _In_ LPCWSTR,
+  _In_ LPCWSTR,
+  _In_opt_ LPCMMIOINFO,
+  _In_ DWORD);
+
+MMRESULT WINAPI mmioClose(_In_ HMMIO, _In_ UINT);
+
+LONG
+WINAPI
+mmioRead(
+  _In_ HMMIO hmmio,
+  _Out_writes_bytes_(cch) HPSTR pch,
+  _In_ LONG cch);
+
+LONG
+WINAPI
+mmioWrite(
+  _In_ HMMIO hmmio,
+  _In_reads_bytes_(cch) const char _huge * pch,
+  _In_ LONG cch);
+
+LONG WINAPI mmioSeek(_In_ HMMIO, _In_ LONG, _In_ int);
+MMRESULT WINAPI mmioGetInfo(_In_ HMMIO, _Out_ LPMMIOINFO, _In_ UINT);
+MMRESULT WINAPI mmioSetInfo(_In_ HMMIO, _In_ LPCMMIOINFO, _In_ UINT);
+
+MMRESULT
+WINAPI
+mmioSetBuffer(
+  _In_ HMMIO hmmio,
+  _Out_writes_opt_(cchBuffer) LPSTR pchBuffer,
+  _In_ LONG cchBuffer,
+  _In_ UINT fuBuffer);
+
+MMRESULT WINAPI mmioFlush(_In_ HMMIO, _In_ UINT);
+MMRESULT WINAPI mmioAdvance(_In_ HMMIO, _In_opt_ LPMMIOINFO, _In_ UINT);
+
+LRESULT
+WINAPI
+mmioSendMessage(
+  _In_ HMMIO,
+  _In_ UINT,
+  _In_opt_ LPARAM,
+  _In_opt_ LPARAM);
+
+MMRESULT
+WINAPI
+mmioDescend(
+  _In_ HMMIO,
+  _Inout_ LPMMCKINFO,
+  _In_opt_ const MMCKINFO*,
+  _In_ UINT);
+
+MMRESULT WINAPI mmioAscend(_In_ HMMIO, _In_ LPMMCKINFO, _In_ UINT);
+MMRESULT WINAPI mmioCreateChunk(_In_ HMMIO, _In_ LPMMCKINFO, _In_ UINT);
+
+MCIERROR
+WINAPI
+mciSendCommandA(
+  _In_ MCIDEVICEID,
+  _In_ UINT,
+  _In_opt_ DWORD_PTR,
+  _In_opt_ DWORD_PTR);
+
+MCIERROR
+WINAPI
+mciSendCommandW(
+  _In_ MCIDEVICEID,
+  _In_ UINT,
+  _In_opt_ DWORD_PTR,
+  _In_opt_ DWORD_PTR);
+
+MCIERROR
+WINAPI
+mciSendStringA(
+  _In_ LPCSTR lpstrCommand,
+  _Out_writes_opt_(uReturnLength) LPSTR lpstrReturnString,
+  _In_ UINT uReturnLength,
+  _In_opt_ HWND hwndCallback);
+
+MCIERROR
+WINAPI
+mciSendStringW(
+  _In_ LPCWSTR lpstrCommand,
+  _Out_writes_opt_(uReturnLength) LPWSTR lpstrReturnString,
+  _In_ UINT uReturnLength,
+  _In_opt_ HWND hwndCallback);
+
+MCIDEVICEID WINAPI mciGetDeviceIDA(_In_ LPCSTR);
+MCIDEVICEID WINAPI mciGetDeviceIDW(_In_ LPCWSTR);
+MCIDEVICEID WINAPI mciGetDeviceIDFromElementIDA(_In_ DWORD, _In_ LPCSTR);
+MCIDEVICEID WINAPI mciGetDeviceIDFromElementIDW(_In_ DWORD, _In_ LPCWSTR);
+
+BOOL
+WINAPI
+mciGetErrorStringA(
+  _In_ MCIERROR mcierr,
+  _Out_writes_(cchText) LPSTR pszText,
+  _In_ UINT cchText);
+
+BOOL
+WINAPI
+mciGetErrorStringW(
+  _In_ MCIERROR mcierr,
+  _Out_writes_(cchText) LPWSTR pszText,
+  _In_ UINT cchText);
+
+BOOL WINAPI mciSetYieldProc(_In_ MCIDEVICEID, _In_opt_ YIELDPROC, _In_ DWORD);
+HTASK WINAPI mciGetCreatorTask(_In_ MCIDEVICEID);
+YIELDPROC WINAPI mciGetYieldProc(_In_ MCIDEVICEID, _In_ PDWORD);
 
 #ifdef _WINE
 DWORD WINAPI GetDriverFlags(HDRVR hDriver);
index 83d6dba..a80b293 100644 (file)
@@ -170,26 +170,36 @@ typedef struct {
 #define ICCOMPRESS_KEYFRAME     0x00000001L
 
 typedef struct {
-    DWORD              dwFlags;
-    LPBITMAPINFOHEADER lpbiOutput;
-    LPVOID             lpOutput;
-    LPBITMAPINFOHEADER lpbiInput;
-    LPVOID             lpInput;
-    LPDWORD            lpckid;
-    LPDWORD            lpdwFlags;
-    LONG               lFrameNum;
-    DWORD              dwFrameSize;
-    DWORD              dwQuality;
-    LPBITMAPINFOHEADER lpbiPrev;
-    LPVOID             lpPrev;
+  DWORD dwFlags;
+  LPBITMAPINFOHEADER lpbiOutput;
+  _Field_size_bytes_(lpbiOutput->biSizeImage) LPVOID lpOutput;
+  LPBITMAPINFOHEADER lpbiInput;
+  _Field_size_bytes_(lpbiInput->biSizeImage) LPVOID lpInput;
+  LPDWORD lpckid;
+  LPDWORD lpdwFlags;
+  LONG lFrameNum;
+  DWORD dwFrameSize;
+  DWORD dwQuality;
+  LPBITMAPINFOHEADER lpbiPrev;
+  _Field_size_bytes_(lpbiPrev->biSizeImage) LPVOID lpPrev;
 } ICCOMPRESS;
 
-DWORD VFWAPIV ICCompress(
-       HIC hic,DWORD dwFlags,LPBITMAPINFOHEADER lpbiOutput,LPVOID lpData,
-       LPBITMAPINFOHEADER lpbiInput,LPVOID lpBits,LPDWORD lpckid,
-       LPDWORD lpdwFlags,LONG lFrameNum,DWORD dwFrameSize,DWORD dwQuality,
-       LPBITMAPINFOHEADER lpbiPrev,LPVOID lpPrev
-);
+DWORD
+VFWAPIV
+ICCompress(
+  _In_ HIC hic,
+  _In_ DWORD dwFlags,
+  _In_ LPBITMAPINFOHEADER lpbiOutput,
+  _Out_writes_bytes_(lpbiOutput->biSizeImage) LPVOID lpData,
+  _In_ LPBITMAPINFOHEADER lpbiInput,
+  _In_reads_bytes_(lpbiInput->biSizeImage) LPVOID lpBits,
+  _Out_opt_ LPDWORD lpckid,
+  _Out_opt_ LPDWORD lpdwFlags,
+  _In_ LONG lFrameNum,
+  _In_ DWORD dwFrameSize,
+  _In_ DWORD dwQuality,
+  _In_opt_ LPBITMAPINFOHEADER lpbiPrev,
+  _In_reads_bytes_opt_(lpbiPrev->biSizeImage) LPVOID lpPrev);
 
 #define ICCompressGetFormat(hic, lpbiInput, lpbiOutput)                \
        ICSendMessage(                                                  \
@@ -236,8 +246,8 @@ typedef struct {
     DWORD               dwScale;
     DWORD               dwOverheadPerFrame;
     DWORD               dwReserved2;
-    LONG (CALLBACK *GetData)(LPARAM lInput,LONG lFrame,LPVOID lpBits,LONG len);
-    LONG (CALLBACK *PutData)(LPARAM lOutput,LONG lFrame,LPVOID lpBits,LONG len);
+    LONG (CALLBACK *GetData)(_In_ LPARAM lInput, _In_ LONG lFrame, _Out_writes_bytes_(len) LPVOID lpBits, _In_ LONG len);
+    LONG (CALLBACK *PutData)(_In_ LPARAM lOutput, _In_ LONG lFrame, _In_reads_bytes_(len) LPVOID lpBits, _In_ LONG len);
 } ICCOMPRESSFRAMES;
 
 typedef struct {
@@ -321,12 +331,12 @@ typedef struct {
 #define ICDECOMPRESS_NOTKEYFRAME       0x08000000      /* this frame is not a key frame */
 
 typedef struct {
-    DWORD              dwFlags;        /* flags (from AVI index...) */
-    LPBITMAPINFOHEADER lpbiInput;      /* BITMAPINFO of compressed data */
-    LPVOID             lpInput;        /* compressed data */
-    LPBITMAPINFOHEADER lpbiOutput;     /* DIB to decompress to */
-    LPVOID             lpOutput;
-    DWORD              ckid;           /* ckid from AVI file */
+  DWORD dwFlags; /* flags (from AVI index...) */
+  LPBITMAPINFOHEADER lpbiInput; /* BITMAPINFO of compressed data */
+  _Field_size_bytes_(lpbiInput->biSizeImage) LPVOID lpInput; /* compressed data */
+  LPBITMAPINFOHEADER lpbiOutput; /* DIB to decompress to */
+  _Field_size_bytes_(lpbiOutput->biSizeImage) LPVOID    lpOutput;
+  DWORD ckid; /* ckid from AVI file */
 } ICDECOMPRESS;
 
 typedef struct {
@@ -348,7 +358,15 @@ typedef struct {
     INT                        dySrc;
 } ICDECOMPRESSEX;
 
-DWORD VFWAPIV ICDecompress(HIC hic,DWORD dwFlags,LPBITMAPINFOHEADER lpbiFormat,LPVOID lpData,LPBITMAPINFOHEADER lpbi,LPVOID lpBits);
+DWORD
+VFWAPIV
+ICDecompress(
+  _In_ HIC hic,
+  _In_ DWORD dwFlags,
+  _In_ LPBITMAPINFOHEADER lpbiFormat,
+  _In_reads_bytes_(lpbiFormat->biSizeImage) LPVOID lpData,
+  _In_ LPBITMAPINFOHEADER lpbi,
+  _Out_writes_bytes_(lpbi->biSizeImage) LPVOID lpBits);
 
 #define ICDecompressBegin(hic, lpbiInput, lpbiOutput)  \
     ICSendMessage(                                             \
@@ -385,13 +403,31 @@ DWORD VFWAPIV ICDecompress(HIC hic,DWORD dwFlags,LPBITMAPINFOHEADER lpbiFormat,L
 
 #define ICDecompressEnd(hic) ICSendMessage(hic, ICM_DECOMPRESS_END, 0, 0)
 
-LRESULT        VFWAPI  ICSendMessage(HIC hic, UINT msg, DWORD_PTR dw1, DWORD_PTR dw2);
-
-static inline LRESULT VFWAPI ICDecompressEx(HIC hic, DWORD dwFlags,
-                                           LPBITMAPINFOHEADER lpbiSrc, LPVOID lpSrc,
-                                           int xSrc, int ySrc, int dxSrc, int dySrc,
-                                           LPBITMAPINFOHEADER lpbiDst, LPVOID lpDst,
-                                           int xDst, int yDst, int dxDst, int dyDst)
+LRESULT
+VFWAPI
+ICSendMessage(
+  _In_ HIC hic,
+  _In_ UINT msg,
+  _In_ DWORD_PTR dw1,
+  _In_ DWORD_PTR dw2);
+
+static inline
+LRESULT
+VFWAPI
+ICDecompressEx(_In_ HIC hic,
+               _In_ DWORD dwFlags,
+               _In_ LPBITMAPINFOHEADER lpbiSrc,
+               _In_reads_bytes_(lpbiSrc->biSizeImage) LPVOID lpSrc,
+               _In_ int xSrc,
+               _In_ int ySrc,
+               _In_ int dxSrc,
+               _In_ int dySrc,
+               _In_ LPBITMAPINFOHEADER lpbiDst,
+               _Out_writes_bytes_(lpbiDst->biSizeImage) LPVOID lpDst,
+               _In_ int xDst,
+               _In_ int yDst,
+               _In_ int dxDst,
+               _In_ int dyDst)
 {
     ICDECOMPRESSEX ic;
 
@@ -411,16 +447,23 @@ static inline LRESULT VFWAPI ICDecompressEx(HIC hic, DWORD dwFlags,
     return ICSendMessage(hic, ICM_DECOMPRESSEX, (DWORD_PTR)&ic, sizeof(ic));
 }
 
-static inline LRESULT VFWAPI ICDecompressExBegin(HIC hic, DWORD dwFlags,
-                                                LPBITMAPINFOHEADER lpbiSrc,
-                                                LPVOID lpSrc,
-                                                int xSrc, int ySrc, int dxSrc, int dySrc,
-                                                LPBITMAPINFOHEADER lpbiDst,
-                                                LPVOID lpDst,
-                                                int xDst,
-                                                int yDst,
-                                                int dxDst,
-                                                int dyDst)
+static inline
+LRESULT
+VFWAPI
+ICDecompressExBegin(_In_ HIC hic,
+                    _In_ DWORD dwFlags,
+                    _In_ LPBITMAPINFOHEADER lpbiSrc,
+                    _In_opt_ LPVOID lpSrc,
+                    _In_ int xSrc,
+                    _In_ int ySrc,
+                    _In_ int dxSrc,
+                    _In_ int dySrc,
+                    _In_ LPBITMAPINFOHEADER lpbiDst,
+                    _Out_opt_ LPVOID lpDst,
+                    _In_ int xDst,
+                    _In_ int yDst,
+                    _In_ int dxDst,
+                    _In_ int dyDst)
 {
     ICDECOMPRESSEX ic;
 
@@ -439,16 +482,24 @@ static inline LRESULT VFWAPI ICDecompressExBegin(HIC hic, DWORD dwFlags,
     ic.dyDst = dyDst;
     return ICSendMessage(hic, ICM_DECOMPRESSEX_BEGIN, (DWORD_PTR)&ic, sizeof(ic));
 }
-static inline LRESULT VFWAPI ICDecompressExQuery(HIC hic, DWORD dwFlags,
-                                                LPBITMAPINFOHEADER lpbiSrc,
-                                                LPVOID lpSrc,
-                                                int xSrc, int ySrc, int dxSrc, int dySrc,
-                                                LPBITMAPINFOHEADER lpbiDst,
-                                                LPVOID lpDst,
-                                                int xDst,
-                                                int yDst,
-                                                int dxDst,
-                                                int dyDst)
+
+static inline
+LRESULT
+VFWAPI
+ICDecompressExQuery(_In_ HIC hic,
+                    _In_ DWORD dwFlags,
+                    _In_ LPBITMAPINFOHEADER lpbiSrc,
+                    _Reserved_ LPVOID lpSrc,
+                    _In_ int xSrc,
+                    _In_ int ySrc,
+                    _In_ int dxSrc,
+                    _In_ int dySrc,
+                    _In_opt_ LPBITMAPINFOHEADER lpbiDst,
+                    _Out_opt_ LPVOID lpDst,
+                    _In_ int xDst,
+                    _In_ int yDst,
+                    _In_ int dxDst,
+                    _In_ int dyDst)
 {
     ICDECOMPRESSEX ic;
 
@@ -487,23 +538,87 @@ static inline LRESULT VFWAPI ICDecompressExQuery(HIC hic, DWORD dwFlags,
 #define ICDrawOpen(fccType, fccHandler, lpbiIn) \
     ICLocate(fccType, fccHandler, lpbiIn, NULL, ICMODE_DRAW)
 
-HANDLE VFWAPI ICImageCompress(HIC hic, UINT uiFlags, LPBITMAPINFO lpbiIn,
-                             LPVOID lpBits, LPBITMAPINFO lpbiOut, LONG lQuality,
-                             LONG* plSize);
-
-HANDLE VFWAPI ICImageDecompress(HIC hic, UINT uiFlags, LPBITMAPINFO lpbiIn,
-                               LPVOID lpBits, LPBITMAPINFO lpbiOut);
-
-BOOL   VFWAPI  ICInfo(DWORD fccType, DWORD fccHandler, ICINFO * lpicinfo);
-BOOL    VFWAPI  ICInstall(DWORD fccType, DWORD fccHandler, LPARAM lParam, LPSTR szDesc, UINT wFlags);
-BOOL    VFWAPI  ICRemove(DWORD fccType, DWORD fccHandler, UINT wFlags);
-LRESULT        VFWAPI  ICGetInfo(HIC hic,ICINFO *picinfo, DWORD cb);
-HIC    VFWAPI  ICOpen(DWORD fccType, DWORD fccHandler, UINT wMode);
-HIC    VFWAPI  ICOpenFunction(DWORD fccType, DWORD fccHandler, UINT wMode, DRIVERPROC lpfnHandler);
-
-LRESULT VFWAPI ICClose(HIC hic);
-HIC    VFWAPI  ICLocate(DWORD fccType, DWORD fccHandler, LPBITMAPINFOHEADER lpbiIn, LPBITMAPINFOHEADER lpbiOut, WORD wFlags);
-HIC    VFWAPI  ICGetDisplayFormat(HIC hic, LPBITMAPINFOHEADER lpbiIn, LPBITMAPINFOHEADER lpbiOut, int BitDepth, int dx, int dy);
+HANDLE
+VFWAPI
+ICImageCompress(
+  _In_ HIC hic,
+  _In_ UINT uiFlags,
+  _In_ LPBITMAPINFO lpbiIn,
+  _In_ LPVOID lpBits,
+  _In_opt_ LPBITMAPINFO lpbiOut,
+  _In_ LONG lQuality,
+  _Inout_opt_ LONG* plSize);
+
+HANDLE
+VFWAPI
+ICImageDecompress(
+  _In_opt_ HIC hic,
+  _In_ UINT uiFlags,
+  _In_ LPBITMAPINFO lpbiIn,
+  _In_ LPVOID lpBits,
+  _In_opt_ LPBITMAPINFO lpbiOut);
+
+BOOL
+VFWAPI
+ICInfo(
+  _In_ DWORD fccType,
+  _In_ DWORD fccHandler,
+  _Out_ ICINFO * lpicinfo);
+
+BOOL
+VFWAPI
+ICInstall(
+  _In_ DWORD fccType,
+  _In_ DWORD fccHandler,
+  _In_ LPARAM lParam,
+  _In_ LPSTR szDesc,
+  _In_ UINT wFlags);
+
+BOOL
+VFWAPI
+ICRemove(
+  _In_ DWORD fccType,
+  _In_ DWORD fccHandler,
+  _In_ UINT wFlags);
+
+_Success_(return != 0)
+LRESULT
+VFWAPI
+ICGetInfo(
+  _In_ HIC hic,
+  _Out_writes_bytes_to_(cb, return) ICINFO *picinfo,
+  _In_ DWORD cb);
+
+HIC VFWAPI ICOpen(_In_ DWORD fccType, _In_ DWORD fccHandler, _In_ UINT wMode);
+
+HIC
+VFWAPI
+ICOpenFunction(
+  _In_ DWORD fccType,
+  _In_ DWORD fccHandler,
+  _In_ UINT wMode,
+  _In_ DRIVERPROC lpfnHandler);
+
+LRESULT VFWAPI ICClose(_In_ HIC hic);
+
+HIC
+VFWAPI
+ICLocate(
+  _In_ DWORD fccType,
+  _In_ DWORD fccHandler,
+  _In_ LPBITMAPINFOHEADER lpbiIn,
+  _In_opt_ LPBITMAPINFOHEADER lpbiOut,
+  _In_ WORD wFlags);
+
+HIC
+VFWAPI
+ICGetDisplayFormat(
+  _In_opt_ HIC hic,
+  _In_ LPBITMAPINFOHEADER lpbiIn,
+  _Out_ LPBITMAPINFOHEADER lpbiOut,
+  _In_ int BitDepth,
+  _In_ int dx,
+  _In_ int dy);
 
 /* Values for wFlags of ICInstall() */
 #define ICINSTALL_UNICODE       0x8000
@@ -555,24 +670,25 @@ typedef struct {
     LPPALETTEENTRY      lppe;
 } ICPALETTE;
 
-DWORD  VFWAPIV ICDrawBegin(
-        HIC                    hic,
-        DWORD                  dwFlags,/* flags */
-        HPALETTE               hpal,   /* palette to draw with */
-        HWND                   hwnd,   /* window to draw to */
-        HDC                    hdc,    /* HDC to draw to */
-        INT                    xDst,   /* destination rectangle */
-        INT                    yDst,
-        INT                    dxDst,
-        INT                    dyDst,
-        LPBITMAPINFOHEADER     lpbi,   /* format of frame to draw */
-        INT                    xSrc,   /* source rectangle */
-        INT                    ySrc,
-        INT                    dxSrc,
-        INT                    dySrc,
-        DWORD                  dwRate, /* frames/second = (dwRate/dwScale) */
-        DWORD                  dwScale
-);
+DWORD
+VFWAPIV
+ICDrawBegin(
+  _In_ HIC hic,
+  _In_ DWORD dwFlags,
+  _In_opt_ HPALETTE hpal,
+  _In_opt_ HWND hwnd,
+  _In_opt_ HDC hdc,
+  _In_ INT xDst,
+  _In_ INT yDst,
+  _In_ INT dxDst,
+  _In_ INT dyDst,
+  _In_ LPBITMAPINFOHEADER lpbi,
+  _In_ INT xSrc,
+  _In_ INT ySrc,
+  _In_ INT dxSrc,
+  _In_ INT dySrc,
+  _In_ DWORD dwRate,
+  _In_ DWORD dwScale);
 
 /* as passed to ICM_DRAW_BEGIN */
 typedef struct {
@@ -607,13 +723,27 @@ typedef struct {
        LONG    lTime;
 } ICDRAW;
 
-DWORD VFWAPIV ICDraw(HIC hic,DWORD dwFlags,LPVOID lpFormat,LPVOID lpData,DWORD cbData,LONG lTime);
-
-static inline LRESULT VFWAPI ICDrawSuggestFormat(HIC hic, LPBITMAPINFOHEADER lpbiIn,
-                                                LPBITMAPINFOHEADER lpbiOut,
-                                                int dxSrc, int dySrc,
-                                                int dxDst, int dyDst,
-                                                HIC hicDecomp)
+DWORD
+VFWAPIV
+ICDraw(
+  _In_ HIC hic,
+  _In_ DWORD dwFlags,
+  _In_ LPVOID lpFormat,
+  _In_reads_bytes_opt_(cbData) LPVOID lpData,
+  _In_ DWORD cbData,
+  _In_ LONG lTime);
+
+static inline
+LRESULT
+VFWAPI
+ICDrawSuggestFormat(_In_ HIC hic,
+                    _In_ LPBITMAPINFOHEADER lpbiIn,
+                    _Out_ LPBITMAPINFOHEADER lpbiOut,
+                    _In_ int dxSrc,
+                    _In_ int dySrc,
+                    _In_ int dxDst,
+                    _In_ int dyDst,
+                    _In_ HIC hicDecomp)
 {
     ICDRAWSUGGEST ic;
 
@@ -666,8 +796,13 @@ static inline LRESULT VFWAPI ICDrawSuggestFormat(HIC hic, LPBITMAPINFOHEADER lpb
 #define ICDrawRenderBuffer(hic) \
     ICSendMessage(hic, ICM_DRAW_RENDERBUFFER, 0, 0)
 
-static inline LRESULT VFWAPI ICSetStatusProc(HIC hic, DWORD dwFlags, LRESULT lParam,
-                                            LONG (CALLBACK *fpfnStatus)(LPARAM, UINT, LONG))
+static inline
+LRESULT
+VFWAPI
+ICSetStatusProc(_In_ HIC hic,
+                _In_ DWORD dwFlags,
+                _In_ LRESULT lParam,
+                _In_ LONG(CALLBACK *fpfnStatus)(_In_ LPARAM, _In_ UINT, _In_ LONG))
 {
     ICSETSTATUSPROC ic;
 
@@ -700,20 +835,39 @@ typedef struct {
 
 #define ICMF_COMPVARS_VALID    0x00000001
 
-BOOL VFWAPI ICCompressorChoose(HWND hwnd, UINT uiFlags, LPVOID pvIn, LPVOID lpData,
-                              PCOMPVARS pc, LPSTR lpszTitle);
+BOOL
+VFWAPI
+ICCompressorChoose(
+  _In_opt_ HWND hwnd,
+  _In_ UINT uiFlags,
+  _In_opt_ LPVOID pvIn,
+  _In_opt_ LPVOID lpData,
+  _Inout_ PCOMPVARS pc,
+  _In_opt_ LPSTR lpszTitle);
 
 #define ICMF_CHOOSE_KEYFRAME           0x0001
 #define ICMF_CHOOSE_DATARATE           0x0002
 #define ICMF_CHOOSE_PREVIEW            0x0004
 #define ICMF_CHOOSE_ALLCOMPRESSORS     0x0008
 
-BOOL VFWAPI ICSeqCompressFrameStart(PCOMPVARS pc, LPBITMAPINFO lpbiIn);
-void VFWAPI ICSeqCompressFrameEnd(PCOMPVARS pc);
+BOOL
+VFWAPI
+ICSeqCompressFrameStart(
+  _In_ PCOMPVARS pc,
+  _In_ LPBITMAPINFO lpbiIn);
+
+void VFWAPI ICSeqCompressFrameEnd(_In_ PCOMPVARS pc);
 
-LPVOID VFWAPI ICSeqCompressFrame(PCOMPVARS pc, UINT uiFlags, LPVOID lpBits,
-                                BOOL *pfKey, LONG *plSize);
-void VFWAPI ICCompressorFree(PCOMPVARS pc);
+LPVOID
+VFWAPI
+ICSeqCompressFrame(
+  _In_ PCOMPVARS pc,
+  _Reserved_ UINT uiFlags,
+  _In_ LPVOID lpBits,
+  _Out_ BOOL *pfKey,
+  _Inout_opt_ LONG *plSize);
+
+void VFWAPI ICCompressorFree(_In_ PCOMPVARS pc);
 
 /********************* AVIFILE function declarations *************************/
 
@@ -998,21 +1152,21 @@ DEFINE_AVIGUID(CLSID_AVIFile,           0x00020000, 0, 0);
 DECLARE_INTERFACE_(IAVIStream,IUnknown)
 {
     /*** IUnknown methods ***/
-    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
+    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, _Outptr_ void** ppvObject) PURE;
     STDMETHOD_(ULONG,AddRef)(THIS) PURE;
     STDMETHOD_(ULONG,Release)(THIS) PURE;
     /*** IAVIStream methods ***/
     STDMETHOD(Create)(THIS_ LPARAM lParam1, LPARAM lParam2) PURE;
-    STDMETHOD(Info)(THIS_ AVISTREAMINFOW *psi, LONG lSize) PURE;
-    STDMETHOD_(LONG,FindSample)(THIS_ LONG lPos, LONG lFlags) PURE;
-    STDMETHOD(ReadFormat)(THIS_ LONG lPos, LPVOID lpFormat, LONG *lpcbFormat) PURE;
-    STDMETHOD(SetFormat)(THIS_ LONG lPos, LPVOID lpFormat, LONG cbFormat) PURE;
-    STDMETHOD(Read)(THIS_ LONG lStart, LONG lSamples, LPVOID lpBuffer, LONG cbBuffer, LONG *plBytes, LONG *plSamples) PURE;
-    STDMETHOD(Write)(THIS_ LONG lStart, LONG lSamples, LPVOID lpBuffer, LONG cbBuffer, DWORD dwFlags, LONG *plSampWritten, LONG *plBytesWritten) PURE;
-    STDMETHOD(Delete)(THIS_ LONG lStart, LONG lSamples) PURE;
-    STDMETHOD(ReadData)(THIS_ DWORD fcc, LPVOID lpBuffer, LONG *lpcbBuffer) PURE;
-    STDMETHOD(WriteData)(THIS_ DWORD fcc, LPVOID lpBuffer, LONG cbBuffer) PURE;
-    STDMETHOD(SetInfo)(THIS_ AVISTREAMINFOW *plInfo, LONG cbInfo) PURE;
+    STDMETHOD(Info)(THIS_ _Out_writes_bytes_(lSize) AVISTREAMINFOW *psi, _In_ LONG lSize) PURE;
+    STDMETHOD_(LONG,FindSample)(THIS_ _In_ LONG lPos, _In_ LONG lFlags) PURE;
+    STDMETHOD(ReadFormat)(THIS_ _In_ LONG lPos, _Out_writes_bytes_to_opt_(*lpcbFormat, *lpcbFormat) LPVOID lpFormat, _Inout_ LONG *lpcbFormat) PURE;
+    STDMETHOD(SetFormat)(THIS_ _In_ LONG lPos, _In_reads_bytes_(cbFormat) LPVOID lpFormat, _In_ LONG cbFormat) PURE;
+    STDMETHOD(Read)(THIS_ _In_ LONG lStart, _In_ LONG lSamples, _Out_writes_bytes_opt_(cbBuffer) LPVOID lpBuffer, _In_ LONG cbBuffer, _Out_opt_ LONG *plBytes, _Out_opt_ LONG *plSamples) PURE;
+    STDMETHOD(Write)(THIS_ _In_ LONG lStart, _In_ LONG lSamples, _In_reads_bytes_(cbBuffer) LPVOID lpBuffer, _In_ LONG cbBuffer, _In_ DWORD dwFlags, _Out_opt_ LONG *plSampWritten, _Out_opt_ LONG *plBytesWritten) PURE;
+    STDMETHOD(Delete)(THIS_ _In_ LONG lStart, _In_ LONG lSamples) PURE;
+    STDMETHOD(ReadData)(THIS_ _In_ DWORD fcc, _Out_writes_bytes_to_opt_(*lpcbBuffer, *lpcbBuffer) LPVOID lpBuffer, _Inout_ LONG *lpcbBuffer) PURE;
+    STDMETHOD(WriteData)(THIS_ _In_ DWORD fcc, _In_reads_bytes_(cbBuffer) LPVOID lpBuffer, _In_ LONG cbBuffer) PURE;
+    STDMETHOD(SetInfo)(THIS_ _In_reads_bytes_(cbInfo) AVISTREAMINFOW *plInfo, _In_ LONG cbInfo) PURE;
 };
 #undef INTERFACE
 
@@ -1039,65 +1193,237 @@ DECLARE_INTERFACE_(IAVIStream,IUnknown)
 
 ULONG WINAPI AVIStreamAddRef(PAVISTREAM iface);
 ULONG WINAPI AVIStreamRelease(PAVISTREAM iface);
-HRESULT WINAPI AVIStreamCreate(PAVISTREAM*,LONG,LONG,CLSID*);
-HRESULT WINAPI AVIStreamInfoA(PAVISTREAM iface,AVISTREAMINFOA *asi,LONG size);
-HRESULT WINAPI AVIStreamInfoW(PAVISTREAM iface,AVISTREAMINFOW *asi,LONG size);
+
+HRESULT
+WINAPI
+AVIStreamCreate(
+  _Outptr_ PAVISTREAM*,
+  _In_ LONG,
+  _In_ LONG,
+  _In_opt_ CLSID*);
+
+HRESULT
+WINAPI
+AVIStreamInfoA(
+  _In_ PAVISTREAM iface,
+  _Out_writes_bytes_(size) AVISTREAMINFOA *asi,
+  _In_ LONG size);
+
+HRESULT
+WINAPI
+AVIStreamInfoW(
+  _In_ PAVISTREAM iface,
+  _Out_writes_bytes_(size) AVISTREAMINFOW *asi,
+  _In_ LONG size);
+
 #define AVIStreamInfo WINELIB_NAME_AW(AVIStreamInfo)
-LONG WINAPI AVIStreamFindSample(PAVISTREAM pstream, LONG pos, LONG flags);
-HRESULT WINAPI AVIStreamReadFormat(PAVISTREAM iface,LONG pos,LPVOID format,LONG *formatsize);
-HRESULT WINAPI AVIStreamSetFormat(PAVISTREAM iface,LONG pos,LPVOID format,LONG formatsize);
-HRESULT WINAPI AVIStreamRead(PAVISTREAM iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,LONG *bytesread,LONG *samplesread);
-HRESULT WINAPI AVIStreamWrite(PAVISTREAM iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,DWORD flags,LONG *sampwritten,LONG *byteswritten);
-HRESULT WINAPI AVIStreamReadData(PAVISTREAM iface,DWORD fcc,LPVOID lp,LONG *lpread);
-HRESULT WINAPI AVIStreamWriteData(PAVISTREAM iface,DWORD fcc,LPVOID lp,LONG size);
-
-PGETFRAME WINAPI AVIStreamGetFrameOpen(PAVISTREAM pavi,LPBITMAPINFOHEADER lpbiWanted);
-LPVOID  WINAPI AVIStreamGetFrame(PGETFRAME pg,LONG pos);
-HRESULT WINAPI AVIStreamGetFrameClose(PGETFRAME pg);
-
-HRESULT WINAPI AVIMakeCompressedStream(PAVISTREAM*ppsCompressed,PAVISTREAM ppsSource,AVICOMPRESSOPTIONS *lpOptions,CLSID*pclsidHandler);
-HRESULT WINAPI AVIMakeFileFromStreams(PAVIFILE *ppfile, int nStreams, PAVISTREAM *ppStreams);
-HRESULT WINAPI AVIMakeStreamFromClipboard(UINT cfFormat, HANDLE hGlobal, PAVISTREAM * ppstream);
-
-HRESULT WINAPI AVIStreamOpenFromFileA(PAVISTREAM *ppavi, LPCSTR szFile,
-                                     DWORD fccType, LONG lParam,
-                                     UINT mode, CLSID *pclsidHandler);
-HRESULT WINAPI AVIStreamOpenFromFileW(PAVISTREAM *ppavi, LPCWSTR szFile,
-                                     DWORD fccType, LONG lParam,
-                                     UINT mode, CLSID *pclsidHandler);
+
+LONG
+WINAPI
+AVIStreamFindSample(
+  _In_ PAVISTREAM pstream,
+  _In_ LONG pos,
+  _In_ LONG flags);
+
+HRESULT
+WINAPI
+AVIStreamReadFormat(
+  _In_ PAVISTREAM iface,
+  _In_ LONG pos,
+  _Out_writes_bytes_to_opt_(*formatsize, *formatsize) LPVOID format,
+  _Inout_ LONG *formatsize);
+
+HRESULT
+WINAPI
+AVIStreamSetFormat(
+  _In_ PAVISTREAM iface,
+  _In_ LONG pos,
+  _In_reads_bytes_(formatsize) LPVOID format,
+  _In_ LONG formatsize);
+
+HRESULT
+WINAPI
+AVIStreamRead(
+  _In_ PAVISTREAM iface,
+  _In_ LONG start,
+  _In_ LONG samples,
+  _Out_writes_bytes_opt_(buffersize) LPVOID buffer,
+  _In_ LONG buffersize,
+  _Out_opt_ LONG *bytesread,
+  _Out_opt_ LONG *samplesread);
+
+HRESULT
+WINAPI
+AVIStreamWrite(
+  _In_ PAVISTREAM iface,
+  _In_ LONG start,
+  _In_ LONG samples,
+  _In_reads_bytes_(buffersize) LPVOID buffer,
+  _In_ LONG buffersize,
+  _In_ DWORD flags,
+  _Out_opt_ LONG *sampwritten,
+  _Out_opt_ LONG *byteswritten);
+
+HRESULT
+WINAPI
+AVIStreamReadData(
+  _In_ PAVISTREAM iface,
+  _In_ DWORD fcc,
+  _Out_writes_bytes_to_opt_(*lpread, *lpread) LPVOID lp,
+  _Inout_ LONG *lpread);
+
+HRESULT
+WINAPI
+AVIStreamWriteData(
+  _In_ PAVISTREAM iface,
+  _In_ DWORD fcc,
+  _In_reads_bytes_(size) LPVOID lp,
+  _In_ LONG size);
+
+PGETFRAME
+WINAPI
+AVIStreamGetFrameOpen(
+  _In_ PAVISTREAM pavi,
+  _In_opt_ LPBITMAPINFOHEADER lpbiWanted);
+
+LPVOID  WINAPI AVIStreamGetFrame(_In_ PGETFRAME pg, _In_ LONG pos);
+HRESULT WINAPI AVIStreamGetFrameClose(_In_ PGETFRAME pg);
+
+HRESULT
+WINAPI
+AVIMakeCompressedStream(
+  _Outptr_ PAVISTREAM *ppsCompressed,
+  _In_ PAVISTREAM ppsSource,
+  _In_ AVICOMPRESSOPTIONS *lpOptions,
+  _In_opt_ CLSID *pclsidHandler);
+
+HRESULT
+WINAPI
+AVIMakeFileFromStreams(
+  _Outptr_ PAVIFILE *ppfile,
+  _In_ int nStreams,
+  _In_reads_(nStreams) PAVISTREAM *ppStreams);
+
+HRESULT
+WINAPI
+AVIMakeStreamFromClipboard(
+  UINT cfFormat,
+  _In_ HANDLE hGlobal,
+  _Outptr_ PAVISTREAM * ppstream);
+
+HRESULT
+WINAPI
+AVIStreamOpenFromFileA(
+  _Outptr_ PAVISTREAM *ppavi,
+  _In_ LPCSTR szFile,
+  _In_ DWORD fccType,
+  _In_ LONG lParam,
+  _In_ UINT mode,
+  _In_opt_ CLSID *pclsidHandler);
+
+HRESULT
+WINAPI
+AVIStreamOpenFromFileW(
+  _Outptr_ PAVISTREAM *ppavi,
+  _In_ LPCWSTR szFile,
+  _In_ DWORD fccType,
+  _In_ LONG lParam,
+  _In_ UINT mode,
+  _In_opt_ CLSID *pclsidHandler);
+
 #define AVIStreamOpenFromFile WINELIB_NAME_AW(AVIStreamOpenFromFile)
 
-LONG WINAPI AVIStreamBeginStreaming(PAVISTREAM pavi, LONG lStart, LONG lEnd, LONG lRate);
-LONG WINAPI AVIStreamEndStreaming(PAVISTREAM pavi);
+LONG
+WINAPI
+AVIStreamBeginStreaming(
+  _In_ PAVISTREAM pavi,
+  _In_ LONG lStart,
+  _In_ LONG lEnd,
+  _In_ LONG lRate);
+
+LONG WINAPI AVIStreamEndStreaming(_In_ PAVISTREAM pavi);
+
+HRESULT
+WINAPI
+AVIBuildFilterA(
+  _Out_writes_(cbFilter) LPSTR szFilter,
+  _In_ LONG cbFilter,
+  _In_ BOOL fSaving);
+
+HRESULT
+WINAPI
+AVIBuildFilterW(
+  _Out_writes_(cbFilter) LPWSTR szFilter,
+  _In_ LONG cbFilter,
+  _In_ BOOL fSaving);
 
-HRESULT WINAPI AVIBuildFilterA(LPSTR szFilter, LONG cbFilter, BOOL fSaving);
-HRESULT WINAPI AVIBuildFilterW(LPWSTR szFilter, LONG cbFilter, BOOL fSaving);
 #define AVIBuildFilter WINELIB_NAME_AW(AVIBuildFilter)
 
-BOOL WINAPI AVISaveOptions(HWND hWnd,UINT uFlags,INT nStream,
-                          PAVISTREAM *ppavi,LPAVICOMPRESSOPTIONS *ppOptions);
-HRESULT WINAPI AVISaveOptionsFree(INT nStreams,LPAVICOMPRESSOPTIONS*ppOptions);
+BOOL
+WINAPI
+AVISaveOptions(
+  _In_ HWND hWnd,
+  _In_ UINT uFlags,
+  _In_ INT nStream,
+  _In_reads_(nStream) PAVISTREAM *ppavi,
+  _Inout_updates_(nStream) LPAVICOMPRESSOPTIONS *ppOptions);
+
+HRESULT
+WINAPI
+AVISaveOptionsFree(
+  INT nStreams,
+  _In_reads_(nStreams) LPAVICOMPRESSOPTIONS *ppOptions);
+
+HRESULT
+CDECL
+AVISaveA(
+  LPCSTR szFile,
+  _In_opt_ CLSID *pclsidHandler,
+  _In_ AVISAVECALLBACK lpfnCallback,
+  _In_ int nStreams,
+  _In_ PAVISTREAM pavi,
+  _In_ LPAVICOMPRESSOPTIONS lpOptions,
+  ...);
+
+HRESULT
+CDECL
+AVISaveW(
+  LPCWSTR szFile,
+  _In_opt_ CLSID *pclsidHandler,
+  _In_ AVISAVECALLBACK lpfnCallback,
+  _In_ int nStreams,
+  _In_ PAVISTREAM pavi,
+  _In_ LPAVICOMPRESSOPTIONS lpOptions,
+  ...);
 
-HRESULT CDECL AVISaveA(LPCSTR szFile, CLSID *pclsidHandler,
-             AVISAVECALLBACK lpfnCallback, int nStreams,
-             PAVISTREAM pavi, LPAVICOMPRESSOPTIONS lpOptions, ...);
-HRESULT CDECL AVISaveW(LPCWSTR szFile, CLSID *pclsidHandler,
-             AVISAVECALLBACK lpfnCallback, int nStreams,
-             PAVISTREAM pavi, LPAVICOMPRESSOPTIONS lpOptions, ...);
 #define AVISave WINELIB_NAME_AW(AVISave)
 
-HRESULT WINAPI AVISaveVA(LPCSTR szFile, CLSID *pclsidHandler,
-                        AVISAVECALLBACK lpfnCallback, int nStream,
-                        PAVISTREAM *ppavi, LPAVICOMPRESSOPTIONS *plpOptions);
-HRESULT WINAPI AVISaveVW(LPCWSTR szFile, CLSID *pclsidHandler,
-                        AVISAVECALLBACK lpfnCallback, int nStream,
-                        PAVISTREAM *ppavi, LPAVICOMPRESSOPTIONS *plpOptions);
+HRESULT
+WINAPI
+AVISaveVA(
+  LPCSTR szFile,
+  _In_opt_ CLSID *pclsidHandler,
+  _In_ AVISAVECALLBACK lpfnCallback,
+  _In_ int nStream,
+  _In_reads_(nStream) PAVISTREAM *ppavi,
+  _In_reads_(nStream) LPAVICOMPRESSOPTIONS *plpOptions);
+
+HRESULT
+WINAPI
+AVISaveVW(
+  LPCWSTR szFile,
+  _In_opt_ CLSID *pclsidHandler,
+  _In_ AVISAVECALLBACK lpfnCallback,
+  _In_ int nStream,
+  _In_reads_(nStream) PAVISTREAM *ppavi,
+  _In_reads_(nStream) LPAVICOMPRESSOPTIONS *plpOptions);
+
 #define AVISaveV WINELIB_NAME_AW(AVISaveV)
 
-LONG WINAPI AVIStreamStart(PAVISTREAM iface);
-LONG WINAPI AVIStreamLength(PAVISTREAM iface);
-LONG WINAPI AVIStreamSampleToTime(PAVISTREAM pstream, LONG lSample);
-LONG WINAPI AVIStreamTimeToSample(PAVISTREAM pstream, LONG lTime);
+LONG WINAPI AVIStreamStart(_In_ PAVISTREAM iface);
+LONG WINAPI AVIStreamLength(_In_ PAVISTREAM iface);
+LONG WINAPI AVIStreamSampleToTime(_In_ PAVISTREAM pstream, _In_ LONG lSample);
+LONG WINAPI AVIStreamTimeToSample(_In_ PAVISTREAM pstream, _In_ LONG lTime);
 
 #define AVIFileClose(pavi) \
     AVIFileRelease(pavi)
@@ -1140,12 +1466,12 @@ LONG WINAPI AVIStreamTimeToSample(PAVISTREAM pstream, LONG lTime);
 DECLARE_INTERFACE_(IAVIStreaming,IUnknown)
 {
     /*** IUnknown methods ***/
-    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
+    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, _Outptr_ void** ppvObject) PURE;
     STDMETHOD_(ULONG,AddRef)(THIS) PURE;
     STDMETHOD_(ULONG,Release)(THIS) PURE;
     /*** IAVIStreaming methods ***/
-    STDMETHOD(Begin)(IAVIStreaming*iface,LONG lStart,LONG lEnd,LONG lRate) PURE;
-    STDMETHOD(End)(IAVIStreaming*iface) PURE;
+    STDMETHOD(Begin)(IAVIStreaming *iface, _In_ LONG lStart, _In_ LONG lEnd, _In_ LONG lRate) PURE;
+    STDMETHOD(End)(IAVIStreaming *iface) PURE;
 };
 #undef INTERFACE
 
@@ -1166,15 +1492,15 @@ DECLARE_INTERFACE_(IAVIStreaming,IUnknown)
 DECLARE_INTERFACE_(IAVIEditStream,IUnknown)
 {
     /*** IUnknown methods ***/
-    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
+    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, _Outptr_ void** ppvObject) PURE;
     STDMETHOD_(ULONG,AddRef)(THIS) PURE;
     STDMETHOD_(ULONG,Release)(THIS) PURE;
     /*** IAVIEditStream methods ***/
-    STDMETHOD(Cut)(IAVIEditStream*iface,LONG*plStart,LONG*plLength,PAVISTREAM*ppResult) PURE;
-    STDMETHOD(Copy)(IAVIEditStream*iface,LONG*plStart,LONG*plLength,PAVISTREAM*ppResult) PURE;
-    STDMETHOD(Paste)(IAVIEditStream*iface,LONG*plStart,LONG*plLength,PAVISTREAM pSource,LONG lStart,LONG lEnd) PURE;
-    STDMETHOD(Clone)(IAVIEditStream*iface,PAVISTREAM*ppResult) PURE;
-    STDMETHOD(SetInfo)(IAVIEditStream*iface,LPAVISTREAMINFOW asi, LONG size) PURE;
+    STDMETHOD(Cut)(IAVIEditStream *iface, _Inout_ LONG *plStart, _Inout_ LONG *plLength, _Outptr_ PAVISTREAM *ppResult) PURE;
+    STDMETHOD(Copy)(IAVIEditStream *iface, _Inout_ LONG *plStart, _Inout_ LONG *plLength, _Outptr_ PAVISTREAM *ppResult) PURE;
+    STDMETHOD(Paste)(IAVIEditStream *iface, _Inout_ LONG *plStart, _Inout_ LONG *plLength, _Inout_ PAVISTREAM pSource, _In_ LONG lStart, _In_ LONG lEnd) PURE;
+    STDMETHOD(Clone)(IAVIEditStream *iface, _Outptr_ PAVISTREAM *ppResult) PURE;
+    STDMETHOD(SetInfo)(IAVIEditStream *iface, _In_reads_bytes_(size) LPAVISTREAMINFOW asi, _In_ LONG size) PURE;
 };
 #undef INTERFACE
 
@@ -1191,23 +1517,62 @@ DECLARE_INTERFACE_(IAVIEditStream,IUnknown)
 #define IAVIEditStream_SetInfo(p,a,b)       (p)->lpVtbl->SetInfo(p,a,b)
 #endif
 
-HRESULT WINAPI CreateEditableStream(PAVISTREAM *ppEditable,PAVISTREAM pSource);
-HRESULT WINAPI EditStreamClone(PAVISTREAM pStream, PAVISTREAM *ppResult);
-HRESULT WINAPI EditStreamCopy(PAVISTREAM pStream, LONG *plStart,
-                             LONG *plLength, PAVISTREAM *ppResult);
-HRESULT WINAPI EditStreamCut(PAVISTREAM pStream, LONG *plStart,
-                            LONG *plLength, PAVISTREAM *ppResult);
-HRESULT WINAPI EditStreamPaste(PAVISTREAM pDest, LONG *plStart, LONG *plLength,
-                              PAVISTREAM pSource, LONG lStart, LONG lEnd);
-
-HRESULT WINAPI EditStreamSetInfoA(PAVISTREAM pstream, LPAVISTREAMINFOA asi,
-                                 LONG size);
-HRESULT WINAPI EditStreamSetInfoW(PAVISTREAM pstream, LPAVISTREAMINFOW asi,
-                                 LONG size);
+HRESULT
+WINAPI
+CreateEditableStream(
+  _Outptr_ PAVISTREAM *ppEditable,
+  _In_ PAVISTREAM pSource);
+
+HRESULT
+WINAPI
+EditStreamClone(
+  _In_ PAVISTREAM pStream,
+  _Outptr_ PAVISTREAM *ppResult);
+
+HRESULT
+WINAPI
+EditStreamCopy(
+  _In_ PAVISTREAM pStream,
+  _Inout_ LONG *plStart,
+  _Inout_ LONG *plLength,
+  _Outptr_ PAVISTREAM *ppResult);
+
+HRESULT
+WINAPI
+EditStreamCut(
+  _In_ PAVISTREAM pStream,
+  _Inout_ LONG *plStart,
+  _Inout_ LONG *plLength,
+  _Outptr_ PAVISTREAM *ppResult);
+
+HRESULT
+WINAPI
+EditStreamPaste(
+  _In_ PAVISTREAM pDest,
+  _Inout_ LONG *plStart,
+  _Inout_ LONG *plLength,
+  _In_ PAVISTREAM pSource,
+  _In_ LONG lStart,
+  _In_ LONG lEnd);
+
+HRESULT
+WINAPI
+EditStreamSetInfoA(
+  _In_ PAVISTREAM pstream,
+  _In_reads_bytes_(size) LPAVISTREAMINFOA asi,
+  _In_ LONG size);
+
+HRESULT
+WINAPI
+EditStreamSetInfoW(
+  _In_ PAVISTREAM pstream,
+  _In_reads_bytes_(size) LPAVISTREAMINFOW asi,
+  _In_ LONG size);
+
 #define EditStreamSetInfo WINELIB_NAME_AW(EditStreamSetInfo)
 
-HRESULT WINAPI EditStreamSetNameA(PAVISTREAM pstream, LPCSTR szName);
-HRESULT WINAPI EditStreamSetNameW(PAVISTREAM pstream, LPCWSTR szName);
+HRESULT WINAPI EditStreamSetNameA(_In_ PAVISTREAM pstream, _In_ LPCSTR szName);
+HRESULT WINAPI EditStreamSetNameW(_In_ PAVISTREAM pstream, _In_ LPCWSTR szName);
 #define EditStreamSetName WINELIB_NAME_AW(EditStreamSetName)
 
 /*****************************************************************************
@@ -1218,17 +1583,17 @@ HRESULT WINAPI EditStreamSetNameW(PAVISTREAM pstream, LPCWSTR szName);
 DECLARE_INTERFACE_(IAVIFile,IUnknown)
 {
     /*** IUnknown methods ***/
-    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
+    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, _Outptr_ void** ppvObject) PURE;
     STDMETHOD_(ULONG,AddRef)(THIS) PURE;
     STDMETHOD_(ULONG,Release)(THIS) PURE;
     /*** IAVIFile methods ***/
-    STDMETHOD(Info)(THIS_ AVIFILEINFOW *pfi, LONG lSize) PURE;
-    STDMETHOD(GetStream)(THIS_ PAVISTREAM *ppStream, DWORD fccType, LONG lParam) PURE;
-    STDMETHOD(CreateStream)(THIS_ PAVISTREAM *ppStream, AVISTREAMINFOW *psi) PURE;
-    STDMETHOD(WriteData)(THIS_ DWORD fcc, LPVOID lpBuffer, LONG cbBuffer) PURE;
-    STDMETHOD(ReadData)(THIS_ DWORD fcc, LPVOID lpBuffer, LONG *lpcbBuffer) PURE;
+    STDMETHOD(Info)(THIS_ _Out_writes_bytes_(lSize) AVIFILEINFOW *pfi, _In_ LONG lSize) PURE;
+    STDMETHOD(GetStream)(THIS_ _Outptr_ PAVISTREAM *ppStream, _In_ DWORD fccType, _In_ LONG lParam) PURE;
+    STDMETHOD(CreateStream)(THIS_ _Outptr_ PAVISTREAM *ppStream, _In_ AVISTREAMINFOW *psi) PURE;
+    STDMETHOD(WriteData)(THIS_ _In_ DWORD fcc, _In_reads_bytes_(cbBuffer) LPVOID lpBuffer, _In_ LONG cbBuffer) PURE;
+    STDMETHOD(ReadData)(THIS_ _In_ DWORD fcc, _Out_writes_bytes_to_(*lpcbBuffer, *lpcbBuffer) LPVOID lpBuffer, _Inout_ LONG *lpcbBuffer) PURE;
     STDMETHOD(EndRecord)(THIS) PURE;
-    STDMETHOD(DeleteStream)(THIS_ DWORD fccType, LONG lParam) PURE;
+    STDMETHOD(DeleteStream)(THIS_ _In_ DWORD fccType, _In_ LONG lParam) PURE;
 };
 #undef INTERFACE
 
@@ -1250,22 +1615,84 @@ DECLARE_INTERFACE_(IAVIFile,IUnknown)
 void WINAPI AVIFileInit(void);
 void WINAPI AVIFileExit(void);
 
-HRESULT WINAPI AVIFileOpenA(PAVIFILE* ppfile,LPCSTR szFile,UINT uMode,LPCLSID lpHandler);
-HRESULT WINAPI AVIFileOpenW(PAVIFILE* ppfile,LPCWSTR szFile,UINT uMode,LPCLSID lpHandler);
+HRESULT
+WINAPI
+AVIFileOpenA(
+  _Outptr_ PAVIFILE* ppfile,
+  _In_ LPCSTR szFile,
+  UINT uMode,
+  _In_opt_ LPCLSID lpHandler);
+
+HRESULT
+WINAPI
+AVIFileOpenW(
+  _Outptr_ PAVIFILE* ppfile,
+  _In_ LPCWSTR szFile,
+  UINT uMode,
+  _In_opt_ LPCLSID lpHandler);
+
 #define AVIFileOpen WINELIB_NAME_AW(AVIFileOpen)
 
 ULONG   WINAPI AVIFileAddRef(PAVIFILE pfile);
 ULONG   WINAPI AVIFileRelease(PAVIFILE pfile);
-HRESULT WINAPI AVIFileInfoA(PAVIFILE pfile,PAVIFILEINFOA pfi,LONG lSize);
-HRESULT WINAPI AVIFileInfoW(PAVIFILE pfile,PAVIFILEINFOW pfi,LONG lSize);
+
+HRESULT
+WINAPI
+AVIFileInfoA(
+  _In_ PAVIFILE pfile,
+  _Out_writes_bytes_(lSize) PAVIFILEINFOA pfi,
+  _In_ LONG lSize);
+
+HRESULT
+WINAPI
+AVIFileInfoW(
+  _In_ PAVIFILE pfile,
+  _Out_writes_bytes_(lSize) PAVIFILEINFOW pfi,
+  _In_ LONG lSize);
+
 #define AVIFileInfo WINELIB_NAME_AW(AVIFileInfo)
-HRESULT WINAPI AVIFileGetStream(PAVIFILE pfile,PAVISTREAM* avis,DWORD fccType,LONG lParam);
-HRESULT WINAPI AVIFileCreateStreamA(PAVIFILE pfile,PAVISTREAM* ppavi,AVISTREAMINFOA* psi);
-HRESULT WINAPI AVIFileCreateStreamW(PAVIFILE pfile,PAVISTREAM* ppavi,AVISTREAMINFOW* psi);
+
+HRESULT
+WINAPI
+AVIFileGetStream(
+  _In_ PAVIFILE pfile,
+  _Outptr_ PAVISTREAM* avis,
+  _In_ DWORD fccType,
+  _In_ LONG lParam);
+
+HRESULT
+WINAPI
+AVIFileCreateStreamA(
+  _In_ PAVIFILE pfile,
+  _Outptr_ PAVISTREAM* ppavi,
+  _In_ AVISTREAMINFOA* psi);
+
+HRESULT
+WINAPI
+AVIFileCreateStreamW(
+  _In_ PAVIFILE pfile,
+  _Outptr_ PAVISTREAM* ppavi,
+  _In_ AVISTREAMINFOW* psi);
+
 #define AVIFileCreateStream WINELIB_NAME_AW(AVIFileCreateStream)
-HRESULT WINAPI AVIFileWriteData(PAVIFILE pfile,DWORD fcc,LPVOID lp,LONG size);
-HRESULT WINAPI AVIFileReadData(PAVIFILE pfile,DWORD fcc,LPVOID lp,LPLONG size);
-HRESULT WINAPI AVIFileEndRecord(PAVIFILE pfile);
+
+HRESULT
+WINAPI
+AVIFileWriteData(
+  _In_ PAVIFILE pfile,
+  _In_ DWORD fcc,
+  _In_reads_bytes_(size) LPVOID lp,
+  _In_ LONG size);
+
+HRESULT
+WINAPI
+AVIFileReadData(
+  _In_ PAVIFILE pfile,
+  _In_ DWORD fcc,
+  _Out_writes_bytes_to_(*size, *size) LPVOID lp,
+  _Inout_ LPLONG size);
+
+HRESULT WINAPI AVIFileEndRecord(_In_ PAVIFILE pfile);
 
 /*****************************************************************************
  * IGetFrame interface
@@ -1274,14 +1701,14 @@ HRESULT WINAPI AVIFileEndRecord(PAVIFILE pfile);
 DECLARE_INTERFACE_(IGetFrame,IUnknown)
 {
     /*** IUnknown methods ***/
-    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
+    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, _Outptr_ void** ppvObject) PURE;
     STDMETHOD_(ULONG,AddRef)(THIS) PURE;
     STDMETHOD_(ULONG,Release)(THIS) PURE;
     /*** IGetFrame methods ***/
-    STDMETHOD_(LPVOID,GetFrame)(THIS_ LONG lPos) PURE;
-    STDMETHOD(Begin)(THIS_ LONG lStart, LONG lEnd, LONG lRate) PURE;
+    STDMETHOD_(LPVOID,GetFrame)(THIS_ _In_ LONG lPos) PURE;
+    STDMETHOD(Begin)(THIS_ _In_ LONG lStart, _In_ LONG lEnd, _In_ LONG lRate) PURE;
     STDMETHOD(End)(THIS) PURE;
-    STDMETHOD(SetFormat)(THIS_ LPBITMAPINFOHEADER lpbi, LPVOID lpBits, INT x, INT y, INT dx, INT dy) PURE;
+    STDMETHOD(SetFormat)(THIS_ _In_ LPBITMAPINFOHEADER lpbi, _In_opt_ LPVOID lpBits, _In_ INT x, _In_ INT y, _In_ INT dx, _In_ INT dy) PURE;
 };
 #undef INTERFACE
 
@@ -1298,15 +1725,15 @@ DECLARE_INTERFACE_(IGetFrame,IUnknown)
 #endif
 
 HRESULT WINAPI AVIClearClipboard(void);
-HRESULT WINAPI AVIGetFromClipboard(PAVIFILE *ppfile);
-HRESULT WINAPI AVIPutFileOnClipboard(PAVIFILE pfile);
+HRESULT WINAPI AVIGetFromClipboard(_Outptr_ PAVIFILE *ppfile);
+HRESULT WINAPI AVIPutFileOnClipboard(_In_ PAVIFILE pfile);
 
 #ifdef OFN_READONLY
-BOOL WINAPI GetOpenFileNamePreviewA(LPOPENFILENAMEA lpofn);
-BOOL WINAPI GetOpenFileNamePreviewW(LPOPENFILENAMEW lpofn);
+BOOL WINAPI GetOpenFileNamePreviewA(_Inout_ LPOPENFILENAMEA lpofn);
+BOOL WINAPI GetOpenFileNamePreviewW(_Inout_ LPOPENFILENAMEW lpofn);
 #define GetOpenFileNamePreview WINELIB_NAME_AW(GetOpenFileNamePreview)
-BOOL WINAPI GetSaveFileNamePreviewA(LPOPENFILENAMEA lpofn);
-BOOL WINAPI GetSaveFileNamePreviewW(LPOPENFILENAMEW lpofn);
+BOOL WINAPI GetSaveFileNamePreviewA(_Inout_ LPOPENFILENAMEA lpofn);
+BOOL WINAPI GetSaveFileNamePreviewW(_Inout_ LPOPENFILENAMEW lpofn);
 #define GetSaveFileNamePreview WINELIB_NAME_AW(GetSaveFileNamePreview)
 #endif
 
@@ -1335,9 +1762,23 @@ BOOL WINAPI GetSaveFileNamePreviewW(LPOPENFILENAMEW lpofn);
 
 BOOL VFWAPIV MCIWndRegisterClass(void);
 
-HWND VFWAPIV MCIWndCreateA(HWND, HINSTANCE, DWORD, LPCSTR);
-HWND VFWAPIV MCIWndCreateW(HWND, HINSTANCE, DWORD, LPCWSTR);
-#define     MCIWndCreate WINELIB_NAME_AW(MCIWndCreate)
+HWND
+VFWAPIV
+MCIWndCreateA(
+  _In_opt_ HWND,
+  _In_opt_ HINSTANCE,
+  _In_ DWORD,
+  _In_opt_ LPCSTR);
+
+HWND
+VFWAPIV
+MCIWndCreateW(
+  _In_opt_ HWND,
+  _In_opt_ HINSTANCE,
+  _In_ DWORD,
+  _In_opt_ LPCWSTR);
+
+#define MCIWndCreate WINELIB_NAME_AW(MCIWndCreate)
 
 #define MCIWNDOPENF_NEW                        0x0001
 
@@ -1574,14 +2015,42 @@ typedef struct
 } DRAWDIBTIME, *LPDRAWDIBTIME; 
 
 HDRAWDIB VFWAPI DrawDibOpen( void );
-UINT VFWAPI DrawDibRealize(HDRAWDIB hdd, HDC hdc, BOOL fBackground);
-
-BOOL VFWAPI DrawDibBegin(HDRAWDIB hdd, HDC hdc, INT dxDst, INT dyDst,
-                        LPBITMAPINFOHEADER lpbi, INT dxSrc, INT dySrc, UINT wFlags);
 
-BOOL VFWAPI DrawDibDraw(HDRAWDIB hdd, HDC hdc, INT xDst, INT yDst, INT dxDst, INT dyDst,
-                       LPBITMAPINFOHEADER lpbi, LPVOID lpBits,
-                       INT xSrc, INT ySrc, INT dxSrc, INT dySrc, UINT wFlags);
+UINT
+VFWAPI
+DrawDibRealize(
+  _In_ HDRAWDIB hdd,
+  _In_ HDC hdc,
+  _In_ BOOL fBackground);
+
+BOOL
+VFWAPI
+DrawDibBegin(
+  _In_ HDRAWDIB hdd,
+  _In_opt_ HDC hdc,
+  _In_ INT dxDst,
+  _In_ INT dyDst,
+  _In_ LPBITMAPINFOHEADER lpbi,
+  _In_ INT dxSrc,
+  _In_ INT dySrc,
+  _In_ UINT wFlags);
+
+BOOL
+VFWAPI
+DrawDibDraw(
+  _In_ HDRAWDIB hdd,
+  _In_ HDC hdc,
+  _In_ INT xDst,
+  _In_ INT yDst,
+  _In_ INT dxDst,
+  _In_ INT dyDst,
+  _In_opt_ LPBITMAPINFOHEADER lpbi,
+  _In_opt_ LPVOID lpBits,
+  _In_ INT xSrc,
+  _In_ INT ySrc,
+  _In_ INT dxSrc,
+  _In_ INT dySrc,
+  _In_ UINT wFlags);
 
 /* DrawDibDraw flags */
 
@@ -1602,19 +2071,34 @@ BOOL VFWAPI DrawDibDraw(HDRAWDIB hdd, HDC hdc, INT xDst, INT yDst, INT dxDst, IN
 #define DDF_SAME_DIB                   DDF_SAME_DRAW
 #define DDF_SAME_SIZE                  DDF_SAME_DRAW
 
-BOOL VFWAPI DrawDibSetPalette(HDRAWDIB hdd, HPALETTE hpal);
-HPALETTE VFWAPI DrawDibGetPalette(HDRAWDIB hdd);
-BOOL VFWAPI DrawDibChangePalette(HDRAWDIB hdd, int iStart, int iLen, LPPALETTEENTRY lppe);
-LPVOID VFWAPI DrawDibGetBuffer(HDRAWDIB hdd, LPBITMAPINFOHEADER lpbi, DWORD dwSize, DWORD dwFlags);
+BOOL VFWAPI DrawDibSetPalette(_In_ HDRAWDIB hdd, _In_opt_ HPALETTE hpal);
+HPALETTE VFWAPI DrawDibGetPalette(_In_ HDRAWDIB hdd);
+
+BOOL
+VFWAPI
+DrawDibChangePalette(
+  _In_ HDRAWDIB hdd,
+  _In_ int iStart,
+  _In_ int iLen,
+  _In_reads_(iLen) LPPALETTEENTRY lppe);
+
+LPVOID
+VFWAPI
+DrawDibGetBuffer(
+  _In_ HDRAWDIB hdd,
+  _Out_ LPBITMAPINFOHEADER lpbi,
+  _In_ DWORD dwSize,
+  _In_ DWORD dwFlags);
+
+BOOL VFWAPI DrawDibStart(_In_ HDRAWDIB hdd, _In_ DWORD rate);
+BOOL VFWAPI DrawDibStop(_In_ HDRAWDIB hdd);
 
-BOOL VFWAPI DrawDibStart(HDRAWDIB hdd, DWORD rate);
-BOOL VFWAPI DrawDibStop(HDRAWDIB hdd);
 #define DrawDibUpdate(hdd, hdc, x, y) \
         DrawDibDraw(hdd, hdc, x, y, 0, 0, NULL, NULL, 0, 0, 0, 0, DDF_UPDATE)
 
-BOOL VFWAPI DrawDibEnd(HDRAWDIB hdd);
-BOOL VFWAPI DrawDibClose(HDRAWDIB hdd);
-BOOL VFWAPI DrawDibTime(HDRAWDIB hdd, LPDRAWDIBTIME lpddtime);
+BOOL VFWAPI DrawDibEnd(_In_ HDRAWDIB hdd);
+BOOL VFWAPI DrawDibClose(_In_ HDRAWDIB hdd);
+BOOL VFWAPI DrawDibTime(_In_ HDRAWDIB hdd, _Out_ LPDRAWDIBTIME lpddtime);
 
 /* display profiling */
 #define PD_CAN_DRAW_DIB         0x0001
@@ -1623,7 +2107,7 @@ BOOL VFWAPI DrawDibTime(HDRAWDIB hdd, LPDRAWDIBTIME lpddtime);
 #define PD_STRETCHDIB_1_2_OK    0x0008
 #define PD_STRETCHDIB_1_N_OK    0x0010
 
-DWORD VFWAPI DrawDibProfileDisplay(LPBITMAPINFOHEADER lpbi);
+DWORD VFWAPI DrawDibProfileDisplay(_In_ LPBITMAPINFOHEADER lpbi);
 
 DECLARE_HANDLE(HVIDEO);
 typedef HVIDEO *LPHVIDEO;
@@ -1917,21 +2401,92 @@ typedef struct tagCaptureParms {
     UINT        AVStreamMaster;
 } CAPTUREPARMS, *PCAPTUREPARMS, *LPCAPTUREPARMS;
 
-typedef LRESULT (CALLBACK* CAPYIELDCALLBACK)  (HWND hWnd);
-typedef LRESULT (CALLBACK* CAPSTATUSCALLBACKW) (HWND hWnd, int nID, LPCWSTR lpsz);
-typedef LRESULT (CALLBACK* CAPERRORCALLBACKW)  (HWND hWnd, int nID, LPCWSTR lpsz);
-typedef LRESULT (CALLBACK* CAPSTATUSCALLBACKA) (HWND hWnd, int nID, LPCSTR lpsz);
-typedef LRESULT (CALLBACK* CAPERRORCALLBACKA)  (HWND hWnd, int nID, LPCSTR lpsz);
-typedef LRESULT (CALLBACK* CAPVIDEOCALLBACK)  (HWND hWnd, LPVIDEOHDR lpVHdr);
-typedef LRESULT (CALLBACK* CAPWAVECALLBACK)   (HWND hWnd, LPWAVEHDR lpWHdr);
-typedef LRESULT (CALLBACK* CAPCONTROLCALLBACK)(HWND hWnd, int nState);
-
-HWND VFWAPI capCreateCaptureWindowA(LPCSTR,DWORD,INT,INT,INT,INT,HWND,INT);
-HWND VFWAPI capCreateCaptureWindowW(LPCWSTR,DWORD,INT,INT,INT,INT,HWND,INT);
-#define     capCreateCaptureWindow WINELIB_NAME_AW(capCreateCaptureWindow)
-BOOL VFWAPI capGetDriverDescriptionA(WORD,LPSTR,INT,LPSTR,INT);
-BOOL VFWAPI capGetDriverDescriptionW(WORD,LPWSTR,INT,LPWSTR,INT);
-#define     capGetDriverDescription WINELIB_NAME_AW(capGetDriverDescription)
+typedef LRESULT (CALLBACK* CAPYIELDCALLBACK)(_In_ HWND hWnd);
+
+typedef LRESULT
+(CALLBACK* CAPSTATUSCALLBACKW)(
+  _In_ HWND hWnd,
+  _In_ int nID,
+  _In_ LPCWSTR lpsz);
+
+typedef LRESULT
+(CALLBACK* CAPERRORCALLBACKW)(
+  _In_ HWND hWnd,
+  _In_ int nID,
+  LPCWSTR lpsz);
+
+typedef LRESULT
+(CALLBACK* CAPSTATUSCALLBACKA)(
+  _In_ HWND hWnd,
+  _In_ int nID,
+  LPCSTR lpsz);
+
+typedef LRESULT
+(CALLBACK* CAPERRORCALLBACKA)(
+  _In_ HWND hWnd,
+  _In_ int nID,
+  LPCSTR lpsz);
+
+typedef LRESULT
+(CALLBACK* CAPVIDEOCALLBACK)(
+  _In_ HWND hWnd,
+  _In_ LPVIDEOHDR lpVHdr);
+
+typedef LRESULT
+(CALLBACK* CAPWAVECALLBACK)(
+  _In_ HWND hWnd,
+  _In_ LPWAVEHDR lpWHdr);
+
+typedef LRESULT
+(CALLBACK* CAPCONTROLCALLBACK)(
+  _In_ HWND hWnd,
+  _In_ int nState);
+
+HWND
+VFWAPI
+capCreateCaptureWindowA(
+  LPCSTR,
+  _In_ DWORD,
+  _In_ INT,
+  _In_ INT,
+  _In_ INT,
+  _In_ INT,
+  _In_opt_ HWND,
+  _In_ INT);
+
+HWND
+VFWAPI
+capCreateCaptureWindowW(
+  LPCWSTR,
+  _In_ DWORD,
+  _In_ INT,
+  _In_ INT,
+  _In_ INT,
+  _In_ INT,
+  _In_opt_ HWND,
+  _In_ INT);
+
+#define capCreateCaptureWindow WINELIB_NAME_AW(capCreateCaptureWindow)
+
+BOOL
+VFWAPI
+capGetDriverDescriptionA(
+  WORD,
+  _Out_writes_(cbName) LPSTR,
+  _In_ INT cbName,
+  _Out_writes_(cbVer) LPSTR,
+  _In_ INT cbVer);
+
+BOOL
+VFWAPI
+capGetDriverDescriptionW(
+  WORD,
+  _Out_writes_(cbName) LPWSTR,
+  _In_ INT cbName,
+  _Out_writes_(cbVer) LPWSTR,
+  _In_ INT cbVer);
+
+#define capGetDriverDescription WINELIB_NAME_AW(capGetDriverDescription)
 
 #ifdef __cplusplus
 }
index 11744dd..6552854 100644 (file)
@@ -473,6 +473,8 @@ BOOL WINAPI SetConsoleMenuClose(_In_ BOOL);
 BOOL WINAPI SetConsoleCursor(_In_ HANDLE, _In_ HCURSOR);
 /* Undocumented, see http://undoc.airesoft.co.uk/kernel32.dll/ShowConsoleCursor.php */
 INT WINAPI ShowConsoleCursor(_In_ HANDLE, _In_ BOOL);
+/* Undocumented, see http://comments.gmane.org/gmane.comp.lang.harbour.devel/27844 */
+BOOL WINAPI SetConsolePalette(_In_ HANDLE, _In_ HPALETTE, _In_ UINT);
 
 BOOL WINAPI WriteConsoleA(HANDLE,CONST VOID*,DWORD,LPDWORD,LPVOID);
 BOOL WINAPI WriteConsoleW(HANDLE,CONST VOID*,DWORD,LPDWORD,LPVOID);
index 4b1a9c3..4ef1220 100644 (file)
@@ -824,7 +824,6 @@ int WINAPI GetTimeFormatA(LCID,DWORD,const SYSTEMTIME*,LPCSTR,LPSTR,int);
 int WINAPI GetTimeFormatW(LCID,DWORD,const SYSTEMTIME*,LPCWSTR,LPWSTR,int);
 LANGID WINAPI GetUserDefaultLangID(void);
 LCID WINAPI GetUserDefaultLCID(void);
-LANGID WINAPI GetUserDefaultUILanguage(void);
 GEOID WINAPI GetUserGeoID(_In_ GEOCLASS);
 BOOL WINAPI IsDBCSLeadByte(_In_ BYTE);
 BOOL WINAPI IsDBCSLeadByteEx(_In_ UINT, _In_ BYTE);
index 06cb931..0867163 100644 (file)
@@ -65,7 +65,7 @@ typedef enum _CONSRV_API_NUMBER
     ConsolepSetCursor,
     ConsolepShowCursor,
     ConsolepMenuControl,
-    // ConsolepSetPalette,
+    ConsolepSetPalette,
     ConsolepSetDisplayMode,
     // ConsolepRegisterVDM,
     ConsolepGetHardwareState,
@@ -303,6 +303,13 @@ typedef struct
     SMALL_RECT Region;
 } CONSOLE_INVALIDATEDIBITS, *PCONSOLE_INVALIDATEDIBITS;
 
+typedef struct
+{
+    HANDLE   OutputHandle;
+    HPALETTE PaletteHandle;
+    UINT     Usage;
+} CONSOLE_SETPALETTE, *PCONSOLE_SETPALETTE;
+
 typedef struct
 {
     DWORD Length;
@@ -664,6 +671,7 @@ typedef struct _CONSOLE_API_MESSAGE
 
         /* Console window */
         CONSOLE_INVALIDATEDIBITS InvalidateDIBitsRequest;
+        CONSOLE_SETPALETTE SetPaletteRequest;
         CONSOLE_GETSETCONSOLETITLE TitleRequest;
         CONSOLE_GETLARGESTWINDOWSIZE GetLargestWindowSizeRequest;
         CONSOLE_MENUCONTROL MenuControlRequest;
index 14a36f5..ac26f16 100644 (file)
@@ -24,6 +24,8 @@ BOOLEAN IpWorkItemQueued = FALSE;
 
 IP_PROTOCOL_HANDLER ProtocolTable[IP_PROTOCOL_TABLE_SIZE];
 
+ULONG IpTimerExpirations;
+
 VOID
 TCPRegisterInterface(PIP_INTERFACE IF);
 
@@ -119,9 +121,16 @@ VOID NTAPI IPTimeoutDpcFn(PKDPC Dpc,
  *     SystemArgument1 = Unused
  *     SystemArgument2 = Unused
  * NOTES:
- *     This routine is dispatched once in a while to do maintainance jobs
+ *     This routine is dispatched once in a while to do maintenance jobs
  */
 {
+    IpTimerExpirations++;
+    
+    if ((IpTimerExpirations % 10) == 0)
+    {
+        LogActiveObjects();
+    }
+
     /* Check if datagram fragments have taken too long to assemble */
     IPDatagramReassemblyTimeout();
 
index d4ca9f3..a7c1d35 100644 (file)
@@ -444,8 +444,6 @@ PNEIGHBOR_CACHE_ENTRY NBLocateNeighbor(
 
   TcpipAcquireSpinLock(&NeighborCache[HashValue].Lock, &OldIrql);
 
-  NCE = NeighborCache[HashValue].Cache;
-
   /* If there's no adapter specified, we'll look for a match on
    * each one. */
   if (Interface == NULL)
@@ -460,6 +458,7 @@ PNEIGHBOR_CACHE_ENTRY NBLocateNeighbor(
 
   do
   {
+      NCE = NeighborCache[HashValue].Cache;
       while (NCE != NULL)
       {
          if (NCE->Interface == Interface &&
@@ -477,6 +476,21 @@ PNEIGHBOR_CACHE_ENTRY NBLocateNeighbor(
   while ((FirstInterface != NULL) &&
          ((Interface = GetDefaultInterface()) != FirstInterface));
 
+  if ((NCE == NULL) && (FirstInterface != NULL))
+  {
+      /* This time we'll even match loopback NCEs */
+      NCE = NeighborCache[HashValue].Cache;
+      while (NCE != NULL)
+      {
+         if (AddrIsEqual(Address, &NCE->Address))
+         {
+             break;
+         }
+
+         NCE = NCE->Next;
+      }
+  }
+
   TcpipReleaseSpinLock(&NeighborCache[HashValue].Lock, OldIrql);
 
   TI_DbgPrint(MAX_TRACE, ("Leaving.\n"));
index c5b8b95..23c0c56 100644 (file)
@@ -264,12 +264,10 @@ TCPFinEventHandler(void *arg, const err_t err)
    const NTSTATUS Status = TCPTranslateError(err);
    KIRQL OldIrql;
 
+   ASSERT(Connection->SocketContext == NULL);
    ASSERT(Connection->AddressFile);
    ASSERT(err != ERR_OK);
 
-   /* First off all, remove the PCB pointer */
-   Connection->SocketContext = NULL;
-
    /* Complete all outstanding requests now */
    FlushAllQueues(Connection, Status);
 
index 57c8876..44a865a 100755 (executable)
@@ -35,6 +35,21 @@ extern NPAGED_LOOKASIDE_LIST QueueEntryLookasideList;
 /* Required for ERR_T to NTSTATUS translation in receive error handling */
 NTSTATUS TCPTranslateError(const err_t err);
 
+void
+LibTCPDumpPcb(PVOID SocketContext)
+{
+    struct tcp_pcb *pcb = (struct tcp_pcb*)SocketContext;
+    unsigned int addr = ntohl(pcb->remote_ip.addr);
+
+    DbgPrint("\tState: %s\n", tcp_state_str[pcb->state]);
+    DbgPrint("\tRemote: (%d.%d.%d.%d, %d)\n",
+    (addr >> 24) & 0xFF,
+    (addr >> 16) & 0xFF,
+    (addr >> 8) & 0xFF,
+    addr & 0xFF,
+    pcb->remote_port);
+}
+
 static
 void
 LibTCPEmptyQueue(PCONNECTION_ENDPOINT Connection)
@@ -231,17 +246,20 @@ InternalRecvEventHandler(void *arg, PTCP_PCB pcb, struct pbuf *p, const err_t er
         Connection->ReceiveShutdown = TRUE;
         Connection->ReceiveShutdownStatus = STATUS_SUCCESS;
 
-        /* This code path executes for both remotely and locally initiated closures,
-         * and we need to distinguish between them */
-        if (Connection->SocketContext)
+        /* If we already did a send shutdown, we're in TIME_WAIT so we can't use this PCB anymore */
+        if (Connection->SendShutdown)
         {
-            /* Remotely initiated close */
-            TCPRecvEventHandler(arg);
+            Connection->SocketContext = NULL;
+            tcp_arg(pcb, NULL);
         }
-        else
+
+        /* Indicate the graceful close event */
+        TCPRecvEventHandler(arg);
+
+        /* If the PCB is gone, clean up the connection */
+        if (Connection->SendShutdown)
         {
-            /* Locally initated close */
-            TCPFinEventHandler(arg, ERR_CLSD);
+            TCPFinEventHandler(Connection, ERR_CLSD);
         }
     }
 
@@ -285,30 +303,20 @@ void
 InternalErrorEventHandler(void *arg, const err_t err)
 {
     PCONNECTION_ENDPOINT Connection = arg;
-    KIRQL OldIrql;
 
     /* Make sure the socket didn't get closed */
-    if (!arg) return;
-
-    /* Check if data is left to be read */
-    LockObject(Connection, &OldIrql);
-    if (IsListEmpty(&Connection->PacketQueue))
-    {
-        UnlockObject(Connection, OldIrql);
+    if (!arg || Connection->SocketContext == NULL) return;
 
-        /* Deliver the error now */
-        TCPFinEventHandler(arg, err);
-    }
-    else
-    {
-        UnlockObject(Connection, OldIrql);
+    /* The PCB is dead now */
+    Connection->SocketContext = NULL;
 
-        /* Defer the error delivery until all data is gone */
-        Connection->ReceiveShutdown = TRUE;
-        Connection->ReceiveShutdownStatus = TCPTranslateError(err);
+    /* Give them one shot to receive the remaining data */
+    Connection->ReceiveShutdown = TRUE;
+    Connection->ReceiveShutdownStatus = TCPTranslateError(err);
+    TCPRecvEventHandler(Connection);
 
-        TCPRecvEventHandler(arg);
-    }
+    /* Terminate the connection */
+    TCPFinEventHandler(Connection, err);
 }
 
 static
@@ -633,7 +641,12 @@ LibTCPShutdownCallback(void *arg)
         goto done;
     }
 
-    /* These need to be called separately, otherwise we get a tcp_close() */
+    /* LwIP makes the (questionable) assumption that SHUTDOWN_RDWR is equivalent to tcp_close().
+     * This assumption holds even if the shutdown calls are done separately (even through multiple
+     * WinSock shutdown() calls). This assumption means that lwIP has the right to deallocate our
+     * PCB without telling us if we shutdown TX and RX. To avoid these problems, we'll clear the
+     * socket context if we have called shutdown for TX and RX.
+     */
     if (msg->Input.Shutdown.shut_rx) {
         msg->Output.Shutdown.Error = tcp_shutdown(pcb, TRUE, FALSE);
     }
@@ -651,6 +664,15 @@ LibTCPShutdownCallback(void *arg)
 
         if (msg->Input.Shutdown.shut_tx)
             msg->Input.Shutdown.Connection->SendShutdown = TRUE;
+
+        if (msg->Input.Shutdown.Connection->ReceiveShutdown &&
+            msg->Input.Shutdown.Connection->SendShutdown)
+        {
+            /* The PCB is not ours anymore */
+            msg->Input.Shutdown.Connection->SocketContext = NULL;
+            tcp_arg(pcb, NULL);
+            TCPFinEventHandler(msg->Input.Shutdown.Connection, ERR_CLSD);
+        }
     }
 
 done:
@@ -697,37 +719,41 @@ LibTCPCloseCallback(void *arg)
     /* Empty the queue even if we're already "closed" */
     LibTCPEmptyQueue(msg->Input.Close.Connection);
 
-    if (!msg->Input.Close.Connection->SocketContext)
+    /* Check if we've already been closed */
+    if (msg->Input.Close.Connection->Closing)
     {
         msg->Output.Close.Error = ERR_OK;
         goto done;
     }
 
-    /* Clear the PCB pointer */
-    msg->Input.Close.Connection->SocketContext = NULL;
+    /* Enter "closing" mode if we're doing a normal close */
+    if (msg->Input.Close.Callback)
+        msg->Input.Close.Connection->Closing = TRUE;
 
-    switch (pcb->state)
+    /* Check if the PCB was already "closed" but the client doesn't know it yet */
+    if (!msg->Input.Close.Connection->SocketContext)
     {
-        case CLOSED:
-        case LISTEN:
-        case SYN_SENT:
-           msg->Output.Close.Error = tcp_close(pcb);
+        msg->Output.Close.Error = ERR_OK;
+        goto done;
+    }
 
-           if (!msg->Output.Close.Error && msg->Input.Close.Callback)
-               TCPFinEventHandler(msg->Input.Close.Connection, ERR_CLSD);
-           break;
+    /* Clear the PCB pointer and stop callbacks */
+    msg->Input.Close.Connection->SocketContext = NULL;
+    tcp_arg(pcb, NULL);
 
-        default:
-           /* Abort the socket */
-           tcp_abort(pcb);
-           msg->Output.Close.Error = ERR_OK;
-           break;
-    }
+    /* This may generate additional callbacks but we don't care,
+     * because they're too inconsistent to rely on */
+    msg->Output.Close.Error = tcp_close(pcb);
 
     if (msg->Output.Close.Error)
     {
         /* Restore the PCB pointer */
         msg->Input.Close.Connection->SocketContext = pcb;
+        msg->Input.Close.Connection->Closing = FALSE;
+    }
+    else if (msg->Input.Close.Callback)
+    {
+        TCPFinEventHandler(msg->Input.Close.Connection, ERR_CLSD);
     }
 
 done:
index 5be07e4..7693f64 100644 (file)
@@ -19,6 +19,6 @@ list(APPEND SOURCE
 add_executable(ntvdm ${SOURCE})
 set_module_type(ntvdm win32cui UNICODE)
 target_link_libraries(ntvdm softx86 softx87)
-add_importlibs(ntvdm msvcrt user32 kernel32 ntdll)
+add_importlibs(ntvdm msvcrt user32 gdi32 kernel32 ntdll)
 add_dependencies(ntvdm softx86 softx87)
 add_cd_file(TARGET ntvdm DESTINATION reactos/system32 FOR all)
index 058ff64..ee23ef4 100644 (file)
@@ -408,7 +408,12 @@ BOOLEAN BiosInitialize(VOID)
     }
 
     /* Initialize VGA */
-    VgaInitialize(BiosConsoleOutput);
+    if (!VgaInitialize(BiosConsoleOutput))
+    {
+        CloseHandle(BiosConsoleOutput);
+        CloseHandle(BiosConsoleInput);
+        return FALSE;
+    }
 
     /* Update the cursor position */
     BiosSetCursorPosition(BiosSavedBufferInfo.dwCursorPosition.Y,
index cebd09d..3a959b4 100644 (file)
 static CONST DWORD MemoryBase[] = { 0xA0000, 0xA0000, 0xB0000, 0xB8000 };
 static CONST DWORD MemoryLimit[] = { 0xAFFFF, 0xAFFFF, 0xB7FFF, 0xBFFFF };
 
+static CONST COLORREF VgaDefaultPalette[VGA_MAX_COLORS] = 
+{
+    0x000000, 0x0000AA, 0x00AA00, 0x00AAAA, 0xAA0000, 0xAA00AA, 0xAA5500, 0xAAAAAA,
+    0x555555, 0x5555FF, 0x55FF55, 0x55FFFF, 0xFF5555, 0xFF55FF, 0xFFFF55, 0xFFFFFF,
+    0x000000, 0x101010, 0x202020, 0x353535, 0x454545, 0x555555, 0x656565, 0x757575,
+    0x8A8A8A, 0x9A9A9A, 0xAAAAAA, 0xBABABA, 0xCACACA, 0xDFDFDF, 0xEFEFEF, 0xFFFFFF,
+    0x0000FF, 0x4100FF, 0x8200FF, 0xBE00FF, 0xFF00FF, 0xFF00BE, 0xFF0082, 0xFF0041,
+    0xFF0000, 0xFF4100, 0xFF8200, 0xFFBE00, 0xFFFF00, 0xBEFF00, 0x82FF00, 0x41FF00,
+    0x00FF00, 0x00FF41, 0x00FF82, 0x00FFBE, 0x00FFFF, 0x00BEFF, 0x0082FF, 0x0041FF,
+    0x8282FF, 0x9E82FF, 0xBE82FF, 0xDF82FF, 0xFF82FF, 0xFF82DF, 0xFF82BE, 0xFF829E,
+    0xFF8282, 0xFF9E82, 0xFFBE82, 0xFFDF82, 0xFFFF82, 0xDFFF82, 0xBEFF82, 0x9EFF82,
+    0x82FF82, 0x82FF9E, 0x82FFBE, 0x82FFDF, 0x82FFFF, 0x82DFFF, 0x82BEFF, 0x829EFF,
+    0xBABAFF, 0xCABAFF, 0xDFBAFF, 0xEFBAFF, 0xFFBAFF, 0xFFBAEF, 0xFFBADF, 0xFFBACA,
+    0xFFBABA, 0xFFCABA, 0xFFDFBA, 0xFFEFBA, 0xFFFFBA, 0xEFFFBA, 0xDFFFBA, 0xCAFFBA,
+    0xBAFFBA, 0xBAFFCA, 0xBAFFDF, 0xBAFFEF, 0xBAFFFF, 0xBAEFFF, 0xBADFFF, 0xBACAFF,
+    0x000071, 0x1C0071, 0x390071, 0x550071, 0x710071, 0x710055, 0x710039, 0x71001C,
+    0x710000, 0x711C00, 0x713900, 0x715500, 0x717100, 0x557100, 0x397100, 0x1C7100,
+    0x007100, 0x00711C, 0x007139, 0x007155, 0x007171, 0x005571, 0x003971, 0x001C71,
+    0x393971, 0x453971, 0x553971, 0x613971, 0x713971, 0x713961, 0x713955, 0x713945,
+    0x713939, 0x714539, 0x715539, 0x716139, 0x717139, 0x617139, 0x557139, 0x457139,
+    0x397139, 0x397145, 0x397155, 0x397161, 0x397171, 0x396171, 0x395571, 0x394571,
+    0x515171, 0x595171, 0x615171, 0x695171, 0x715171, 0x715169, 0x715161, 0x715159,
+    0x715151, 0x715951, 0x716151, 0x716951, 0x717151, 0x697151, 0x617151, 0x597151,
+    0x517151, 0x517159, 0x517161, 0x517169, 0x517171, 0x516971, 0x516171, 0x515971,
+    0x000041, 0x100041, 0x200041, 0x310041, 0x410041, 0x410031, 0x410020, 0x410010,
+    0x410000, 0x411000, 0x412000, 0x413100, 0x414100, 0x314100, 0x204100, 0x104100,
+    0x004100, 0x004110, 0x004120, 0x004131, 0x004141, 0x003141, 0x002041, 0x001041,
+    0x202041, 0x282041, 0x312041, 0x392041, 0x412041, 0x412039, 0x412031, 0x412028,
+    0x412020, 0x412820, 0x413120, 0x413920, 0x414120, 0x394120, 0x314120, 0x284120,
+    0x204120, 0x204128, 0x204131, 0x204139, 0x204141, 0x203941, 0x203141, 0x202841,
+    0x2D2D41, 0x312D41, 0x352D41, 0x3D2D41, 0x412D41, 0x412D3D, 0x412D35, 0x412D31,
+    0x412D2D, 0x41312D, 0x41352D, 0x413D2D, 0x41412D, 0x3D412D, 0x35412D, 0x31412D,
+    0x2D412D, 0x2D4131, 0x2D4135, 0x2D413D, 0x2D4141, 0x2D3D41, 0x2D3541, 0x2D3141,
+    0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000
+};
+
 static BYTE VgaMemory[VGA_NUM_BANKS * VGA_BANK_SIZE];
 static BYTE VgaLatchRegisters[VGA_NUM_BANKS] = {0, 0, 0, 0};
 static BYTE VgaMiscRegister;
@@ -33,6 +69,7 @@ static BYTE VgaAcRegisters[VGA_AC_MAX_REG];
 static BYTE VgaDacIndex = 0;
 static BOOLEAN VgaDacReadWrite = FALSE;
 static BYTE VgaDacRegisters[VGA_PALETTE_SIZE];
+static HPALETTE PaletteHandle = NULL;
 static BOOLEAN InVerticalRetrace = FALSE;
 static BOOLEAN InHorizontalRetrace = FALSE;
 static HANDLE TextConsoleBuffer = NULL;
@@ -42,6 +79,7 @@ static HANDLE ConsoleMutex = NULL;
 static BOOLEAN NeedsUpdate = FALSE;
 static BOOLEAN ModeChanged = TRUE;
 static BOOLEAN CursorMoved = FALSE;
+static BOOLEAN PaletteChanged = FALSE;
 static BOOLEAN TextMode = TRUE;
 static SMALL_RECT UpdateRectangle = { 0, 0, 0, 0 };
 
@@ -262,11 +300,30 @@ static VOID VgaWriteCrtc(BYTE Data)
 
 static VOID VgaWriteDac(BYTE Data)
 {
+    INT PaletteIndex;
+    PALETTEENTRY Entry;
+
     /* Set the value */
-    VgaDacRegisters[VgaDacIndex++] = Data;
-    VgaDacIndex %= VGA_PALETTE_SIZE;
+    VgaDacRegisters[VgaDacIndex] = Data;
+
+    /* Find the palette index */
+    PaletteIndex = VgaDacIndex / 3;
+
+    /* Fill the entry structure */
+    Entry.peRed = VGA_DAC_TO_COLOR(VgaDacRegisters[PaletteIndex * 3]);
+    Entry.peGreen = VGA_DAC_TO_COLOR(VgaDacRegisters[PaletteIndex * 3 + 1]);
+    Entry.peBlue = VGA_DAC_TO_COLOR(VgaDacRegisters[PaletteIndex * 3 + 2]);
+    Entry.peFlags = 0;
+
+    /* Update the palette entry */
+    SetPaletteEntries(PaletteHandle, PaletteIndex, 1, &Entry);
 
-    // TODO: Change the palette!
+    /* Set the palette changed flag */
+    PaletteChanged = TRUE;
+
+    /* Update the index */
+    VgaDacIndex++;
+    VgaDacIndex %= VGA_PALETTE_SIZE;
 }
 
 static VOID VgaWriteAc(BYTE Data)
@@ -397,6 +454,11 @@ static VOID VgaUpdateMode(VOID)
 
         /* Clear the text mode flag */
         TextMode = FALSE;
+
+        /* Set the palette */
+        SetConsolePalette(GraphicsConsoleBuffer,
+                          PaletteHandle,
+                          SYSPAL_NOSTATIC256);
     }
 
     /* Perform a full update */
@@ -691,6 +753,19 @@ VOID VgaRefreshDisplay(VOID)
         CursorMoved = FALSE;
     }
 
+    if (PaletteChanged)
+    {
+        if (VgaGcRegisters[VGA_GC_MISC_REG] & VGA_GC_MISC_NOALPHA)
+        {
+            /* Set the graphics mode palette */
+            SetConsolePalette(GraphicsConsoleBuffer,
+                              PaletteHandle,
+                              SYSPAL_NOSTATIC256);
+        }
+        
+        PaletteChanged = FALSE;
+    }
+
     /* Update the contents of the framebuffer */
     VgaUpdateFramebuffer();
 
@@ -1026,7 +1101,7 @@ VOID VgaClearMemory(VOID)
     ZeroMemory(VgaMemory, sizeof(VgaMemory));
 }
 
-VOID VgaInitialize(HANDLE TextHandle)
+BOOLEAN VgaInitialize(HANDLE TextHandle)
 {
     INT i, j;
     COORD Resolution;
@@ -1037,6 +1112,7 @@ VOID VgaInitialize(HANDLE TextHandle)
     PCHAR_INFO CharBuffer;
     DWORD Address = 0;
     DWORD CurrentAddr;
+    LPLOGPALETTE Palette;
 
     /* Set the global handle */
     TextConsoleBuffer = TextHandle;
@@ -1083,6 +1159,40 @@ VOID VgaInitialize(HANDLE TextHandle)
         /* Move to the next scanline */
         Address += ScanlineSize;
     }
+
+    /* Allocate storage space for the palette */
+    Palette = (LPLOGPALETTE)HeapAlloc(GetProcessHeap(),
+                                      HEAP_ZERO_MEMORY,
+                                      sizeof(LOGPALETTE)
+                                      + VGA_MAX_COLORS * sizeof(PALETTEENTRY));
+    if (Palette == NULL) return FALSE;
+
+    /* Initialize the palette */
+    Palette->palVersion = 0x0100;
+    Palette->palNumEntries = VGA_MAX_COLORS;
+
+    /* Copy the colors of the default palette to the DAC and console palette */
+    for (i = 0; i < VGA_MAX_COLORS; i++)
+    {
+        /* Set the palette entries */
+        Palette->palPalEntry[i].peRed = GetRValue(VgaDefaultPalette[i]);
+        Palette->palPalEntry[i].peGreen = GetGValue(VgaDefaultPalette[i]);
+        Palette->palPalEntry[i].peBlue = GetBValue(VgaDefaultPalette[i]);
+
+        /* Set the DAC registers */
+        VgaDacRegisters[i * 3] = VGA_COLOR_TO_DAC(GetRValue(VgaDefaultPalette[i]));
+        VgaDacRegisters[i * 3 + 1] = VGA_COLOR_TO_DAC(GetGValue(VgaDefaultPalette[i]));
+        VgaDacRegisters[i * 3 + 2] = VGA_COLOR_TO_DAC(GetBValue(VgaDefaultPalette[i]));
+    }
+
+    /* Create the palette */
+    PaletteHandle = CreatePalette(Palette);
+
+    /* Free the palette */
+    HeapFree(GetProcessHeap(), 0, Palette);
+
+    /* Return success */
+    return TRUE;
 }
 
 /* EOF */
index b06cc75..23b5a3a 100644 (file)
 
 #define VGA_NUM_BANKS 4
 #define VGA_BANK_SIZE 0x10000
-#define VGA_PALETTE_SIZE 768
+#define VGA_MAX_COLORS 256
+#define VGA_PALETTE_SIZE (VGA_MAX_COLORS * 3)
 #define VGA_BITMAP_INFO_SIZE (sizeof(BITMAPINFOHEADER) + 2 * (VGA_PALETTE_SIZE / 3))
+#define VGA_DAC_TO_COLOR(x) (((x) << 2) | ((x) >> 6))
+#define VGA_COLOR_TO_DAC(x) ((x) >> 2)
 
 /* Sequencer reset register bits */
 #define VGA_SEQ_RESET_AR (1 << 0)
@@ -194,7 +197,7 @@ VOID VgaWriteMemory(DWORD Address, LPBYTE Buffer, DWORD Size);
 BYTE VgaReadPort(WORD Port);
 VOID VgaWritePort(WORD Port, BYTE Data);
 VOID VgaClearMemory(VOID);
-VOID VgaInitialize(HANDLE TextHandle);
+BOOLEAN VgaInitialize(HANDLE TextHandle);
 
 #endif // _VGA_H_
 
index a7f340b..80c24ac 100644 (file)
@@ -25,6 +25,7 @@ CSR_API(SrvGetConsoleNumberOfInputEvents);
 
 /* conoutput.c */
 CSR_API(SrvInvalidateBitMapRect);
+CSR_API(SrvSetConsolePalette);
 CSR_API(SrvReadConsoleOutput);
 CSR_API(SrvWriteConsole);
 CSR_API(SrvWriteConsoleOutput);
index 03d5745..e0c4340 100644 (file)
@@ -203,6 +203,16 @@ ConDrvInvalidateBitMapRect(IN PCONSOLE Console,
     return STATUS_SUCCESS;
 }
 
+NTSTATUS NTAPI
+ConDrvSetConsolePalette(IN PCONSOLE Console,
+                        IN PGRAPHICS_SCREEN_BUFFER Buffer,
+                        IN HPALETTE PaletteHandle,
+                        IN UINT Usage)
+{
+    DPRINT1("ConDrvSetConsolePalette is UNIMPLEMENTED but returns STATUS_SUCCESS\n");
+    return STATUS_SUCCESS;
+}
+
 NTSTATUS NTAPI
 ConDrvGetConsoleCursorInfo(IN PCONSOLE Console,
                            IN PTEXTMODE_SCREEN_BUFFER Buffer,
index 223f6ca..af3325a 100644 (file)
@@ -50,6 +50,36 @@ CSR_API(SrvInvalidateBitMapRect)
     return Status;
 }
 
+NTSTATUS NTAPI
+ConDrvSetConsolePalette(IN PCONSOLE Console,
+                        IN PGRAPHICS_SCREEN_BUFFER Buffer,
+                        IN HPALETTE PaletteHandle,
+                        IN UINT Usage);
+CSR_API(SrvSetConsolePalette)
+{
+    NTSTATUS Status;
+    PCONSOLE_SETPALETTE SetPaletteRequest = &((PCONSOLE_API_MESSAGE)ApiMessage)->Data.SetPaletteRequest;
+    // PCONSOLE_SCREEN_BUFFER Buffer;
+    PGRAPHICS_SCREEN_BUFFER Buffer;
+
+    DPRINT("SrvSetConsolePalette\n");
+
+    // NOTE: Tests show that this function is used only for graphics screen buffers
+    // and otherwise it returns false + sets last error to invalid handle.
+    Status = ConSrvGetGraphicsBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
+                                     SetPaletteRequest->OutputHandle,
+                                     &Buffer, GENERIC_WRITE, TRUE);
+    if (!NT_SUCCESS(Status)) return Status;
+
+    Status = ConDrvSetConsolePalette(Buffer->Header.Console,
+                                     Buffer,
+                                     SetPaletteRequest->PaletteHandle,
+                                     SetPaletteRequest->Usage);
+
+    ConSrvReleaseScreenBuffer(Buffer, TRUE);
+    return Status;
+}
+
 NTSTATUS NTAPI
 ConDrvGetConsoleCursorInfo(IN PCONSOLE Console,
                            IN PTEXTMODE_SCREEN_BUFFER Buffer,
index 92c147a..f6e148f 100644 (file)
@@ -220,7 +220,7 @@ CSR_API(SrvSetConsoleCursor)
     PCONSOLE_SCREEN_BUFFER Buff;
 
     // FIXME: Tests show that this function is used only for graphics screen buffers
-    // and otherwise it returns false + set last error to invalid handle.
+    // and otherwise it returns false + sets last error to invalid handle.
     // NOTE: I find that behaviour is ridiculous but ok, let's accept that at the moment...
     Status = ConSrvGetGraphicsBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
                                      SetCursorRequest->OutputHandle,
index 1cc32b6..a1ba235 100644 (file)
@@ -75,7 +75,7 @@ PCSR_API_ROUTINE ConsoleServerApiDispatchTable[ConsolepMaxApiNumber - CONSRV_FIR
     SrvSetConsoleCursor,
     SrvShowConsoleCursor,
     SrvConsoleMenuControl,
-    // SrvSetConsolePalette,
+    SrvSetConsolePalette,
     SrvSetConsoleDisplayMode,
     // SrvRegisterConsoleVDM,
     SrvGetConsoleHardwareState,
@@ -166,7 +166,7 @@ BOOLEAN ConsoleServerApiServerValidTable[ConsolepMaxApiNumber - CONSRV_FIRST_API
     FALSE,   // SrvSetConsoleCursor,
     FALSE,   // SrvShowConsoleCursor,
     FALSE,   // SrvConsoleMenuControl,
-    // FALSE,   // SrvSetConsolePalette,
+    FALSE,   // SrvSetConsolePalette,
     FALSE,   // SrvSetConsoleDisplayMode,
     // FALSE,   // SrvRegisterConsoleVDM,
     FALSE,   // SrvGetConsoleHardwareState,
@@ -257,7 +257,7 @@ PCHAR ConsoleServerApiNameTable[ConsolepMaxApiNumber - CONSRV_FIRST_API_NUMBER]
     "SetConsoleCursor",
     "ShowConsoleCursor",
     "ConsoleMenuControl",
-    // "SetConsolePalette",
+    "SetConsolePalette",
     "SetConsoleDisplayMode",
     // "RegisterConsoleVDM",
     "GetConsoleHardwareState",