getmodulefilename

How do I GetModuleFileName() if I only have a window handle (hWnd)?

I'm trying to get the name of the executable of a window that is outside my C# 2.0 application. My app currently gets a window handle (hWnd) using the GetForegroundWindow() call from "user32.dll". From the digging that I've been able to do, I think I want to use the GetModuleFileNameEx() function (from PSAPI) to obtain the name, but Get...

How can I calculate the complete buffer size for GetModuleFileName?

The GetModuleFileName() takes a buffer and size of buffer as input; however its return value can only tell us how many characters is has copied, and if the size is not enough (ERROR_INSUFFICIENT_BUFFER). How do I determine the real required buffer size to hold entire file name for GetModuleFileName()? Most people use MAX_PATH but I rem...