summaryrefslogtreecommitdiff
path: root/src/VBox/Additions/WINNT/VBoxMMR/dllmain.cpp
blob: 0898ef03696d00b1d04eef77dd7535dcf1a58101 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* $Id: dllmain.cpp $ */
/** @file
 * VBoxMMR - Multimedia Redirection
 */

/*
 * Copyright (C) 2012 Oracle Corporation
 *
 * This file is part of VirtualBox Open Source Edition (OSE), as
 * available from http://www.virtualbox.org. This file is free software;
 * you can redistribute it and/or modify it under the terms of the GNU
 * General Public License (GPL) as published by the Free Software
 * Foundation, in version 2 as it comes in the "COPYING" file of the
 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 */

#include "stdafx.h"
#include "tsmfhook.h"
#include "logging.h"

#include <Winternl.h>
#include <iprt/initterm.h>
#include <VBox/VBoxGuestLib.h>

bool isWMP = false;

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:

        DisableThreadLibraryCalls(hModule);

        {
            CHAR buffer[MAX_PATH];
            GetModuleFileNameA(NULL, buffer, sizeof(buffer));
            const PCHAR pc = strrchr(buffer, '\\');
            isWMP = (0 == strcmp(pc + 1, "wmplayer.exe"));

            if (isWMP)
            {
                RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
                VbglR3Init();
                VBoxMMRHookLog("VBoxMMR: Hooking wmplayer process\n");
            }
        }

    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
        break;
    case DLL_PROCESS_DETACH:
        Shutdown();
        if (isWMP)
        {
            VBoxMMRHookLog("VBoxMMR: Unhooking wmplayer process\n");
            VbglR3Term();
        }
        break;
    }
    return TRUE;
}