WinRT/C++ Code kompilieren?
Hallo liebe Community,
ich habe auf Stackoverflow diesen Code hier gefunden, und habe keine Ahnung wie ich den richtig kompilieren soll
#include <winrt/Windows.Networking.Connectivity.h>
#include <winrt/Windows.Networking.NetworkOperators.h>
#include <winrt/Windows.Devices.WiFiDirect.h>
#include <winrt/Windows.Security.Credentials.h>
namespace winrt { // /ZW embed in :<winrt> when `Windows` is ambiguously defined
static void af_winrt_wifi_hotspot_test() {
// start ms-settings:network-mobilehotspot
init_apartment(); // apartment_type::multi_threaded
if (false /* play as you wish to test this all in simple c++ console app, I used clang */) {
auto publisher = Windows::Devices::WiFiDirect::WiFiDirectAdvertisementPublisher();
auto advertisement = publisher.Advertisement();
advertisement.ListenStateDiscoverability(Windows::Devices::WiFiDirect::WiFiDirectAdvertisementListenStateDiscoverability::Intensive);
advertisement.IsAutonomousGroupOwnerEnabled(true);
auto legacySettings = advertisement.LegacySettings();
legacySettings.IsEnabled(true);
legacySettings.Ssid(L"your-hotspot-name");
auto credential = Windows::Security::Credentials::PasswordCredential(); credential.Password(L"the-password!");
legacySettings.Passphrase(credential);
publisher.Start();
}
else {
auto connectionProfile{ Windows::Networking::Connectivity::NetworkInformation::GetInternetConnectionProfile() };
auto tetheringManager = Windows::Networking::NetworkOperators::NetworkOperatorTetheringManager::CreateFromConnectionProfile(connectionProfile);
auto credential = Windows::Security::Credentials::PasswordCredential(); credential.Password(L"the-password!");
auto conf = Windows::Networking::NetworkOperators::NetworkOperatorTetheringAccessPointConfiguration();
conf.Ssid(L"I-Own-You"); conf.Passphrase(credential.Password());
auto oldConf = tetheringManager.GetCurrentAccessPointConfiguration();
auto oldSsid = oldConf.Ssid(); auto oldPwd = oldConf.Passphrase();
tetheringManager.ConfigureAccessPointAsync(conf); // Sets new ssid/pwd here
switch (tetheringManager.TetheringOperationalState()) {
case Windows::Networking::NetworkOperators::TetheringOperationalState::Off: {
auto ioAsync = tetheringManager.StartTetheringAsync();
auto fResult = ioAsync.get();
}
break;
case Windows::Networking::NetworkOperators::TetheringOperationalState::On: {
// auto ioAsync = tetheringManager.StopTetheringAsync();
// auto fResult = ioAsync.get();
}
break;
case Windows::Networking::NetworkOperators::TetheringOperationalState::InTransition:
default:
break;
}
}
clear_factory_cache();
uninit_apartment();
}
}
1 Antwort
Vom Fragesteller als hilfreich ausgezeichnet
Das ist eine Implementation einer statischen Funktion. Ich vermute, dass das noch ein paar der Funktionen fehlen, die in der Funktion aufgerufen werden.
Du wirst da wenig Glück haben, weil da irgendwo die main()-Funktion fehlt, die die Funktion sinnvoll aufruft.
Woher ich das weiß:Hobby – Hobby seit meiner Jugend
ShimaG
20.05.2021, 21:04
@FrageToGo
Das ist ein Code-Fragment für einen Treiber. Was willst du denn machen?
ShimaG
20.05.2021, 21:16
@FrageToGo
Ich glaube nicht, dass du das ohne wirklich gute Programmierkenntnisse hinbekommst. Selbst mit ist das IMHO nicht so einfach.
hmm ok, ist da wirklich keine Chance? Hab den Code hier her: https://stackoverflow.com/a/50712007
Brauche ihn dringendst, da ich keinen dieser Art gefunden habe...
Oder einen ähnlichen