I am new to C++ so please be gentle. So i created a small C++ script which will be a part of a larger program. It creates an invisible IE and navigates to home. While that part is done, it always creates a console window when it finishes execution and then in less than a second it vanishes. What do i need to change in order to make the program work in a way that the console window won't open ?
I have tried the following code in Visual Studio and it compiles correctly. I have created a new project using windows desktop wizard.
#include "StdAfx.h"
using namespace ATL;
using namespace std;
void ThrowIfFailed(HRESULT hr)
{
if (FAILED(hr))
throw CAtlException(hr);
}
int main()
{
::CoInitialize(nullptr);
try
{
CComPtr<IWebBrowser2> pWebBrowser;
HRESULT hr = ::CoCreateInstance(CLSID_InternetExplorer, nullptr, CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&pWebBrowser));
ThrowIfFailed(hr);
hr = pWebBrowser->put_Visible(VARIANT_FALSE);
ThrowIfFailed(hr);
hr = pWebBrowser->GoHome();
ThrowIfFailed(hr);
CComPtr<IDispatch> pDispatch;
hr = pWebBrowser->get_Document(&pDispatch);
ThrowIfFailed(hr);
}
catch (const CAtlException& e)
{
}
::CoUninitialize();
return 0;
}
This is able to create an invisible IE window which shows up in Task manager. It compiles properly and doesn't have any errors. However, it does also show a black console window. I dont want that to show. Please help. Thanks.
Aucun commentaire:
Enregistrer un commentaire