How to get Monitor Handle from Index or Name? - windows

A C++ version (How can I get an HMONITOR handle from a display device name?) has no solution provided (at least in my circumstances that require non-OOP code such as in AutoIt).
I'm adapting an AutoIt script that uses WinAPI functions to support multi-monitor Windows 7+ systems. I can provide either monitor/device Name or it's Index, but some functions require an HMONITOR handle instead.
I cannot get the HMONITOR by Window or by pixel or point, which would be quite easy. No, I need to get the handle from name or index only, and I need a non-OOP solution (ideally AutoIt & WinAPI calls but non-OOP pseudo-code would be fine).

The function below returns an array of the following structure:
| hMonitor | xPosMonitor | yPosMonitor | widthMonitor | heightMonitor |
| 0x00010001 | 0 | 0 | 1366 | 768 |
| 0x0001024 | 1366 | -236 | 1920 | 1080 |
Code:
#include-once
#include <Array.au3>
#include <WinAPIGdi.au3>
Func _getMonitorInfos()
Local $aPosition, $aMonitorData = _WinAPI_EnumDisplayMonitors()
If IsArray($aMonitorData) Then
ReDim $aMonitorData[$aMonitorData[0][0] + 1][5]
For $i = 1 To $aMonitorData[0][0] Step 1
$aPosition = _WinAPI_GetPosFromRect($aMonitorData[$i][1])
For $j = 0 To 3 Step 1
$aMonitorData[$i][$j + 1] = $aPosition[$j]
Next
Next
Return $aMonitorData
EndIf
EndFunc
Global $aMonitorData = _getMonitorInfos()
_ArrayDisplay($aMonitorData)
hMonitor value is contained by the array $aMonitorData[1][1].

Related

Simple Arduino PlatformIO C++11 project has undefined reference to default constructor during linking stage (but intellisense detects no errors)

I've been scouring the internet trying to find a solution and done a ton of tinkering myself, but at this point, I've lost all my hair and feel no closer to solving this problem.
The intellisense in VSCode with Platformio extension is able to auto complete the constructors from /lib/SelectWheel/SelectWheel.h, but it seems like the build linker can't find the header and/or cpp file. Why would the intellisense and build process disagree? How can I fix this?
Here's the error:
Linking .pio\build\megaatmega2560\firmware.elf
C:\Users\matth\AppData\Local\Temp\cclHZ2N6.ltrans0.ltrans.o: In function `_GLOBAL__sub_I_selectWheel':
<artificial>:(.text.startup+0xf6): undefined reference to `SelectWheel::SelectWheel()'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\megaatmega2560\firmware.elf] Error 1
Here's the terminal output for pio run -t clean and platformio run --verbose: https://pastebin.com/xn862p00
Here's the project structure:
Hydro9000
| -- .pio
| -- .vscode
| -- include
| | -- Adafruit_BusIO
| | -- Adafruit_EPD
| | -- Adafruit_GFX_Library
| | -- Adafruit_SSD1306
| | -- ArduinoSTL
| -- lib
| | -- SelectWheel
| | | -- SelectWheel.h
| | | -- SelectWheel.cpp
| -- src
| | -- main.cpp
| -- platformio.ini
Here's platformio.ini
[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
framework = arduino
Here's /src/main.cpp
#include <Arduino.h>
#include "SelectWheel/SelectWheel.h"
SelectWheel* selectWheel = new SelectWheel();
void setup() {}
void loop() {}
Here's /lib/SelectWheel/SelectWheel.h
#ifndef SelectWheel_h
#define SelectWheel_h
#include "Arduino.h"
class SelectWheel {
private:
int pinA, pinB;
public:
SelectWheel();
SelectWheel(int, int);
};
#endif
Here's /lib/SelectWheel/SelectWheel.cpp
#include "SelectWheel.h"
SelectWheel::SelectWheel() {}
SelectWheel::SelectWheel(int pinA, int pinB) {
this->pinA = pinA;
this->pinB = pinB;
pinMode(this->pinA, INPUT);
pinMode(this->pinB, INPUT);
}
Let me know if there is any additional information I can supply to help as I've already tried a bunch of ways to fix this.
I am using...
VSCode v1.47.2
PlatformIO IDE Extension (platformio.platformio-ide) v1.10.0
Microsoft C/C++ Extension (ms-vscode.cpptools) v0.29.0
According to your build log, your file SelectWheel.cpp didn't participate in build process at all (it has not been built). So, add it to build process and make sure it's linked

how get the cisco switch interfaces' status by snmp?

By using command line(ssh), I can get switch interfaces status like below(just demo):
Cisco-Switch# show int status
Port Name Status Vlan Duplex Speed
Eth0/1 test_alias connected 1 a-full a-100
Eth0/2 notconnect 1 auto auto
Eth0/3 connected 3 a-full a-100
Eth0/4 connected 3 a-full a-100
Eth0/5 potchann linkFlapE 255 auto auto
Eth0/6 notconnect 300 auto auto
Eth0/7 sfpAbsent routed auto auto
Eth0/8 sfpAbsent routed auto auto
Eth0/9 connected trunk full a-10G
By using SNMP walk(oid:.1.3.6.1.2.1.2.2.1 or .1.3.6.1.2.1.31.1.1.1), I can get every interface name, adminStatus, operStatus and so on.
I got these after the summary:
| adminStatus | OperStatus | commandLine Port Status |
| up | up | connected |
| up | down | notconnect |
| up | down | linkFlapE |
| up | down | sfpAbsent |
| down | down | disable |
| down | down | sfpAbsent |
abviosly, there are 3 staus when AdminStatus is up and OperStatus is down in snmp oid "1.3.6.1.2.1.2.2.1".
So, I think the commandLine port status cannot be fetched by this snmp oid.
finnaly, I don't find a way to get switch interface status(like "connected","notconnect","disable","sfpAbsent") in SNMP.
hoping someone can tell me the oid to resolve it.
Thx for your help.
Most of the interface information is retrievable using this OID:
.1.3.6.1.2.1.2.2.1.7
Maybe u can try this oid .1.3.6.1.2.1.2.2.1.8 (ifOperStatus). It should have this (1-up, 2-down, 3-testing, 4-unknown, 5-dormant, 6-notPresent, 7-lowerLayerDown) from the site I have been search for. link

run a program with tcsetattr raw mode in background

I need to run a program as is in the background. The catch is that the program does a tcsetattr() call and sets the raw mode as following :
struct termios tio;
if (tcgetattr(fileno(stdin), &tio) == -1) {
perror("tcgetattr");
return;
}
_saved_tio = tio;
tio.c_iflag |= IGNPAR;
tio.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF);
tio.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL);
// #ifdef IEXTEN
tio.c_lflag &= ~IEXTEN;
// #endif
tio.c_oflag &= ~OPOST;
tio.c_cc[VMIN] = 1;
tio.c_cc[VTIME] = 0;
if (tcsetattr(fileno(stdin), TCSADRAIN, &tio) == -1)
perror("tcsetattr");
else
_in_raw_mode = 1;
The implication is that as soon as I run my program with '&' and press enter, the process shows 'stopped'. Even the ps aux output shows 'T' as the process state which means it is not running.
How can I make this program running in background.Issue is I cant modify this program.
For complete details, actually I need to use ipmitool with 'sol' as a background process.
Any help is appreciated !
Thanks
It is hard to give a complete answer on what is going wrong without knowledge of how ipmitool is actually used/started but I'll try to add some details.
So all the options in the question are needed to adjust i/o for the program (see comments):
// ignorance of errors of parity bit
tio.c_iflag |= IGNPAR;
// removed any interpretation of symbols (CR, NL) for input and control signals
tio.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF);
// switch off generation of signals for special characters, non-canonical mode is on,
// no echo, no reaction to kill character etc
tio.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL);
// removed recognition of some spec characters
// #ifdef IEXTEN
tio.c_lflag &= ~IEXTEN;
// #endif
// disable special impl-based output processing
tio.c_oflag &= ~OPOST;
// minimum number of characters to read in non-canonical mode
tio.c_cc[VMIN] = 1;
// timeout -> 0
tio.c_cc[VTIME] = 0;
// accurately make all the adjustments then it will be possible
if (tcsetattr(fileno(stdin), TCSADRAIN, &tio) == -1)
perror("tcsetattr");
else
_in_raw_mode = 1;
More details on terminal configuring are here and here.
In other words this part of code configures the standard input of the process to a "complete silent" or "raw" mode.
In spite of the lack of the information you may also try "kill -cont %PID%" to the process or try to provide some file as standard input for it.

List of all (integer) constants for various types

Does there exist some kind of service, where I can input a system "enum type" (or similar) and get a list of all the possible values?
When debugging with gdb and you encounter an error, it would be nice to quickly get the name of the error, without having to look through related headers files of the header file where the type is defined.
For example the type kern_return_t in OS X is defined in /usr/include/mach/i386/kern_return.h which basically only contains one line of content (no includes):
typedef int kern_return_t;
The valid values are defined in /usr/include/mach/kern_return.h, which makes sense, but I can never remember this path and I would like to speed up this process.
Example:
Input: kern_return_t
Output:
0 | KERN_SUCCESS
1 | KERN_INVALID_ADDRESS
2 | KERN_PROTECTION_FAILURE
3 | KERN_NO_SPACE
4 | KERN_INVALID_ARGUMENT
5 | KERN_FAILURE
6 | KERN_RESOURCE_SHORTAGE
7 | KERN_NOT_RECEIVER
8 | KERN_NO_ACCESS
9 | KERN_MEMORY_FAILURE
...
This is what open -h was made for. I recommend combining it with -s however, like so:
$ open -s iOS -h kern_return
kern_return?
[0] cancel
[1] all
[2] /usr/include/mach/i386/kern_return.h
[3] /usr/include/mach/kern_return.h
[4] /usr/include/mach/machine/kern_return.h
[5] /System/Library/Frameworks/Kernel.framework/Headers/mach/i386/kern_return.h
[6] /System/Library/Frameworks/Kernel.framework/Headers/mach/kern_return.h
[7] /System/Library/Frameworks/Kernel.framework/Headers/mach/machine/kern_return.h
Which header(s) for "kern_return"?

fopen and open produce files with different file permissions

These two code snippets produce files with different file-permissions. Example 1 creates the expected default file-permissions but Example 2 does not. What's the explanation for this?
OS: Mac OS X version: 10.6.4
Xcode version: 3.2.2, 64 bit
// Example 1
FILE *fh1 = fopen("Test1.txt", "w+x");
if (fh1) {
fwrite("TEST1", 1, 5, fh1);
fclose(fh1);
}
Creates:
-rw-r--r-- 1 me staff 5 29 Jul 00:41 Test1.txt
// Example 2
int fh2 = open("Test2.txt", O_EXCL | O_CREAT | O_WRONLY);
if (fh2 >= 0) {
write(fh2, "TEST2", 5);
close(fh2);
}
Creates:
---------- 1 me staff 5 29 Jul 00:41 Test2.txt
When you use O_CREAT you need to add a third argument to open, the mode. For instance:
int fh2 = open("Test2.txt",
O_EXCL | O_CREAT | O_WRONLY,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
This would be equivalent to 0666. Be aware that this mode is then masked by the process's umask, meaning the permissions you specify will usually be reduced a bit. A typical umask is 0022, which would result in a mode of 0666 & ~0222 = 0644, i.e. -rw-r--r--.
From man open:
The oflag argument may indicate that the file is to be created if it does not exist (by specifying the O_CREAT flag). In this case, open requires a third argument mode_t mode; the file is created with mode mode as described in chmod(2) and modified by the process' umask value (see umask(2)).
int open(const char *pathname, int flags, mode_t mode);
The argument mode specifies the permissions to use in case a new file is created. See http://linux.about.com/od/commands/l/blcmdl2_open.htm
In your case, you'll want to set mode with value 0644

Resources