1

I am trying to connect my Surplex VR tracking shoes to my desktop via Wifi but unfortunately Microsoft in their infinite wisdom have depreciated the functionality to setup a simple Wifi hotspot.

The have provided some example C++ code that allows the creation of a "legacy" hotspot but it has one major flaw that makes it impractical to use - it generates a random password every time it is ran.

I am a Python novice that has never touched C++ before but I figured hard-coding something that is currently randomly generated would be straightforward but it seems like C++ has multiple different kinds of strings and methods are picky about what they are given?

This is the current block of code that handles the SSID and passcode:

    // Either specify a passphrase, or read the randomly generated one
    ComPtr<IPasswordCredential> passwordCredential;

    hr = _legacySettings->get_Passphrase(passwordCredential.GetAddressOf());
    if (FAILED(hr))
    {
        throw WlanHostedNetworkException("Get Passphrase for WiFiDirectLegacySettings failed", hr);
    }

    if (_passphraseProvided)
    {
        hr = hstrPassphrase.Set(_passphrase.c_str());
        if (FAILED(hr))
        {
            throw WlanHostedNetworkException("Failed to create HSTRING representation for Passphrase", hr);
        }

        hr = passwordCredential->put_Password(hstrPassphrase.Get());
        if (FAILED(hr))
        {
            throw WlanHostedNetworkException("Set Passphrase for WiFiDirectLegacySettings failed", hr);
        }
    }
    else
    {
        hr = passwordCredential->get_Password(hstrPassphrase.GetAddressOf());
        if (FAILED(hr))
        {
            throw WlanHostedNetworkException("Get Passphrase for WiFiDirectLegacySettings failed", hr);
        }

        _passphrase = hstrPassphrase.GetRawBuffer(nullptr);
    }

And this is what I thought I would need to replace it with to make it functional

    HString hstrSSID = HString::Make(L"surplex-io");
    HString hstrPassphrase = HString::Make(L"abcd1234");
    _ssid = hstrSSID.GetRawBuffer(nullptr);
    _passphrase = hstrPassphrase.GetRawBuffer(nullptr);

It was suggested I could use the Make method to turn a regular old string into the HString required by the rest of the code. However I am repeatedly told

'Make': is not a member of 'Microsoft::WRL::Wrappers::HString'

Some investigation suggested the Make method of HString could be found in the icrosoft.WRL.Wrappers.h header file which is included in the Windows 10 SDK and I'd need to include that. But the Windows SDK does not include a file of this name so I'm at a bit of a loss.

The original unmodified demo code can be found here: https://github.com/zig13/WiFiDirectLegacySurplex I hope to hardcode the SSID and passcode to the defaults used by Surplex* shoes and make it available on Github for others in the same position. *Although I will probably set a different password for my own use

zig13
  • 13
  • 1
  • 4
  • It says one can configure the password via the a command line argument. – Motomotes May 13 '23 at 07:48
  • @Motomotes Yes-ish. If the .exe is run you get a terminal interface and you can set the password and ssid using commands. But you'd have to do that every time you wanted to use it. The .exe doesn't seem to take arguments so it's an entirely manual process every time. – zig13 May 13 '23 at 08:07
  • The [`HString`](https://learn.microsoft.com/en-us/cpp/cppcx/wrl/hstring-class) class in the WRL doesn't have a `Make` member, so it's not clear where you got the idea from. If you need to initialize a WRL `HString` then that is a two-step process: Instantiate an empty (default-constructed) object, followed by a call to [`Set`](https://learn.microsoft.com/en-us/cpp/cppcx/wrl/hstring-class#set). Personally, I'd use [C++/WinRT](https://aka.ms/cppwinrt) instead, and have all the `wchar_t*` -> `HSTRING` conversions performed automatically, e.g. `passwordCredential->Password(L"abcd1234")`. – IInspectable May 13 '23 at 08:21
  • https://github.com/btframework/WCL-Python-Demos https://www.btframework.com/hostednetwork.htm – Mike Petrichenko May 13 '23 at 09:53

1 Answers1

1

Just remove the conditional checking for passphrase being provided and use that branch to always set password, .c_str() can be replaced by a string literal, L"password".

ComPtr<IPasswordCredential> passwordCredential;

hr = _legacySettings->get_Passphrase(passwordCredential.GetAddressOf());
if (FAILED(hr))
{
    throw WlanHostedNetworkException("Get Passphrase for WiFiDirectLegacySettings failed", hr);
}

hr = hstrPassphrase.Set(L"Hardcoded Password");
if (FAILED(hr))
{
throw WlanHostedNetworkException("Failed to create HSTRING representation for Passphrase", hr);
}

hr = passwordCredential->put_Password(hstrPassphrase.Get());
if (FAILED(hr))
{
throw WlanHostedNetworkException("Set Passphrase for WiFiDirectLegacySettings failed", hr);
}
Motomotes
  • 4,111
  • 1
  • 25
  • 24
  • This very much does the trick. Thank you very much! Seems I was overcomplicating things. I ran into no end of problems getting it to compile but eventually got it to work and I was able to modify the console file to so it displays the correct SSID and passcode. Available here: https://github.com/zig13/WifiDirectLegacySurplex/tree/main – zig13 May 13 '23 at 14:06