0

Obviously I can't terminate a given process, when its main window is hidden ("minimized to tray"). So I tried showing the window again in the other processes' FormClosing handler. Didn't work either.

Now I want to use ShowWindow

IntPtr Handle = Gateway->MainWindowHandle;
ShowWindow((HWND)Handle.ToPointer(), SW_SHOWDEFAULT);

which unfortunately yields

error LNK2028: Nicht aufgelöstes Token (0A000072) ""extern "C" int __stdcall ShowWindow(struct HWND__ *,int)" (?ShowWindow@@$$J18YGHPAUHWND__@@H@Z)", auf das in Funktion ""private: void __clrcall lidarctrl::Form1::Form1_FormClosing(class System::Object ^,class System::Windows::Forms::FormClosingEventArgs ^)" (?Form1_FormClosing@Form1@lidarctrl@@$$FA$AAMXP$AAVObject@System@@P$AAVFormClosingEventArgs@Forms@Windows@4@@Z)" verwiesen wird.
error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" int __stdcall ShowWindow(struct HWND__ *,int)" (?ShowWindow@@$$J18YGHPAUHWND__@@H@Z)" in Funktion ""private: void __clrcall lidarctrl::Form1::Form1_FormClosing(class System::Object ^,class System::Windows::Forms::FormClosingEventArgs ^)" (?Form1_FormClosing@Form1@lidarctrl@@$$FA$AAMXP$AAVObject@System@@P$AAVFormClosingEventArgs@Forms@Windows@4@@Z)".

Sorry - German errors; don't know how to change the compiler's locale.

Non resolved Token...in function...referenced by...

Reference to non-resolved extern symbol...in function...

I appreciate any hints on which header to include, library to load.

I am using Microsoft Visual C++ 2010 Express; the project is a plain Windows Forms Application.

Thank you!

  • 1
    You can terminate a process with a hidden/minimized/whatsoever window. Perhaps you need to start from explaining what prevents you from doing so. – Roman R. Oct 16 '12 at 11:33
  • Agree with Roman; just send a `WM_CLOSE` message to the hidden application. – MSalters Oct 16 '12 at 11:46
  • I am using `GetProcessesByName` to get my other process (_gateway_). `Gateway->CloseMainWindow(); Gateway->WaitForExit(100);` kills it only when the main window is visible. Otherwise, the other process just keeps running. – Paul Wilhelm Oct 16 '12 at 11:49
  • @MSalters, `SendMessage((HWND)Handle.ToPointer(), WM_CLOSE, 0, 0);` yields the same error message as above (replace ShowWindow with SendMessage). – Paul Wilhelm Oct 16 '12 at 11:52
  • @PaulWilhelm: You have linked error, which means you just cannot get all together into your app. Which is not C++ in first place as it seems, still the API you are about to use is native Win32. This takes yuur question into actually different space that APIs do work, and there are many way to deliver the close request to the app, however you just need to start from being able to build your code... – Roman R. Oct 16 '12 at 12:08
  • What did you do with the Linker + Input + Additional Dependencies setting? – Hans Passant Oct 16 '12 at 12:56
  • Everything's set to default. Any advice on how I _should_ change any of these settings? – Paul Wilhelm Oct 16 '12 at 13:02

2 Answers2

1

In a project created from standard Windows Forms Application template, there are no standard/default libraries linked that are normally included on native projects. And you need to add them explicitly, in project settings or in code. Where you include <windows.h>, add #pragma as shown below:

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#pragma comment(lib, "user32.lib") // <<--- Add Me

This will link your missing ShowWindow.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
0

You're probably not using C++ and Win32. Then you would write

#include <windows.h>
//...
{
  //...
  HWND Handle = Gateway->MainWindowHandle; // Gateway probably is your class.
  ShowWindow(Handle, SW_SHOWDEFAULT);
}
MSalters
  • 173,980
  • 10
  • 155
  • 350
  • Like I said, this is a Microsoft Visual C++ 2010 Express Windows Forms Application-project. If I'm not mistaken, that should be C++/CLI. (Still a C++ noob.) So ShowWindow is a Win32 function; the questions is how to use it in my project, which is not vanilla Win32. – Paul Wilhelm Oct 16 '12 at 11:56