How to use the standard output by Flash Air? - actionscript-3

I want to make a command line tool by Flash Air, but there is not any api of AS3 to output content to standard output.
Then, I try to use ANE to solve my problem(By making a windows ane and use C's printf function to output content), but it doesn't work.
Is there any methods to use the standard output by Flash air, or to make a command line tool by Flash Air?
The code of dll written by c++ is:
FREObject add(FREContext ctx, void* functionData, uint32_t argc, FREObject argv[])
{
int32_t x,y;
FREGetObjectAsInt32(argv[0], &x);
FREGetObjectAsInt32(argv[1], &y);
int32_t result = x + y;
FREObject resObj;
FRENewObjectFromInt32(result, &resObj);
//I want to use the "printf" to print content to the console
printf("print by dll: the result is %d\n", result);
return resObj;
}

but there is not any api of AS3 to output content to standard output.
Only a running OS process can give back Standard Output (also called stdio in C).
The best you can do is create an app that looks like commandline tool but in reality it just runs & passes data to the actual (native) OS commandline tool. Meaning in your tool you capture the user command to a string and then run a nativeProcess involving that (parsed) string as your process arguments.
Example in your app user types : calc. Your AIR runs: c:\Windows\System32\calc.exe
Anyways, on to your real question...
I try to use C's printf function to output content, but it doesn't
work.
If you mean you made some test.exe with C and when you get AIR to run it you want to capture the printf output then you can try:
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, CTest_OutputData);
or
process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, CTest_ErrorData);
To catch the output (it will be sent as bytes) make sure you have some public byteArray and String created. Here's an example for STANDARD_ERROR_DATA (it's likely the output goes here too, since you claim that STANDARD_OUTPUT_DATA is not working).
The code shown below inside that function works same whichever type of progressEvent you choose. Just put in the "right" one. temp_BA is the byteArray variable you setup earlier.
public function CTest_ErrorData (event:ProgressEvent):void
{
process.standardOutput.readBytes( temp_BA, temp_BA.length, process.standardOutput.bytesAvailable );
if ( temp_BA.length > 0 )
{
temp_String = temp_BA.readUTFBytes(temp_BA.length);
trace( "temp_String is : " + temp_String ); //if you want to check it
}
}
Final TIP: You can get traces inside Flash IDE by disabling "desktop" and keeping "extended desktop" ticked. Both must be ticked later when you make installing app.

Related

How to fix 'avr-g++: error: device-specs/specs-atmega328p: No such file or directory' error in Arduino IDE

I am programming my arduino uno on the new raspberry pi 4. I have installed arduino IDE v1.8.9 and I am having issues in compiling the code.
I am getting an error.
avr-g++: error: device-specs/specs-atmega328p: No such file or directory
Please Help.
I am running Rasbian Os
/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the Serial Monitor.
Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/AnalogReadSerial
*/
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(1); // delay in between reads for stability
}
This is the -tools option for arduino-builder missing the location avr.
A setting like
-tools /home/owner/arduino-1.8.10/hardware/tools/avr
is needed so as to find the spec files. Set your compile output to verbose to see the compile command that is issued, and verify above line is present.
More info: https://github.com/arduino/arduino-builder/issues/263

How to get NV12 file in the Nvidia CUDA 5.0 SDK's project cudaDecodeGL?

Lately, I've been reading the cudaDecodeGL project of Nvidia cuda5.0 SDK.This project convert a MPEG2 file to NV12 file, then the NV12 file is converted to ARGB file in the kernel function, finally this ARGB file will be rendered and displayed in the OpenGL window. Actually, the middle-produced NV12 file is not output, while I want to get the NV12 file.
I would be so appreciated if someone could tell me what to do.
Referring to the whitepaper:
Post processing on a frame is done by mapping the frame through cudaPostProcessFrame(). This returns a pointer to a NV12 decoded frame.
This function is contained (and used) in the source file videoDecodeGL.cpp which is contained in the sample project.
There is only one actual use (function call) for this function. It is called out of the copyDecodedFrameToTexture function. The decoded frame in this function is what you want. If you look through this function prior to the call to cudaPostProcessFrame you'll see the following code:
// If streams are enabled, we can perform the readback to the host while the kernel is executing
if (g_bReadback && g_ReadbackSID)
{
CUresult result = cuMemcpyDtoHAsync(g_bFrameData[active_field], pDecodedFrame[active_field], (nDecodedPitch * nHeight * 3 / 2), g_ReadbackSID);
This shows how/where/when to grab the decoded frame back to the host if you want to. At that point you will have to queue up the frames and save to a file if that is what you want to do.

Disable Windows 8 edge gestures/hot corners for multi-touch applications while running in full screen

I have a full screen AS3 game maby with Adobe AIR that runs in Windows 7.
In this game it may not be easy to exit (think about kiosk mode, only exit by pressing esc and enter a password).
Now I want this game to run in Windows 8. The game is working like expected but the anoying things are these edge gestures/hot corners (left, top, right, bottom) and the shortcuts.
I've read articles but none helped me. People talk about registery edits, but I dont get this working + the user needs to restart his/hers computer.
I want to open my game, turn off gestures/hot corners and when the game closes the gestures/hot corners need to come back available again.
I have seen some applications doing the same what I want to accomplish.
I found this so I am able to detect the gestures. But how to ignore they're actions?
I also read ASUS Smart Gestures but this is for the touch-pad.
And I have tried Classic Shell but I need to disable the edge gestures/hot corners without such programs, just on-the-fly.
I also found this but I don't know how to implement this.
HRESULT SetTouchDisableProperty(HWND hwnd, BOOL fDisableTouch)
{
IPropertyStore* pPropStore;
HRESULT hrReturnValue = SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(&pPropStore));
if (SUCCEEDED(hrReturnValue))
{
PROPVARIANT var;
var.vt = VT_BOOL;
var.boolVal = fDisableTouch ? VARIANT_TRUE : VARIANT_FALSE;
hrReturnValue = pPropStore->SetValue(PKEY_EdgeGesture_DisableTouchWhenFullscreen, var);
pPropStore->Release();
}
return hrReturnValue;
}
Does anyone know how I can do this? Or point me into the right direction?
I have tried some in C# and C++, but I aint a skilled C#/C++ developer. Also the game is made in AS3 so it will be hard to implement this in C#/C++.
I work on the Lenovo aio (All in one) with Windows 8.
I am making a kiosk application for windows 8 using C#,
I succesfully disabled the swipe gestures by killing the explorer process
when the program starts up. I don't know how it's done in C++
but in C# it's like this.
var explorers = Process.GetProcessesByName("explorer");
foreach (var explorer in explorers) {
explorer.Kill();
}
On the closing event of my program I just start the process again.
Process.Start("explorer.exe");
Before this works you might have to edit your register to prevent explorer
from restarting after you kill it.
In regedit go to
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
Set the AutoRestartShell to 0.
(as long as your running off AIR - which it sounds like) You can use AIR 2.0's NativeProcess to execute it.
From there I can think of two solutions:
If there are command line options in Classic Shell, call it from within your AS3 and toggle the gestures on/off through it.
Write a C++ application that toggles the gestures on/off manually.
If you can get that example working in C++, add a bit to the C++ to handle a on/off command line argument and call the C++ exe on initialization and exit of your AS3 application to toggle.
I don't have C++ installed here (at work), but it looks like that C++ function just requires the window handle of your application (hWnd). This tutorial should get you compiled and running, but the window handle you see there will be for the C++ application's window.
Accessing the flash window's handle will be slightly more difficult:
for a direct solution; you'll need to use .NET - Process.MainWindowHandle,
or alternatively without .NET -
How to get main window handle from process id?
Either way you'll need to use the Process name or ID to identify it as your AS3 process.
This solution also depends on your ability to install things other than the AIR app on the client PC. (ie .NET runtimes, C++ runtimes, Classic Shell installer)
I'm trying to do the same thing. The C++ below disables Win8 Gestures on every running application/window. As JonoRR mentioned, the next step would be calling it only on the HWND you would like to target. If the targeted application is closed, then re-opened, the gestures will return.
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <propsys.h>
#include <propkey.h>
using namespace std;
HWND windowHandle;
HRESULT SetTouchDisableProperty(HWND hwnd, BOOL fDisableTouch)
{
IPropertyStore* pPropStore;
HRESULT hrReturnValue = SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(&pPropStore));
if (SUCCEEDED(hrReturnValue))
{
PROPVARIANT var;
var.vt = VT_BOOL;
var.boolVal = fDisableTouch ? VARIANT_TRUE : VARIANT_FALSE;
hrReturnValue = pPropStore->SetValue(PKEY_EdgeGesture_DisableTouchWhenFullscreen, var);
pPropStore->Release();
}
return hrReturnValue;
}
BOOL CALLBACK MyEnumProc(HWND hWnd, LPARAM lParam)
{
TCHAR title[500];
ZeroMemory(title, sizeof(title));
GetWindowText(hWnd, title, sizeof(title)/sizeof(title[0]));
SetTouchDisableProperty(hWnd,true);
_tprintf(_T("Value is %s\n"), title);
return TRUE;
}
int _tmain(int argc, _TCHAR* argv[])
{
EnumWindows(MyEnumProc, 0);
return 0;
}
The answer below is based on Dovogja's brilliant answer, but it uses a batch file to do it. This way you just have to launch with a launch.bat
Windows charms bar is operated by explorer.exe. So if your app can run without it then you can hack around it by first disabling the autorestart of explorer.exe via (run as administrator):
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "AutoRestartShell" /t REG_DWORD /d 0
Then the lines below represent my launch.bat - which works in the end as expected:
;; kill explorer (this disables all windows functionalities
taskkill /f /im explorer.exe
;; start your kiosk app - should block the batch execution (so explorer.exe doesn't get executed at the end)
"\path\to\your\app.exe"
;; after you close both the app window and the opened chrome window relaunch explorer.exe to give back the functionality to windows
explorer.exe
I use the approach outlined above to let a keyboardless kiosk app run. Because with a keyboard you can still close the app with alt+f4.

Does ActionScript have an equivalent of a "core dump"?

Here's my situation: I'm working on an AS3-based game and I'd like to have a "Report a problem!" function within the game so that users can submit feedback to me.
When my user reports a problem, I'd like to get as much information as I can about the state of their game; basically what objects are in memory, what the values are of all those variables inside all those objects; essentially the same information I can get when I hit a breakpoint in the debugger.
Is there a simple way of doing this? I'm afraid that I'll spend several days trying to write a bunch of functions that gets all this information for me, only to have somebody tell me afterwards, "Oh, why didn't you just call ASUtils.getSnapshot()"?
There is no generic way in AS3 to dump the state of your variables, but there are several things we do that you might find useful:
Capture a log of recent click activity. Use stage event listener to log clicks and trace the object "path" up the parent chain to the stage. The object path is just all the DisplayObject names, like: screenMain.dialogBuyItem.buttonBuy
Capture a screenshot, reduce it to a small thumbnail, JPEG encode it, and upload it to your server along with their feedback. We also do this when there is an exception (see #4). as3corelib has JPEG encoding functions in com/adobe/images
Write a command-line pearl or PHP script you can run on your AS3 code before you publish it that will inject call tracing at the top of each function call. This allows call history to be logged. While it's not as good as a full stack, it will give you some indication of what your code has been doing recently.
Trap asserts and unhandled exceptions and log them to your server with click activity and call history trace. Unhandled exception listeners are new in flash 10.1, but most users have this feature. You can check for that support and add a listener like this:
// Check for the presence of the Flash 10.1 global Error event (exception) handler class.
// If it exists, we'll listen for it and it will allow us to report errors to our server.
if ( loaderInfo.hasOwnProperty( 'uncaughtErrorEvents' ) )
loaderInfo.uncaughtErrorEvents.addEventListener( "uncaughtError", onUncaughtError ); // UncaughtErrorEvent.UNCAUGHT_ERROR
If you have global state variables that you want to log with feedback, you can write a function to dump them to a string for uploading with the user feedback. While you can enumerate class and object properties using for each, this only works for public members. Google around and you'll find some functions people have written to dump objects and array data recursively using this enumeration trick.
i'd like to add it as a comment, but don't want to lose code formatting
this is what i'm using to trace complex objects:
private function parseObject(o:Object, prefix:String = '>'):String {
var retStr:String = '';
for (var s:String in o) {
retStr += prefix + s + ' = ' + o[s] + '\n';
if (typeof(o[s]) == 'object') {
retStr += parseObject(o[s], prefix + '>');
}
}
return retStr;
}
hope it'd be helpful

Unhandled Exception with c++ app on Visual Studio 2008 release build - occurs when returning from function

I have a (rather large) application that I have written in C++ and until recently it has been running fine outside of visual studio from the release build. However, now, whenever I run it it says "Unhandled exception at 0x77cf205b in myprog.exe: 0xC0000005: Access violation writing location 0x45000200.", and leads me to "crtexe.c" at line 582 ("mainret = main(argc, argv, envp);") if I attempt to debug it. Note that this problem never shows if I run my debug executable outside of visual studio, or if I run my debug or release build within visual studio. It only happens when running the release build outside of visual studio.
I have been through and put plenty of printfs and a couple of while(1)s in it to see when it actually crashed, and found that the access violation occurs at exactly the point that the value is returned from the function (I'm returning a pointer to an object). I don't fully understand why I would get an access violation at the point it returns, and it doesn't seem to matter what I'm returning as it still occurs when I return 0.
The point it started crashing was when I added a function which does a lot of reading from a file using ifstream. I am opening the stream every time I attempt to read a new file and close it when I finish reading it.
If I keep attempting to run it, it will run once in about 20 tries. It seems a lot more reliable if I run it off my pen drive (it seems to crash the first 3 or 4 times then run fine after that - maybe it's due to its slower read speed).
Thanks for your help, and if I've missed anything let me know.
EDIT: New info
Well I removed the entirity of the function and replaced it with:
IndexedMesh * loadObj(char * objName)
{
ifstream fp_in;
fp_in.open("lol.bmp", ios::in);
fp_in.clear();
fp_in.close();
IndexedMesh * mesh = new IndexedMesh();
printf("finished");
return mesh;
}
I also tried it with "return 0" and "return new IndexedMesh()". It's all fine until you put the ifstream stuff in. I do have 2 other ifstreams open in different functions (accessing completely different files). Could this be the problem?
It actually errors on the return mesh line, (I got the debugger working with the separate release file). It completely nulls the mesh object when it attempts to return it.
The point it started crashing was when I added a function which does a lot of reading from a file using ifstream. I am opening the stream every time I attempt to read a new file and close it when I finish reading it.
Given your description of the code only failing in release mode outside the debugger I'd examine this function for any unset variables. Compiling debug sets variables (or at least it used to) as did running release code in the debugger.
You are probably running over something stored deep in the stack.
I'll bet that if you were to put this at near the top of your code:
int my_main(int argc, char * argv[], char * envp[]);
int main(int argc, char * argv[], char * envp) {
char ** a;
char ** e;
a = malloc(argc+1); // note: you should test the results for NULL
e = malloc(1+count(envp) ) ;// I'm not writing code to count it, but it's easy
int i = 0;
while (argv[i++]) {
a[i] = strdup(argv[i]);
}
a[i] = argv[i]; // argv[i] is NULL and already in a register
// do the same thing for envp
return my_main(argc, a, e);
}
#define main my_main
then whatever it is that is smashing your stack would instead end up smashing this duplicated environment. It's not garenteed, and it is no fix for your problem, but not that difficult.
Thanks very much for your help, I haven't exactly solved the problem but I have managed to evade it. Basically, if I even mentioned an ifsteam (in that function and that function only), the program crashed.
I actually went as far as altering the function to simply declare an ifstream then return 0. I "fixed" it by declaring the ifstreams as pointers and new-ing them. If I deleted the pointer it crashed out again so I had to set it to 0 (leeeeak).
If anyone could enlighten me as to why this occurs, that would be great. While I'm just happy it works now, I'd rather know why..