How to activate IWiFiDirectDevice in Win32 Console APP using WRL? - windows-runtime

I want to use WinRT API for WiFi Direct from Windows 10 SDK in Win32 Console Application. I know about C++/CX (and even made some progress going that way), but still want to make it work without this extension.
My problem is that I can't activate IWifiDirectDevice interface (from ABI::Windows::Devices::WiFiDirect) to access IWifiDirectDeviceStatics that provides an GetDeviceSelector method.
HStringReference strDevice(RuntimeClass_Windows_Devices_WiFiDirect_WiFiDirectDevice);
ComPtr<IInspectable> insp;
hr = RoActivateInstance(strDevice.Get(), insp.GetAddressOf());
This code ends up with E_NOTIMPL as a result. In Microsoft's example they used factories for activation, but ABI::Windows::Devices::WiFiDirect namespace has no factories.
Worth mentioning that IWifiDirectAdvertisementPublisher works just fine when activated the way I wrote before.
So how to activate IWifiDirectDevice from WRL?

Windows.Devices.WiFiDirect.WiFiDirectDevice is not an activatable class. You can see that by looking at windows.devices.wifidirect.idl.
You will need to use the static methods, e.g.:
HStringReference strDevice(RuntimeClass_Windows_Devices_WiFiDirect_WiFiDirectDevice);
ComPtr<IWiFiDirectDeviceStatics> wiFiDirectDeviceStatics;
hr = Windows::Foundation::GetActivationFactory(
strDevice.Get(),
&wiFiDirectDeviceStatics);
ComPtr<IWiFiDirectDevice> wiFiDirectDevice;
ComPtr<IAsyncOperation<WiFiDirectDevice*>> asyncOperation;
hr = wiFiDirectDeviceStatics->FromIdAsync(deviceId.Get(), &asyncOperation);
Consider taking a look at the Wi-Fi Direct sample.

Related

ServiceLocationProvider is null when launched as a Share Target

I'm using MVVM Light and everything is fine except when launching my Windows Phone 8.1 WinRT app as a Share Target.
When I try to assign MainViewModel viewModel = ServiceLocator.Current.GetInstance<MainViewModel>(); I get an exception for ServiceLocator.Current.
Exception Message: ServiceLocationProvider must be set.
Do I need to do something extra in App.xaml.cs OnShareTargetActivated event to insure the Locator is running?
UPDATE:
A ShareTarget page needs to be thought of as a small extension of your app. It seems that not all of the app's resources are loaded (including app-wide resources in App.xaml). So I just created a new instance of MainViewModel in the share page's constructor, loaded only the things I need for the share to complete, save the information and call ShareOperation.ReportCompleted. This returns the user back to the app that is sharing.
I still haven't found a good solution for getting other resources in my ViewModel, but this works for now.
This indicates that the following line has not been executed:
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
This line will instruct the ServiceLocator class to use the SimpleIoc.Default instance as its ServiceLocator.Current. When you run your app as a Share target, the initialization is slightly different and probably the ViewModelLocator doesn't get initialized. You need to find a good location to perform the initialization before you use the ServiceLocator.
Cheers
Laurent

Can an embedded cocos2d-js app call back out to c++?

I'm researching the possibility of using cocos2d-js by embedding it as a view inside an existing iOS app. In order to make this work, I'm going to need 2-way communication between cocos2d and the surrounding application.
After some initial investigation, I have determined that it is possible to call in to cocos using ScriptingCore:
ScriptingCore* sc = ScriptingCore::getInstance();
jsval outVal;
sc->evalString("function()", &outVal);
My question, then, is around doing the reverse. It is possible to (e.g. in response to user input) call back out of cocos2d-js to C++? Ideally, there would be a way to register a callback with ScriptingCore which could be invoked from JavaScript.
I believe it can be done, but I have not tried myself, nor can I find a good and concise example.
All I can do is point you at SuperSuraccoon's Bluetooth example and it's git page, which apparently does both ways communication between C++ and JS code.

NaCLl Change Browser Interface

Google's NaCL OpenGL demo uses the "Pure" OpenGLES function calls. However, I'd like to play around with the Pepper OpenGL interface.
The problem I'm having is that the Google demo initializes the PPB Graphic Interface from the browser calling
ppb_g3d_interface = (PPB_Graphics3D*)get_browser(PPB_GRAPHICS_3D_INTERFACE);
In my case, this seems to be returning an instance of PPB_Graphics3D_1_0 and not an OpenGLES interface. Is there anyway to set Chrome use the OpenGLES interface at launch or from within the NaCL code?
The interface you're looking for is PPB_OpenGLES2. It can be found in $NACL_SDK_ROOT/include/ppapi/c/ppb_opengles2.h.
You can use it like this:
ppb_opengles_interface = (PPB_OpenGLES2*)get_browser(PPB_OPENGLES2_INTERFACE);
See the auto-generated documentation for it here:
https://developers.google.com/native-client/pepperc/struct_p_p_b___open_g_l_e_s2
The source for the "extension library" described in your link is also available in the SDK. You can look at the source for it in $NACL_SDK_ROOT/src/ppapi_gles2.

getWindowHandle function doesn't exist for driver in Selenium

I need to implement switch from one window to another in IE. However, element driver doesn't support getWindowHandle function.
I assume it might be just configuration problem or settings, though I don't know how to fix it.
Please, any suggestions.
I'm working with c# - Visual Studio
You haven't said which language bindings you're using, but based on a comment you posted, it looks like you're using C#. The method names are slightly different for each language binding. From this answer:
The object, method, and property names in the .NET language bindings
do not exactly correspond to those in the Java bindings. One of the
principles of the project is that each language binding should "feel
natural" to those comfortable coding in that language.
So you have to do a little translation if you're trying to copy-paste Java code. In this case, you want the combination of the WindowHandles property (to look for the new window handle) and the CurrentWindowHandle property of the driver. You can find full API documentation for the .NET bindings at the project's Google code site.
I am going to make wild guess:
Try to initialize your driver like this:
WebDriver driver = new FirefoxDriver(); //assume you use firefox
The interface WebDriver supports that method. Do not forget to store the handle somewhere ;)
String myWindow = driver.getWindowHandle();
BTW that method should return you actual window If you need all windows you probably should use getWindowHandles() method
If this does not work, please provide more info:
what error exactly are you getting?
How do you initialize WebDriver?
What version of selenium are you using?|
What type of driver are you using?

Protobuf-net on Windows Phone 8

I try use Google protobuf in my WP8 application. I use protobuf-net for my purpoces. When I generate my proto.cs file from qwerty.proto I see next string (below)
...
[global::System.Serializable, global::ProtoBuf.ProtoContract(Name=#"Query") ]
...
But WP8 SDK has not Serializable in System namespace.
May be I made a mistake when I generated proto.cs via protogen.exe? May be it has any additional parameters?
If you use protogen -p:help it will show you the options available not just for the tool, but: for the template you are using (csharp by default). The one of particular interest here is lightFramework. So add -p:lightFramework and you should be set.
Also: for the best performance on phone 8, you may also want to look at precompile, which allows it to use static IL rather than reflection. This is discussed more here.
Note that with protobuf-net it is not required that you start from a .proto file, but that usage is supported; it also works fine "code-first".