winapi

C library vs WinApi

Hi, Many of the standard c library (fwrite, memset, malloc) functions have direct equivalents in the windows API (WriteFile, FillMemory/ ZeroMemory, GlobalAlloc). Apart from portability issues, what should be used, the CLIB or windows API functions? Will the C functions call the winapi functions or is it the other way around? thanks...

Is there a way to find all the functions exposed by a dll

I've been searching for a way to get all the strings that map to function names in a dll. I mean by this all the strings for which you can call GetProcAddress. If you do a hex dump of a dll the symbols (strings) are there but I figure there must me a system call to acquire those names. ...

How to open a "nul" file?

I need to create a new process with redirected standard error stream to some file. The code from which child process is being created has no console available, so there are cases when GetStdHandle(any) will return 0. Child process will try to duplicate all of its standard IO handles for some reason (source code for child process is unava...

Monitor a process's network usage?

Is there a way in C# or C/C++ & Win32 to monitor a certain process's network usage (Without that application being built by you obviously)? I would like to monitor just 1 process for like an hour or so, then return the bytes used by only that process, such as limewire for example. Is it possible? I know netstat -e on windows will tell y...

Virtual allocation granularity and page size

Howdy folks, What are the typical values of the virtual allocation granularity and page size on Win64 platforms? That'd be SYSTEM_INFO's dwAllocationGranularity and dwPageSize. On Win32 systems these would be 64k and 4k. I need to know because I've designed a custom allocator based on VirtualAlloc for a Win32 application and wonder if...

Gently kill a process

I have a Windows service(C#), that sprawns few child native processes (C++). I'd like to gently kill those processes once in a while. (gently = let the procs to finalize its work before going down). I tried to use the SetConsoleCtrlHandler() routine to register the child procs to console events and to call the CloseMainWindow() from t...

How can Windows API calls to an application/service be monitored?

My company is looking at implementing a new VPN solution, but require that the connection be maintained programatically by our software. The VPN solution consists of a background service that seems to manage the physical connection and a command line/GUI utilty that initiates the request to connect/disconnect. I am looking for a way to "...

Reading Command Line Arguments of Another Process (Win32 C code)

I need to be able to list the command line arguments (if any) passed to other running processes. I have the PIDs already of the running processes on the system, so basically I need to determine the arguments passed to process with given PID XXX. I'm working on a core piece of a Python module for managing processes. The code is written ...

Why would recv fail when the requested buffer size is greater than the amount of data available?

Underlying the TCP transport stack are a number of buffer limits sometimes documented by their authors. On WinXP SP3 I've run into one of these, I think, and can't figure out why. I have implemented a simple client to get data from a server (written by a colleague in Java). The protocol is to write the length of the data (in network o...

How to get the bigger icon

I CAN get the associated icon just fine, and draw it accordingly, however, I want to extract the FULL Icon information not just the 32x32 (or the 16x16) pixels that the SHGetFileInfo allows. For instance, I might want to display the 128x128 icon (or even 256x256) that is stored in the icon file inside the executable. And I can only acco...

Replacing a Window Class all across Windows

I need to replace one of the pre-defined window classes all across Windows. For example, I would like to replace the "EDIT" class so that my own custom edit box is used whenever any Windows program calls CreateWindowEx with "EDIT" as the class name argument. How can I achieve this? Will a message hook help? I believe a message hook woul...

Does unblocking connect to socket cause a context switch?

I'm using winsock and calling connect on a non-blocking socket. I occasionally see some delay (up to 200ms) before the function returns when the CPU is hogged by other processes. From what I know, a connect on a non-blocking socket should return immediately, but perhaps connect causes a context switch and since the CPU is working hard it...

Hook windows logon/logoff events

I am having a service which would be running at SYSTEM level. Now, i want to track the logged on user in it. Earlier i was trying to get the logged in user name from GetUserName api but in my case it returns "SYSTEM" every time. Is there anyway to get logged on username in my case? or is there any hook that i can install so that i may ...

How to know whether we are in a console or a windowed app?

Context : programming a c/c++ win32-mfc library How to know whether we are in a console or a windowed app? ...

Cross-thread exception throwing

I have an application that allows users to write their own code in a language of our own making that's somewhat like C++. We're getting problems, however, where sometimes our users will accidentally write an infinite loop into their script. Once the script gets into the infinite loop, the only way they can get out is to shut the applicat...

How to check if a file can be created inside given directory on MS XP/Vista?

I have a code that creates file(s) in user-specified directory. User can point to a directory in which he can't create files, but he can rename it. I have created directory for test purposes, let's call it C:\foo. I have following permissions to C:\foo: Traversing directory/Execute file Removing subfolders and files Removing Re...

Can the DllMain of an .exe be called?

Hi, My question is not exactly the same as this one (it's not theoretical, there is only a main thread without message loop, InitInstance and ExitInstance are no fitting calls). I'm using a console app without message loop; this app loads an exe with the LoadLibrary function, so that it can use its exported functions. Bad news: the Dll...

What is the equivalent to Posix popen() in the Win32 API?

Is there a rough equivalent to the Linux/Unix stdio.h popen() function in the Win32 API? If so, where can I find it? Edit: I need to know this to patch an omission in the D standard library. Any answer must use only standard Win32 API, no MSVC-specific functions. Also, I'd prefer something that's not horribly low-level, if it exists...

Is there a TRACE statement for basic win32 C++?

In MFC C++ (Visual Studio 6) I am used to using the TRACE macro for debugging. Is there an equivalent statement for plain win32? ...

win32 SDK child window paint (C/C++)

I'm using the win32 Platform SDK (on XP Pro) to create an app consisting a single main window with a number of child windows. The styles passed to CreateWindow are WS_OVERLAPPEDWINDOW | WS_VISIBLE (for the main window) and WS_CHILDWINDOW | WS_VISIBLE for the children. The error I'm seeing is that when another application is dragged on ...