-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWiFiDirectLegacyAPPlus.cpp
More file actions
73 lines (64 loc) · 2.51 KB
/
WiFiDirectLegacyAPPlus.cpp
File metadata and controls
73 lines (64 loc) · 2.51 KB
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
67
68
69
70
71
72
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
#include "stdafx.h"
#include "SimpleConsole.h"
#include "WlanHostedNetworkWinRT.h"
using namespace ABI::Windows::Foundation;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
std::wstring s2ws(const std::string& str)
{
int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
std::wstring wstrTo(size_needed, 0);
MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstrTo[0], size_needed);
return wstrTo;
}
int _tmain(int argc, _TCHAR* argv[])
{
// Initialize the Windows Runtime.
RoInitializeWrapper initialize(RO_INIT_MULTITHREADED);
if (FAILED(initialize))
{
std::cout << "Failed to initialize Windows Runtime" << std::endl;
return static_cast<HRESULT>(initialize);
}
SimpleConsole console;
if (argc == 1) {
// if there is no cmd line argument other than app's path+name, we start the AP with hard coded defaults
std::string buf = "ssid testAP";
console.ExecuteCommand(s2ws(buf));
buf = "pass 12345678";
console.ExecuteCommand(s2ws(buf));
buf = "autoaccept 1";
console.ExecuteCommand(s2ws(buf));
buf = "start";
console.ExecuteCommand(s2ws(buf));
}
else {
// if there are two cmd line arguments other than the app's path+name, they are interpreted as ssid and pass
if (argc == 3) {
TCHAR buf[100];
_stprintf_s(buf, sizeof(buf) / sizeof(TCHAR), _T("ssid %s"), argv[1]);
console.ExecuteCommand(buf);
_stprintf_s(buf, sizeof(buf) / sizeof(TCHAR), _T("pass %s"), argv[2]);
console.ExecuteCommand(buf);
_stprintf_s(buf, sizeof(buf) / sizeof(TCHAR), _T("autoaccept 1"));
console.ExecuteCommand(buf);
_stprintf_s(buf, sizeof(buf) / sizeof(TCHAR), _T("start"));
console.ExecuteCommand(buf);
}
else {
// if there is one cmd line argument or more than 2, let's switch to interactive mode, just like the original app behaviour
}
}
console.RunConsole();
return 0;
}