winapi

How to distinguish a Win32 socket handle from other pipe handles?

I need to determine whether a handle that my code did not create, for which GetFileType()==FILE_TYPE_PIPE, is a socket or not. There does not seem to be an API for this. I have tried the following. The general idea is to use a socket-specific function and treat failure as meaning non-socket. getsockopt() -- This was my first attempt. ...

Is there a way to set the environment path programatically in C++ on Windows?

Is there a way to set the global windows path environment variable programatically (C++)? As far as I can see, putenv sets it only for the current application. Changing directly in the registry (HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment) is also an option though I would prefer API methods if there are? ...

Why does wgluseFontBitmaps consume too much memory on some computers?

I'm creating a game in OpenGL which loads the entire Arial Unicode MS font when it loads. The program uses on avg. 10 megs of memory on my computer (op sys is WinXP SP2) and runs without problems, but when I move the program to my laptop (with Vista) the wglUseFontBitmaps hangs and allocates memory fluently and never returns. This proble...

Recompiling a simple Win32 C++ app for x64

I have a small C++ program for Win32, which has the following WinMain: int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) when trying to compile for x64, I get the following error: error LNK2019: unresolved external...

Win32API function to join directories ?

Does the Win32 API have a function for joining two paths? I can't find it, so I thought I'd ask before rolling my own. ...

How can I bring a window to the foreground in Vista using C++?

I have a piece of code that brings the window under the cursor to the foreground using the SetForegroundWindow API for WinXP. I have been testing it for Vista but the API seems to no longer do the job correctly. AllowSetForeground did not help, my process is a background process. What can I use to accomplish this? ...

Sound processing: Should I use DirectSound or directly Win32 APIs?

I'm making an application where I will: Record from the microphone and do some realtime processing on the input Play an MP3 file (a regular song), but manipulating the output in realtime Every now and then I'll need to play additional sounds over this song too, but I guess I can do that by simply adding the buffers. In short, I need ...

Alternative to system() and _popen() on Windows

This is related to: http://stackoverflow.com/questions/309491/how-do-i-read-the-results-of-a-system-call-in-c I am trying to do the exact the same thing only that my program needs to pass 'multiple parameters with spaces' to the command. I need the command line output and the exit code from the process. Example: An example with Textpad...

How can I change a main menu First level caption?

I have a main menu in an MDI parent form, and it as a main menu. Now I need to change the first level caption of my first menu item in runtime. How can I do that? --- Update --- Sorry. I forgot to tell you that the mainMenu is housed in a TcontrolBar. I think that is the problem because all answer so far don’t work. I had tried all tha...

Exporting functions from a DLL with dllexport

I'd like a simple example of exporting a function from a C++ windows DLL. I'd like to see the header, the cpp file, and the def file (if absolutely required). I'd like the exported name to be undecorated. I'd like to use the most standard calling convention (stdcall?). I'd like the use **__declspec(dllexport) and not have to use a DEF ...

How to get a window handle to a COM Single-Threaded Apartment (STA)?

CoInitialize(NULL) creates an STA by creating a hidden window. How to get an HWND handle for this window? Function EnumThreadWindows does not work, in an example I tried: ... CoInitialize(NULL); EnumThreadWindows(GetCurrentThreadId(), EnumThreadWndProc, 0); ... BOOL CALLBACK EnumThreadWndProc(HWND hwnd, LPARAM lParam) { m_hwnd =...

WinAPI - how to draw dotted line?

I create HPEN using WinAPI GDI method: HPEN hPen = CreatePen(PS_DOT, 1, color); Then draw line using the methods MoveToEx and LineTo. In fact drawn line is dashed. 3 pixels empty, 3 pixels with color -- dashed line. Why PS_DOT style doesn't draw dotted line? How to draw dotten line using WinAPI? ...

How to build a C++ Dll wrapper that catches all exceptions?

Like the title says, we’re looking for a way to catch all exceptions from a piece of C++ code, and wrap this in a dll. This way we can shield of the application that uses this dll, from any errors occurring in this dll. However, this does not seem possible with C++ under Windows. Example: void function() { try { ...

Create GUI from Windows Service with a Network Log on

I have been reading a lot about executing a GUI application from a Windows Service. The "Allow service to interact with desktop" check box worked for me when the Service runs as the SYSTEM user (I am using Windows XP). Now I need the Service to run as a User defined in a domain (from the network). Everything works fine (even if no user i...

What is wrong with my WINAPI call to handle long file paths?

I've been trying to figure out the best way to copy files in Windows with deep paths (files, not folders so robocopy is out of the question). The best solution I've been able to come up with is writing my own solution. I've been able to write the code to handle listing directories with 10,000 character deeps paths but using the same ap...

Why do I get this ERROR_NO_TOKEN when I call WINAPI's CopyFile on deep paths?

This is a follow up to my previous question. After taking the solution to the previous question, I got an error code (1008: ERROR_NO_TOKEN) when copying a file with a 1300 character path. After googling and reading msdn, this doesn't seem to be a solid solution to this problem. The error seems to be tied to thread and process privileg...

How to exit SW quickly

I have a SW which reside in external HDD, it will run automatically when user plug external HDD, of course, the SW have to close automatically when user unplug the external HDD. I can receive the device lost message, however my SW will not be respond druing releasing all objects, if I call exit(0) directly, the SW will show a crash messa...

Switching Printer Trays

I know this question has been asked before, but there was no clear answer. How do I change the printer tray programmatically? I am trying to use python to batch print some PDFs. I need to print different pages from different trays. The printer is a Ricoh 2232C. Is there a way to do it through and Acrobat Reader command line parame...

Why does StackWalk64 return always true?

I tried to make my program dump and save its stack trace when crashes. I installed my own win32 SE handler with _set_se_translator and tried to dump the stack trace with StackWalk64 and finally throw a C++ exception (which actually does the logging when caught). The code looks like this: ... _set_se_handlers(WIN32EXCEPTION::Win32Except...

UC(User component) concept in Win32/.NET Win forms.

Couple of year ago I when to work for company as web developer. It has my first Sirius web development job, (ASPx/C#) so it has very exciting and I learned a lot about that world, from the developer point of view. In that group we had a concept for the pages where loaded in the page UC’s (User controls), I don’t know if it’s the same in...