Calling WinRT::MiracastReceiver from a Desktop Application(Win32/C++), it's non support - windows

First, I use WinRT::MiracastReceiver(Win10 sdk) by "Windows Application Packaging Project" in Win32/C++ project.
https://learn.microsoft.com/zh-tw/windows/msix/desktop/desktop-to-uwp-packaging-dot-net.
So It already has package identity(Private Networks and Internet C/S capability).
And I check this API has DualApiPartition property, so the desktop app can call the WinRT API.
https://learn.microsoft.com/zh-tw/windows/win32/apiindex/uwp-apis-callable-from-a-classic-desktop-app
When I start a MiracastReceiver session, I get the result MiracastNotSupported?
How can I solve this?
When I put the same code in WinRT/UWP project, it's successful.
int main()
{
winrt::init_apartment();
receiver_ = MiracastReceiver();
receiver_.StatusChanged( {&OnStatusChanged} );
MiracastReceiverSettings settings = receiver_.GetDefaultSettings();
settings.FriendlyName(L"MiracastReceiver.2020.1217");
settings.AuthorizationMethod(MiracastReceiverAuthorizationMethod::None);
settings.ModelName(receiver_.GetDefaultSettings().ModelName());
settings.ModelNumber(receiver_.GetDefaultSettings().ModelNumber());
settings.RequireAuthorizationFromKnownTransmitters(false);
auto settings_sts = receiver_.DisconnectAllAndApplySettings(settings);
session_ = receiver_.CreateSession(nullptr);
session_.AllowConnectionTakeover(true);
session_.ConnectionCreated( {&OnConnectionCreated} );
session_.Disconnected( {&OnDisconnected} );
session_.MediaSourceCreated( {&OnMediaSourceCreated} );
MiracastReceiverSessionStartResult result = session_.Start();
MiracastReceiverSessionStartStatus status = result.Status();
std::wostringstream message;
message << L"ClickHandler: session_.Start, status=" << (int)status << std::endl;
OutputDebugString(message.str().c_str());
system("PAUSE");
}
status = MiracastNotSupported
env:
Visual Studio 2017 v15.9.30
Win10 SDK 10.0.19041.0
Win10 OS 2004 (19041)

I spent 8 hours on this exact problem, and eventually found out that if I compile the app as x64 instead of targeting [Any CPU] I could get it to work.

Related

IOCreatePlugInInterfaceForService failed w/ kIOReturnNoResources/0xe00002be

IOCreatePlugInInterfaceForService failed w/ kIOReturnNoResources/0xe00002be
I am rewriting old FireWire based command line utility into XPCService. I need some help about an IOKit function.
Following part is to get IOCFPlugInInterface for FireWireAVCLibUnit.(almost same as original code; basic idea comes from legacy simpleAVC samplecode).
When I call IOCreatePlugInInterfaceForService() in the XPCService, it always failed returning 0xe00002be = kIOReturnNoResources in IOReturn.h.
I have confirmed no sandbox, no hardened for the XPC Service.
Original command line utility works perfectly on macOS 10.14 though, would you someone give me a hint on this topic?
CFDictionaryRef dict = CFDictionaryCreateCopy(kCFAllocatorDefault, self.dict);
kern_return_t result = IOServiceGetMatchingServices(kIOMasterPortDefault, dict, &serviceIterator);
if (result == KERN_SUCCESS && serviceIterator != IO_OBJECT_NULL) {
while ((service = IOIteratorNext(serviceIterator)) != IO_OBJECT_NULL) {
SInt32 score = 0;
kern_return_t result = IOCreatePlugInInterfaceForService(service,
kIOFireWireAVCLibUnitTypeID,
kIOCFPlugInInterfaceID,
&interface,
&score);
if (result != KERN_SUCCESS) continue;
// result 0xe00002be = kIOReturnNoResources in IOReturn.h
break;
}
}
Additional details
I have find IOCFPlugIn.c in opensource.apple.com. After basic verification,
- IOCreatePlugInInterfaceForService() failed to IOCFPlugIn->Start() .
(*iunknown)->QueryInterface(iunknown, CFUUIDGetUUIDBytes(interfaceType),
(LPVOID *)&interface);
<snip>
kr = (*interface)->Probe(interface, plist, service, &score);
<snip>
haveOne = (kIOReturnSuccess == (*interface)->Start(interface, plist, service));
Probe() returned kIOReturnSuccess though,
Start() failed w/ kIOReturnNoDevice = 0xe00002c0. and haveOne = false.
Finally IOCreatePlugInInterfaceForService() returned kIOReturnNoResources = 0xe00002be.
Is this related to some security feature on macOS?
MODIFIED
I have found hardened runtime with Camera access was rejected FireWireAVCLibUnit (tccd shows error).
Even if no sandbox, no hardened for the XPC Service in Xcode was checked, XPCservice is handled via sandbox. (macOS 10.14.6 + Xcode 10.3)
I would appreciate if you have an advice.
I have found the solution.
- Add NSCameraUsageDescription in Info.plist, and IOFireWireAVCUserClient will work.
- If sandboxed, com.apple.security.device.firewire is also required.
Even if capabilities-sandbox is off, tccd verify info.plist.
If “Privacy - Camera Usage Description” is not available, sandboxd reject to use IOFireWireAVCUserClient device.
Information Property List Key Reference/Cocoa Keys

Attaching to process in Visual Studio Package

I'm trying to write a Visual Studio Package that will attach the debugger to a named process.
I am using the following code in my package.
var info = new VsDebugTargetInfo
{
dlo = DEBUG_LAUNCH_OPERATION.DLO_AlreadyRunning,
bstrExe = strProcessName,
bstrCurDir = "c:\\",
bstrArg = "",
bstrEnv = "",
bstrOptions = null,
bstrPortName = null,
bstrMdmRegisteredName = null,
bstrRemoteMachine = "",
cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf<VsDebugTargetInfo>(),
grfLaunch = (uint)(__VSDBGLAUNCHFLAGS.DBGLAUNCH_DetachOnStop| __VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd| __VSDBGLAUNCHFLAGS.DBGLAUNCH_WaitForAttachComplete),
fSendStdoutToOutputWindow = 1,
clsidCustom = VSConstants.CLSID_ComPlusOnlyDebugEngine
};
VsShellUtilities.LaunchDebugger(ServiceProvider, info);
However I get the following, unhelpful, error:
Exception : Unable to attach. Operation not supported. Unknown error: 0x80070057.
The code is obviously doing something because if the process has not started I get this error
Exception : Unable to attach. Process 'xxxxxxxx' is not running on 'xxxxxxxx'.
The process is a managed .net 4 process and I am able to attach to it through the VS UI.
For context I am trying to replace a simple Macro I was using in VS 2010 to do the same job but that obviously can't be run in newer versions of Visual Studio.
I found a totally different piece of code, inspited by https://github.com/whut/AttachTo, worked much better to achieve the same result
foreach (Process process in (DTE)GetService(typeof(DTE)).Debugger.LocalProcesses)
if (process.Name.EndsWith(strProcessName,StringComparison.InvariantCultureIgnoreCase))
process.Attach();
I had to use 'ends with' because the process names include the full path to the running exe.

uninstalling applications using SCCM SDK

I have been trying to uninstall applications on devices or users using SCCM. I have been successful in creating an application assignment that would install applications, but I haven't been able to get it to uninstall. The code I have been using is:
IResultObject assignment = this.manager.CreateInstance("SMS_ApplicationAssignment");
IResultObject application =
this.manager.GetInstance("SMS_Application.CI_ID=16777339");
assignment["ApplicationName"].StringValue = application["LocalizedDisplayName"].StringValue;
assignment["AssignedCI_UniqueID"].StringValue = application["CI_UniqueID"].StringValue;
assignment["AssignedCIs"].IntegerArrayValue = new[] { application["CI_ID"].IntegerValue};
assignment["AssignmentName"].StringValue = "Deepak's deployment";
assignment["CollectionName"].StringValue = "Deepak's Collection of Devices";
assignment["DisableMomAlerts"].BooleanValue = true;
assignment["NotifyUser"].BooleanValue = false;
assignment["OfferFlags"].IntegerValue = 0;
assignment["DesiredConfigType"].IntegerValue = 1;
assignment["OverrideServiceWindows"].BooleanValue = false;
assignment["RebootOutsideOfServiceWindows"].BooleanValue = false;
assignment["SuppressReboot"].IntegerValue = 0;
assignment["TargetCollectionID"].StringValue = "UKN0000F";
assignment["EnforcementDeadline"].DateTimeValue = DateTime.Now.AddDays(1);
assignment["StartTime"].DateTimeValue = DateTime.Now;
assignment["UseGMTTimes"].BooleanValue = false;
assignment["UserUIExperience"].BooleanValue = false;
assignment["WoLEnabled"].BooleanValue = false;
assignment["RequireApproval"].BooleanValue = true;
assignment["OfferTypeId"].IntegerValue = 2;
assignment.Put();
This code will put up the application as an install deployment in SCCM. How do I get it as an uninstall deployment?
There is an AppAction enumeration, which I suspect is used by the client and not on the server.
typedef enum AppAction
{
appDiscovery = 0,
appInstall = 1,
appUninstall = 2
} AppAction;
Any help would be appreciated!
The setting that needs to be changed is DesiredConfigType.
For your code add the following before put():
assignment["DesiredConfigType"].IntegerValue = 2;
A value of 1 represents install (required) and 2 will uninstall (not allowed).
https://msdn.microsoft.com/en-us/library/hh949014.aspx
The way I do it is first use uninstall.exe to determine the guid of the program, and then create a program for the package I wish to uninstall, and just call uninstall.exe /whatever as the command. This works for most apps that show up in Add/Remove, and if it doesn't show up there then it'll have to be a hack (or script) anyway to uninstall. I believe the reason you're falling short is because if there is no command to uninstall the deployment in sccm, then it has nothing to run.
After you create an uninstall program, you could just call that deployment from your code, and voila.
As long as the target program that you are trying to use was installed via an MSI (Microsoft Installer) then you can loop through the registry to find your product (Registry Location: "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall") And just look at each DisplayName value.
In our environment, I accomplish this task by using Powershell, and we setup a program that specifically uninstalls whatever we are after.
Hope this helps...
Raged.

Open a windows phone 7 application In Emulator using Command Line

Is there a way to open a Windows Phone 7 Application in emulator using command line?
I know that there already exists a question related to this here, but I want a simple way to start a wp7 application (having the xap file) from command line without modify the code of the application.
I know that this is possible for XNA applications (info here) but I do not know if this is possible for apps made under Silverlight framework?!
Later edit - problem RESOLVED
Looking deeply, the Justin blog seemed to be very ok for this problem I've had.
Anyway I had to make some small changes:
changed the line:
Platform WP7SDK = dsmgrObj.GetPlatforms().Single(p => p.Name == "New Windows Mobile 7 SDK");
into line:
Platform WP7SDK = dsmgrObj.GetPlatforms().Single(p => p.Name == "Windows Phone 7");
I used a foreach for retrieving the platform names:
// iterate over all platforms and write their names
foreach (Platform p in dsmgrObj.GetPlatforms().ToList<Platform>())
{
Console.WriteLine("Platform: " + p.Name);
}
and the line:
WP7Device = WP7SDK.GetDevices().Single(d => d.Name == "Windows Phone 7 Emulator");
into line:
WP7Device = WP7SDK.GetDevices().Single(d => d.Name == "Windows Phone Emulator");
Used again a foreach :
// iterate over all devces and write their names
foreach (Device d in WP7SDK.GetDevices().ToList<Device>())
{
Console.WriteLine("Device: " + d.Name);
}
As mentioned you should follow Justin Angel's blog post. The end result is a very simple command line application which you run to, amongst other things, install your XAP file to the emulator/phone and start this application.
There is one thing I would modify though. Justin's app uninstalls the previous version of your application before installing the new one. This removes all files in isolated storage, including the IsolatedStorageSettings resource. I made the following changes to update the the phone application if it already exists.
// ... code to get command line parameters, device instance etc ...
if (WP7Device.IsApplicationInstalled(appID)) {
Console.WriteLine("Found {0} XAP on Windows Phone 7 Emulator/Device...", appName);
app = WP7Device.GetApplication(appID);
app.TerminateRunningInstances();
app.UpdateApplication("NormalApp",
appLocation + #"\ApplicationIcon.png",
appLocation + #"\Bin\" + configuration + #"\" + appName + #".xap");
Console.WriteLine("{0} XAP Updated from Windows Phone 7 Emulator/Device...", appName);
} else {
// Install XAP
Console.WriteLine("Installing {0} XAP to Windows Phone 7 Emulator/Device...", appName);
app = WP7Device.InstallApplication(appID,
appID,
"NormalApp",
appLocation + #"\ApplicationIcon.png",
appLocation + #"\Bin\" + configuration + #"\" + appName + #".xap");
Console.WriteLine("{0} XAP installed to Windows Phone 7 Emulator...", appName);
}
// Launch Application
Console.WriteLine("Launching {0} on Windows Phone 7 Emulator...", appName);
app.Launch();
Console.WriteLine("Launched {0} on Windows Phone 7 Emulator...", appName);
Cheers,
Alasdair

Recycling IIS application pool using PowerShell: "Exception calling Recycle"

It looks like a recent windows update has broken some functionality I was using to recycle IIS6 application pools, as this has been working for months up to today.
Exception calling "Recycle" : "Win32: The object identifier does not representException calling "Recycle" : "Win32: The object identifier does not represent a valid object.
the function I was using to recycle the application pools was:
function recycle-pool($strServerName)
{
$objWMI = [WmiSearcher] "Select * From IIsApplicationPool"
$objWMI.Scope.Path = "\\" + $strServerName + "\root\microsoftiisv2"
$objWMI.Scope.Options.Authentication = 6
$pools = $objWMI.Get()
foreach ($pool in $pools)
{
$pool.recycle()
if (!$?)
{
Write-Host $pool.name " - ERROR"
}
else
{
Write-Host $pool.name " - Recycled"
}
}
Any idea on what the problem is and how I should approach this?
The original question was for IIS6, but I ran into something similar using the WebAdministration Module's Restart-WebAppPool on Windows 2012. So I dropped back to calling AppCMD, and that worked fine:
& $env:windir\system32\inetsrv\appcmd recycle apppool "YOURAPPPOOLNAMEHERE"
Sometimes, you don't have to over-engineer the solution. Hope that helps others some day.
One of the application pools was stopped, which was causing the error. The other application pools were recycling fine. The code above is ok to use for anyone else.
You can try to recycle with ADSI:
$server = "IIsServerName"
$iis = [adsi]"IIS://$server/W3SVC/AppPools"
$iis.psbase.children | foreach {
$pool = [adsi]($_.psbase.path)
$pool.psbase.invoke("recycle")
}

Resources