Windows Runtime Component C++ Windows Phone 8 - windows-runtime

I am trying to use Windows Runtime ComponenT, i want to run C++ in Windows Phone 8 C#.
I can return Integers, double, float, booleans, but no char string or use void functions. I am receiving this when building the solution:
Error 3 error C3992: 'getChar': signature of public member contains invalid type 'char'
I can create void functions and it compiles but i can not use it in my C# code.
Also i would like to create objects in C++ and use it in the Windows Phone 8.
i don't know if my question is clear but i hope someone understand what i want to do and thanks in advance for the help.

I'm not clear on exactly what you're trying to do but there are only certain types that are supported in C++/CX
See here:
http://msdn.microsoft.com/en-us/library/windows/apps/hh755822.aspx
and
http://msdn.microsoft.com/en-us/library/windows/apps/hh700121.aspx

Related

How to instantiate H264 Encoder on WinRT Store App

I want to be able to encode video frames using Media Foundation IMFTransform for H264 Video Encoding. That's easily doable in Win32, where you can use MFTEnumEx to enumerate the transforms and find the H264 encoder.
However, on WinRT (Store Apps), I can't find a way to instantiate.
I've noticed there's a class CMSH264EncoderMFT, but there's no definition for the CLSID to use on CoCreateInstance.
With:
CoCreateInstance(CLSID_CMSH264EncoderMFT, nullptr, CLSCTX_INPROC_SERVER, __uuidof(IUnknown), (void **)&pUnknown);
CLSID_CMSH264EncoderMFT is undefined for WinRT apps.
And tried:
ComPtr<CMSH264EncoderMFT> encoder = Make<CMSH264EncoderMFT>();
It says the class CMSH264EncoderMFT is incomplete, and says "use of undefined type 'CMSH264EncoderMFT'". Don't even know if the syntax for Make is correct or appropriate...
Does anyone have a clue on how to do this for WinRT?
Use MFCreateSinkWriterFromURL to create a file writer first. Then, use MFCreateMediaType to create an IMFMediaType. Set up its properties, one of which will be the output format: use SetGUID method on the media type with MF_MT_SUBTYPE guid and specify MFVideoFormat_H264 as the argument. Finally, use AddStream method on the sink writer to set the media type to it.
There's an example here (you'll need to modify it a bit when it sets MF_MT_SUBTYPE).
you cannot instantiate object via CMSH264EncoderMFT because it DOES NOT have some interfaces which MUST have object in WinRT for example IInspectable - Provides functionality required for all Windows Runtime classes. CMSH264EncoderMFT IS NOT WinRT class. You can try resolve your task by function MFCreateSinkWriterFromMediaSink - this function takes an object with interface IMFMediaSink. It is possible write code for object with IMFMediaSink interface and receive samples from IMFTransform::ProcessOutput. I just point your attention - you cannot instantiate in WindowsStore code objects which IS NOT Windows Runtime classes.
Regards,
Evgeny Pereguda

how to lock the screen programmatically in windows phone 8?

We can prevent the screen to lock using the below code
PhoneApplicationService.Current.ApplicationIdleMode = IdleDetectionMode.Disabled
and
PhoneApplicationService.Current.UserIdleDetectionMode= IdleDetectionMode.Disabled
but how to lock the screen from my app. Like the below app
http://www.windowsphone.com/en-us/store/app/one-touch-lockscreen/a3b1220b-1f9a-4bf0-93bc-21ed02792279
Thanks in advance
It's pretty hacky. It's not in the official API, so it could stop working at any time, just like the volume control API. Anyway, it you want to do it, you need to use this external method:
[System.Runtime.InteropServices.DllImport("ShellChromeAPI.dll")]
private extern static void Shell_TurnScreenOn(bool value);
For WP8.0 app this needs to be in a Windows Runtime Component (you should reference its output, as the project cannot be referenced).
From what I understand, though, this won't work on WP8.1 devices, so you'll need a separate WP8.1 app and I think it needs to be a XAML (Windows Store) app.
What #yasen wrote is correct.
[DllImport("ShellChromeAPI.dll")]
private extern static void Shell_TurnScreenOn(bool value);
I've tried the following cases:
Runtime 8.1 C# (Passed store certification)
Runtime 8.1 C++ with Runtime Component 8.1 C# (Haven't tried to publish this in store)
Silverlight/DirectX 8.0 C++ (Passed store certification)
Here's the link to my app that's using the last solution mentioned above.
http://www.windowsphone.com/s?appid=38bf5918-025e-4f23-b515-2cac451a84ab
And I've heard about cases in store using Silverlight that supports 8.0 and 8.1.
You can get Screen is locked or not by Windows.Phone.System.SystemProtection.ScreenLocked
but Unfortunately There is no way to lock the screen via code in Windows Phone 7.x or 8.

Windows Phone 8 app: using Platform Invoke

I'm trying to use Platform Invoke functionality in Windows Phone 8 application and getting NotSupportedException.
I'm doing something like this:
[System.Runtime.InteropServices.DllImport("PhoneDLL1.dll")]
public static extern void CallMeInC(int num);
....
CallMeInC(100);
Am I doing something wrong or this functionality is not supported for Windows Phone 8 apps ?
Thanks,
Rafi
Unfortunately, DllImport is not supported in Windows Phone. Currenty, the only workaround is to write a native component that mimics the behavior of DllImport and then referene that component from your managed code project.
more info here: Forum thread on MSDN
and here: Blog post on how to combine native code and managed code in Windows Phone

Windows RunTime Component with NetworkCredential in windows 8

I have created sample WindowsRunTimeComponent app in windows 8, with one property my class looks like..
namespace WindowsRunTimeComponentTest
{
public sealed class Class1
{
public NetworkCredential Credentials {get; set;}
}
}
when I tried to build this, its giving error :
Method 'WindowsRunTimeComponentTest.class1.Credentials.get()' returns System.Net.Credentials', which is not a valid Windows Runtime type. Methods exposed to Windows Runtime must return only Windows Runtime types.
I have vs2012.
please any idea what I have to change to resolve this issue?
My best guess is, when you create a Windows Runtime Component, your component can be used by languages that are not managed, like Javascript or C++.
Those languages don't know how to create specific .NET types such as NetworkCredentials.
For more info see the MSDN documentation here and this stackoverflow post.

byte array parameter in visual c++

i am new to visual c++.. I had a method in .h file something like this:
public:
void DoSomething();
Here i need to pass byte array as parameter and i need to implement it in .cpp file.. I am working on windows phone 8 for this i need to include visual c++ project of windows phone run time component. I need to use this method in c# class and pass the byte array from there. But i dont know how to declare a byte array method in c++. can any one please help me to find the solution.
In C++/CX, what you're using for a Runtime Component, the signature would look like this (assuming you have a ref class):
void DoSomething(const Platform::Array<uint8>^ something);
This could be called from C# directly by passing in a byte[].
public:
void DoSomething(Byte *);
Or
public:
void DoSomething(unsigned char *);
for exemple.