vchtchetkine | f855c4e | 2009-08-05 16:57:18 -0700 | [diff] [blame^] | 1 | /*
|
| 2 | * Copyright (C) 2009 The Android Open Source Project
|
| 3 | *
|
| 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 | * you may not use this file except in compliance with the License.
|
| 6 | * You may obtain a copy of the License at
|
| 7 | *
|
| 8 | * http://www.apache.org/licenses/LICENSE-2.0
|
| 9 | *
|
| 10 | * Unless required by applicable law or agreed to in writing, software
|
| 11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 | * See the License for the specific language governing permissions and
|
| 14 | * limitations under the License.
|
| 15 | */
|
| 16 |
|
| 17 | // AdbWinUsbApi.cpp : Implementation of DLL Exports.
|
| 18 |
|
| 19 | #include "stdafx.h"
|
| 20 | #include "adb_winusb_interface.h"
|
| 21 |
|
| 22 | class CAdbWinApiModule : public CAtlDllModuleT< CAdbWinApiModule > {
|
| 23 | public:
|
| 24 | };
|
| 25 |
|
| 26 | CAdbWinApiModule _AtlModule;
|
| 27 |
|
| 28 | // DLL Entry Point
|
| 29 | extern "C" BOOL WINAPI DllMain(HINSTANCE instance,
|
| 30 | DWORD reason,
|
| 31 | LPVOID reserved) {
|
| 32 | return _AtlModule.DllMain(reason, reserved);
|
| 33 | }
|
| 34 |
|
| 35 | /** \brief Instantiates interface instance that uses WinUsb API to communicate
|
| 36 | with USB driver.
|
| 37 |
|
| 38 | This is the only exported routine from this DLL. This routine instantiates an
|
| 39 | object of AdbWinUsbInterfaceObject on request from AdbWinApi.dll when it is
|
| 40 | detected that underlying USB driver is WinUsb.sys.
|
| 41 | @param[in] interface_name Name of the interface.
|
| 42 | @return AdbInterfaceObject - casted instance of AdbWinUsbInterfaceObject
|
| 43 | object on success, or NULL on failure with GetLastError providing
|
| 44 | information on an error that occurred.
|
| 45 | */
|
| 46 | extern "C" __declspec(dllexport)
|
| 47 | AdbInterfaceObject* __cdecl InstantiateWinUsbInterface(
|
| 48 | const wchar_t* interface_name) {
|
| 49 | // Validate parameter.
|
| 50 | if (NULL == interface_name) {
|
| 51 | return NULL;
|
| 52 | }
|
| 53 |
|
| 54 | // Instantiate requested object.
|
| 55 | try {
|
| 56 | return new AdbWinUsbInterfaceObject(interface_name);
|
| 57 | } catch (...) {
|
| 58 | // We expect only OOM exceptions here.
|
| 59 | SetLastError(ERROR_OUTOFMEMORY);
|
| 60 | return NULL;
|
| 61 | }
|
| 62 | }
|