Posts

Showing posts with the label winapi

GetTempPathA returning incorrect user folder

GetTempPathA returning incorrect user folder I need to access the user specific temp folder on windows, which is supposed to be doable with the GetTempPathA() I have something along the lines of: char buff[512]; GetTempPath(500,buff); strcat(buff,"specific_folder_in_temp\file.txt"); FILE f*; f = fopen(buff,"w"); However, instead of returning the expected C:Usersuser.nameAppDataLocalTemp... I'm getting C:UsersUSER~1.NAMAppDataLocalTemp... This results in my code failing. Any tips as to what I might be doing wrong? What does GetTempPathW return? And what is the values of your TMP, TEMP, and USERPROFILE environment variables? (Type set at command prompt to see your env) – selbie Jul 2 at 5:47 set As the environment variables TMP or TEMP may use short path, you cou...

Reading pipe asynchronously using ReadFile

Reading pipe asynchronously using ReadFile I think I need some clarification on how to read from a named pipe and have it return immediately, data or not. What I am seeing is ReadFile fails, as expected, but GetLastError returns either ERROR_IO_PENDING or ERROR_PIPE_NOT_CONNECTED, and it does this until my surrounding code times out. I get these errors EVEN THOUGH THE DATA HAS IN FACT ARRIVED. I know this by checking my read buffer and seeing what I expect. And the pipe keeps working. I suspect I am not using the overlapped structure correctly, I'm just setting all fields to zero. My code looks like this: gPipe = CreateFile(gPipename, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); pMode = PIPE_READMODE_MESSAGE; bret = SetNamedPipeHandleState(gPipe, &pMode, NULL, NULL); OVERLAPPED ol; memset(&ol, 0, sizeof(OVERLAPPED)); // the following inside a loop that times out after a period bret = ReadFile(gPipe, &tmostat, sizeof(TMO64STAT), N...

How to send WM_INPUTLANGCHANGEREQUEST to app with modal window?

How to send WM_INPUTLANGCHANGEREQUEST to app with modal window? I wrote a keyboard switcher, which works well, but fails if current application has modal window opened. On keyboard switch I do the following hwnd = GetForegroundWindow(); PostMessage(hwnd, WM_INPUTLANGCHANGEREQUEST, IntPtr.Zero, handle); where [DllImport("User32.dll", EntryPoint = "PostMessage")] private static extern int PostMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); [DllImport("user32.dll")] static extern IntPtr GetForegroundWindow(); but the language does not change. How would I accomplish this? Adding get root owner improved situation, but didn't help completely. Adding call for GetDesktopWindow didn't help: GetDesktopWindow hwnd = GetDesktopWindow(); InputLangChangeRequest(hwnd, language); hwnd = GetRootOwner(); InputLangChangeRequest(hwnd, language); Code is here https://github.com/dims12/NormalKeyboardSwitcher Possible duplicate o...

C++ std vs Windows “MultiByte”

C++ std vs Windows “MultiByte” [update] The key question here is one of the context. Not the "how" and not "you have this API". Thus: Why would anybody use Windows Multi Byte strings in 2018, in Win10 RS4, namely in an UWP application? For example cppWINRT does it. What is the use-case where inside UWP app, one would transform from wide string to narrow multi byte string, using the WideCharToMultiByte ? Where is the result used and how? WideCharToMultiByte [original question] Results of my research & development "10 Years After" we have C++ 17, we have <codecvt> deprecated and we also have std way of converting between four (4) standard C++ string types: <codecvt> std // std::string std::basic_string<char> std::wstring std::basic_string<wchar_t> std::u16string (C++11) std::basic_string<char16_t> std::u32string (C++11) std::basic_string<char32_t> This is excluding additional four (4) 'n...