How to convert cyrillic clipboard text to windows-1257 encoding - winapi

Visual FoxPro 9 grid control text field contains russian characters. Font charset is set to Cyrillic.
If russian text is pasted from web page to this field, ??? characters appear instead of russian letters.
I tried
CLEAR
_screen.FontCharSet= 204
cContents = STRCONV(_cliptext,9,1251,1)
?ccontents
cContents = STRCONV(_cliptext,6,1251,1)
?ccontents
cContents = STRCONV(cContents,9,1251,1)
?ccontents
FOR i=1 TO 15
?i,STRCONV(_cliptext,i)
ENDFOR
But russian characters do not appear in any line.
For example, Аналитика produces output
How to convert russian clipboard data to windows 1251 encoding ?
Can some foxpro or windows API function used for this ?
Update
I tried code below from http://www.news2news.com/vfp/?function=-1&example=31 and copied single english character to clipboard but it is not returned
Avaliable count of formats is 5. How to get raw clipboard content as unicode data ?
CLEAR
_screen.FontCharSet= 204
#DEFINE CF_TEXT 1
#DEFINE CF_BITMAP 2
#DEFINE CF_METAFILEPICT 3
#DEFINE CF_SYLK 4
#DEFINE CF_TIFF 6
#DEFINE CF_DIF 5
#DEFINE CF_OEMTEXT 7
#DEFINE CF_DIB 8
#DEFINE CF_PALETTE 9
#DEFINE CF_PENDATA 10
#DEFINE CF_RIFF 11
#DEFINE CF_WAVE 12
#DEFINE CF_UNICODETEXT 13
#DEFINE CF_ENHMETAFILE 14
#DEFINE CF_HDROP 15
#DEFINE CF_LOCALE 16
#DEFINE CF_DIBV5 17
DO declare
ncount=CountClipboardFormats()
? "Number of formats currently on the clipboard: ", ncount
cBuffer = Chr(CF_TEXT) + Repli(Chr(0),3) +;
Chr(CF_OEMTEXT) + Repli(Chr(0),3) +;
Chr(CF_UNICODETEXT) + Repli(Chr(0),3)
? "First available text format, ID: " +;
LTRIM(STR(GetPriorityClipboardFormat(#cBuffer, 3)))
?'Buffer: ', cbuffer
PROCEDURE declare
DECLARE INTEGER CountClipboardFormats IN user32
DECLARE INTEGER GetPriorityClipboardFormat IN user32;
STRING #paFormatPriorityList, INTEGER cFormats
RETURN

Related

Read a utf8 file to a std::string without BOM

I am trying to read a utf8 content to char*, my file does not have any DOM, so the code is straight, (the file is unicode punctuation)
char* fileData = "\u2010\u2020";
I cannot see how a single unsigned char 0 > 255 can contain a character of value 0 > 65535 so I must be missing something.
...
std::ifstream fs8("../test_utf8.txt");
if (fs8.is_open())
{
unsigned line_count = 1;
std::string line;
while ( getline(fs8, line))
{
std::cout << ++line_count << '\t' << line << L'\n';
}
}
...
So how can I read a utf8 file into a char*, (or even a std::string)
well, you ARE reading the file correctly into std::string and std::string do support UTF8, it's probably that your console * which cannot show non-ASCII character.
basically, when a character code page is bigger than CHAR_MAX/2, you simply represent this character with many character.
how and how many characters? this is what encoding is all about.
UTF32 for example, will show each character, ASCII and non ASCII as 4 characters. hence the "32" (each byte is 8 bit, 4*8 = 32).
without providing any auditional information on what OS you are using, we can't give a an advice on how your program can show the file's line.
*or more exactly, the standard output which will probably be implemented as console text.

PE/COFF symbol type field

Microsoft's documentation for PE/COFF says of the type field in the symbol table:
"The most significant byte specifies whether the symbol is a pointer to, function returning, or array of the base type that is specified in the LSB. Microsoft tools use this field only to indicate whether the symbol is a function, so that the only two resulting values are 0x0 and 0x20 for the Type field."
However, the documentation and winnt.h both specify that IMAGE_SYM_DTYPE_FUNCTION = 2, not 0x20. Even if this is taken to be the value of the MSB, that would give a value for the entire field of 0x200, not 0x20.
What am I missing?
Check winnt.h for following lines:
// type packing constants
#define N_BTMASK 0x000F
#define N_TMASK 0x0030
#define N_TMASK1 0x00C0
#define N_TMASK2 0x00F0
#define N_BTSHFT 4
#define N_TSHIFT 2
// MACROS
// Basic Type of x
#define BTYPE(x) ((x) & N_BTMASK)
// Is x a pointer?
#ifndef ISPTR
#define ISPTR(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_POINTER << N_BTSHFT))
#endif
// Is x a function?
#ifndef ISFCN
#define ISFCN(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT))
#endif
So it seems official MSB, LSB description is wrong - they are not bytes but nibbles. So 0x20 would be a function (MS nibble = 2) returning base type of IMAGE_SYM_TYPE_NULL (LS nibble = 0) .

Cocoa: How to get a music file's Disc Number tag?

Right now i can get these tags from an audio file:
#define kAFInfoDictionary_Artist "artist"
#define kAFInfoDictionary_Album "album"
#define kAFInfoDictionary_Tempo "tempo"
#define kAFInfoDictionary_KeySignature "key signature"
#define kAFInfoDictionary_TimeSignature "time signature"
#define kAFInfoDictionary_TrackNumber "track number"
#define kAFInfoDictionary_Year "year"
#define kAFInfoDictionary_Composer "composer"
#define kAFInfoDictionary_Lyricist "lyricist"
#define kAFInfoDictionary_Genre "genre"
#define kAFInfoDictionary_Title "title"
#define kAFInfoDictionary_RecordedDate "recorded date"
#define kAFInfoDictionary_Comments "comments"
#define kAFInfoDictionary_Copyright "copyright"
#define kAFInfoDictionary_SourceEncoder "source encoder"
#define kAFInfoDictionary_EncodingApplication "encoding application"
#define kAFInfoDictionary_NominalBitRate "nominal bit rate"
#define kAFInfoDictionary_ChannelLayout "channel layout"
#define kAFInfoDictionary_ApproximateDurationInSeconds "approximate duration in seconds"
#define kAFInfoDictionary_SourceBitDepth "source bit depth"
#define kAFInfoDictionary_ISRC "ISRC" // International Standard Recording Code
#define kAFInfoDictionary_SubTitle "subtitle"
So how can i get the Disc Number tag? Thanks!
You can try to use TagLib: http://taglib.github.io/
It's free and powerful.

Letting the mouse pass through Windows C++

I am working on an Win32 C++ application where I want to ignore the mouse events and let is pass through to the window beneath my window. Basically the window below mine will handle the mouse event. I would prefer not to send the mouse message using SendMessage to the window beneath mine or use SetCapture. Is there a way basically to ignore the mouse event and let it pass through with Windows APIs or with styles? Note that my window is not transparent.
Thanks in advance for the help.
So I found this question, and others, while attempting to create a music player that overlays a graphical display over the screen without impacting any other interaction, including e.g. dragging windows.
I've tried both the WM_NCHITTEST approach, as well as simply adding WS_EX_TRANSPARENT to my window. Neither of these approaches work -- they both seem to capture mouse click events, which is something I don't want.
However, by pure coincidence, I did manage to find a combination of flags I can pass to SetWindowLong(..., GWL_EXSTYLE, ...) that seem to do the trick, leading to the following code:
LONG cur_style = GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong(hwnd, GWL_EXSTYLE, cur_style | WS_EX_TRANSPARENT | WS_EX_LAYERED);
It appears that this behavior is documented here:
Hit testing of a layered window is based on the shape and transparency of the window. This means that the areas of the window that are color-keyed or whose alpha value is zero will let the mouse messages through. However, if the layered window has the WS_EX_TRANSPARENT extended window style, the shape of the layered window will be ignored and the mouse events will be passed to other windows underneath the layered window.
The extended window style documentation is also very useful. For applications such as mine, where a window is not meant to be interacted with, WS_EX_NOACTIVATE may also be useful, as it prevents some user interactions.
For posterity's sake, I will note that the code I am using to ensure my window is always on top is the following:
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
I would try handling WM_NCHITTEST and returning HTNOWHERE.
I believe the approaches that use WS_EX_TRANSPARENT will have other side effects and are only useful if the underlying window is owned by the same thread. From the question, it's not clear if the underlying windows are part of the same application or any old application underneath.
I have been testing this with 2 different RDC solutions by 2 different 3rd parties. Each solution probably creates its own window differently, with different styles etc. If I do below in WindowProc:
case WM_MOUSEMOVE:
{
std::cout << "WM_MOUSEMOVE" << std::endl;
VideoWindowWin32* window = reinterpret_cast<VideoWindowWin32*> (GetWindowLongPtr (hWnd, GWL_USERDATA));
if (window)
{
HWND rParent = GetParent(window->window);
SetCapture(window->parent);
//SendMessage(window->parent, uMsg, wParam, lParam);
}
}
break;
Everything works with one of them. But it doesn't for the other.
I would appreciate if there is anything you could suggest.
Based on Adrian McCarthy, but actually works for me (though only when the parent owns the child window, otherwise the window will catch the mouse again):
case WM_NCHITTEST: return HTTRANSPARENT;
HTNOWHERE just caused that the LoadCursor() for the window wasn't shown anymore.
These values seem to be possible:
#ifndef NONCMESSAGES
/*
* WM_NCHITTEST and MOUSEHOOKSTRUCT Mouse Position Codes
*/
#define HTERROR (-2)
#define HTTRANSPARENT (-1)
#define HTNOWHERE 0
#define HTCLIENT 1
#define HTCAPTION 2
#define HTSYSMENU 3
#define HTGROWBOX 4
#define HTSIZE HTGROWBOX
#define HTMENU 5
#define HTHSCROLL 6
#define HTVSCROLL 7
#define HTMINBUTTON 8
#define HTMAXBUTTON 9
#define HTLEFT 10
#define HTRIGHT 11
#define HTTOP 12
#define HTTOPLEFT 13
#define HTTOPRIGHT 14
#define HTBOTTOM 15
#define HTBOTTOMLEFT 16
#define HTBOTTOMRIGHT 17
#define HTBORDER 18
#define HTREDUCE HTMINBUTTON
#define HTZOOM HTMAXBUTTON
#define HTSIZEFIRST HTLEFT
#define HTSIZELAST HTBOTTOMRIGHT
#if(WINVER >= 0x0400)
#define HTOBJECT 19
#define HTCLOSE 20
#define HTHELP 21
#endif /* WINVER >= 0x0400 */
/*
* SendMessageTimeout values
*/
#define SMTO_NORMAL 0x0000
#define SMTO_BLOCK 0x0001
#define SMTO_ABORTIFHUNG 0x0002
#if(WINVER >= 0x0500)
#define SMTO_NOTIMEOUTIFNOTHUNG 0x0008
#endif /* WINVER >= 0x0500 */
#if(WINVER >= 0x0600)
#define SMTO_ERRORONEXIT 0x0020
#endif /* WINVER >= 0x0600 */
#if(WINVER >= 0x0602)
#endif /* WINVER >= 0x0602 */
#endif /* !NONCMESSAGES */

ffmpeg exit status -1094995529

I'm developing an application that makes calls to ffprobe that return the unorthodox exit status of -1094995529 for certain files when on Windows. This exit status is given consistently, and there is some minor discussion of this.
Why is this value given, and where is it documented? Can I expect this status to be different on a unix machine where the allowed exit statuses are more constrained?
Error codes from ffmpeg (error.h from avutil) :
http://ffmpeg.org/doxygen/trunk/error_8h_source.html
It turns out the value you specified is :
#define AVERROR_INVALIDDATA FFERRTAG( 'I','N','D','A')
The -1094995529 becomes -0x41444E49 and when you look at those letters, in ACSII, 0x41 = 'A', 0x44 = 'D', 0x4E = 'N, and 0x49 = 'I'. Due to the macro/etc things are reversed, so ADNI becomes INDA, which you can see from the #define snippet, is the AVERROR_INVALIDDATA defined FFERRTAG( 'I','N','D','A').
The rest of the error codes are in that file and I've pasted them below here :
#define AVERROR_BSF_NOT_FOUND FFERRTAG(0xF8,'B','S','F') ///< Bitstream filter not found
#define AVERROR_BUG FFERRTAG( 'B','U','G','!') ///< Internal bug, also see AVERROR_BUG2
#define AVERROR_BUFFER_TOO_SMALL FFERRTAG( 'B','U','F','S') ///< Buffer too small
#define AVERROR_DECODER_NOT_FOUND FFERRTAG(0xF8,'D','E','C') ///< Decoder not found
#define AVERROR_DEMUXER_NOT_FOUND FFERRTAG(0xF8,'D','E','M') ///< Demuxer not found
#define AVERROR_ENCODER_NOT_FOUND FFERRTAG(0xF8,'E','N','C') ///< Encoder not found
#define AVERROR_EOF FFERRTAG( 'E','O','F',' ') ///< End of file
#define AVERROR_EXIT FFERRTAG( 'E','X','I','T') ///< Immediate exit was requested; the called function should not be restarted
#define AVERROR_EXTERNAL FFERRTAG( 'E','X','T',' ') ///< Generic error in an external library
#define AVERROR_FILTER_NOT_FOUND FFERRTAG(0xF8,'F','I','L') ///< Filter not found
#define AVERROR_INVALIDDATA FFERRTAG( 'I','N','D','A') ///< Invalid data found when processing input
#define AVERROR_MUXER_NOT_FOUND FFERRTAG(0xF8,'M','U','X') ///< Muxer not found
#define AVERROR_OPTION_NOT_FOUND FFERRTAG(0xF8,'O','P','T') ///< Option not found
#define AVERROR_PATCHWELCOME FFERRTAG( 'P','A','W','E') ///< Not yet implemented in FFmpeg, patches welcome
#define AVERROR_PROTOCOL_NOT_FOUND FFERRTAG(0xF8,'P','R','O') ///< Protocol not found
#define AVERROR_STREAM_NOT_FOUND FFERRTAG(0xF8,'S','T','R') ///< Stream not found
#define AVERROR_BUG2 FFERRTAG( 'B','U','G',' ')
#define AVERROR_UNKNOWN FFERRTAG( 'U','N','K','N') ///< Unknown error, typically from an external library
#define AVERROR_EXPERIMENTAL (-0x2bb2afa8) ///< Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it.
#define AVERROR_INPUT_CHANGED (-0x636e6701) ///< Input changed between calls. Reconfiguration is required. (can be OR-ed with AVERROR_OUTPUT_CHANGED)
#define AVERROR_OUTPUT_CHANGED (-0x636e6702) ///< Output changed between calls. Reconfiguration is required. (can be OR-ed with AVERROR_INPUT_CHANGED)
#define AVERROR_HTTP_BAD_REQUEST FFERRTAG(0xF8,'4','0','0')
#define AVERROR_HTTP_UNAUTHORIZED FFERRTAG(0xF8,'4','0','1')
#define AVERROR_HTTP_FORBIDDEN FFERRTAG(0xF8,'4','0','3')
#define AVERROR_HTTP_NOT_FOUND FFERRTAG(0xF8,'4','0','4')
#define AVERROR_HTTP_OTHER_4XX FFERRTAG(0xF8,'4','X','X')
#define AVERROR_HTTP_SERVER_ERROR FFERRTAG(0xF8,'5','X','X')

Resources