Beispiel #1
0
USEFORM("forms\Glyphs.cpp", GlyphsModule); /* TDataModule: File Type */
//---------------------------------------------------------------------------
#include <CoreMain.h>
#include <WinInterface.h>
#include <ProgParams.h>
#include <VCLCommon.h>
#include <Setup.h>
//---------------------------------------------------------------------------
WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
{
  int Result = 0;
  try
  {
    WinInitialize();
    Application->Initialize();
    Application->MainFormOnTaskBar = true;
    Application->ModalPopupMode = pmAuto;
    SetEnvironmentVariable(L"WINSCP_PATH",
      ExcludeTrailingBackslash(ExtractFilePath(Application->ExeName)).c_str());
    CoreInitialize();
    InitializeWinHelp();
    InitializeSystemSettings();
    // now everything is setup and mainly the configured locale is already loaded,
    // detect scaling type and possibly forbid further runtime changes to locale
    GUIConfiguration->DetectScalingType();

    try
    {
      try
      {
        ConfigureInterface();
        SetupInitialize();

        Application->Title = AppName;
        Result = Execute();
      }
      catch (Exception & E)
      {
        // Capture most errors before Usage class is released,
        // so that we can count them
        Configuration->Usage->Inc(L"GlobalFailures");
        ShowExtendedException(&E);
      }
    }
    __finally
    {
      FinalizeSystemSettings();
      FinalizeWinHelp();
      CoreFinalize();
      WinFinalize();
    }
  }
  catch (Exception &E)
  {
    ShowExtendedException(&E);
  }
  return Result;
}
HRESULT CLoopbackDevice::ConfigureDevice() {
  HRESULT hr = S_OK;
  ISoftUSBConfiguration* piConfig = NULL;
  ISoftUSBInterface* piInterface = NULL;
  ISoftUSBConfigList* piConfigList = NULL;
  ISoftUSBInterfaceList* piInterfaceList = NULL;
  ISoftUSBEndpointList* piEndpointList= NULL; 
  VARIANT varIndex;
  VariantInit(&varIndex);

  // All members of the collection will be added at the default locations
  // so set up the index appropriately
  varIndex.vt = VT_ERROR;
  varIndex.scode = DISP_E_PARAMNOTFOUND;

  // Create the IN Endpoint
  hr = CoCreateInstance(CLSID_SoftUSBEndpoint, 
                        NULL,
                        CLSCTX_INPROC_SERVER,
                        __uuidof(ISoftUSBEndpoint),     
                        reinterpret_cast<void**>(&m_piINEndpoint));
  IfFailHrGo(hr);

  // Setup the IN Endpoint
  IfFailHrGo(ConfigureINEndpoint());

  // Create the OUT Endpoint
  hr = CoCreateInstance(CLSID_SoftUSBEndpoint, 
                        NULL,
                        CLSCTX_INPROC_SERVER,
                        __uuidof(ISoftUSBEndpoint),     
                        reinterpret_cast<void**>(&m_piOUTEndpoint));
  IfFailHrGo(hr);

  // Setup the OUT Endpoint
  IfFailHrGo(ConfigureOUTEndpoint());

  // Create the device interface
  hr = CoCreateInstance(CLSID_SoftUSBInterface, 
                        NULL,
                        CLSCTX_INPROC_SERVER,
                        __uuidof(ISoftUSBInterface),     
                        reinterpret_cast<void**>(&piInterface));
  IfFailHrGo(hr);

  // Setup the device interface
  IfFailHrGo(ConfigureInterface(piInterface));

  // Add the Endpoints to the endpoint list
  IfFailHrGo(piInterface->get_Endpoints(&piEndpointList));
  IfFailHrGo(piEndpointList->Add(reinterpret_cast<SoftUSBEndpoint*>(m_piINEndpoint), varIndex));
  IfFailHrGo(piEndpointList->Add(reinterpret_cast<SoftUSBEndpoint*>(m_piOUTEndpoint), varIndex));

  // Create the configuration
  hr = CoCreateInstance(CLSID_SoftUSBConfiguration, 
                        NULL,
                        CLSCTX_INPROC_SERVER,
                        __uuidof(ISoftUSBConfiguration),     
                        reinterpret_cast<void**>(&piConfig));
  IfFailHrGo(hr);

  // Set the configuration data up
  IfFailHrGo(ConfigureConfig(piConfig));

  // Add the interface to the interface collection
  IfFailHrGo(piConfig->get_Interfaces(&piInterfaceList));
  IfFailHrGo(piInterfaceList->Add(reinterpret_cast<SoftUSBInterface*>(piInterface), varIndex));

  // Add the configuration to the configuration collection
  IfFailHrGo(m_piSoftUSBDevice->get_Configurations(&piConfigList));
  IfFailHrGo(piConfigList->Add(reinterpret_cast<SoftUSBConfiguration*>(piConfig), varIndex));

Exit:
  RELEASE(piConfig);
  RELEASE(piInterface);
  RELEASE(piConfigList);
  RELEASE(piInterfaceList);
  RELEASE(piEndpointList);
  return hr;
}