I don't understand the issue you are having.
You can rename the function to whatever you like. Here is an example (with a few corrections to other portions of code)
#include "stdafx.h"
#include <stdio.h>
#include <wchar.h>
#include <windows.h>
#include <exdisp.h>
#include <string>
#pragma warning(disable: 4192)
#pragma warning(disable: 4146)
#import <mshtml.tlb>
#import <shdocvw.dll>
void PrintBrowserInfo(IWebBrowser2 *pBrowser) {
BSTR bstr;
pBrowser->get_LocationURL(&bstr);
std::wstring wsURL;
wsURL = bstr;
size_t DSlashLoc = wsURL.find(L"//www."); if (DSlashLoc != wsURL.npos) {
wsURL.erase(wsURL.begin(), wsURL.begin() + DSlashLoc + 6);
}
DSlashLoc = wsURL.find(L"/");
if (DSlashLoc != wsURL.npos)
wsURL.erase(DSlashLoc);
wprintf(L" URL: %s\n\n", wsURL.c_str());
SysFreeString(bstr);
}
void EnumExplorers() {
CoInitialize(NULL);
SHDocVw::IShellWindowsPtr spSHWinds;
IDispatchPtr spDisp;
if (spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)) == S_OK) {
long nCount = spSHWinds->GetCount();
for (long i = 0; i < nCount; i++) {
_variant_t va(i, VT_I4);
spDisp = spSHWinds->Item(va);
SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);
if (spBrowser != NULL) {
PrintBrowserInfo((IWebBrowser2 *)spBrowser.GetInterfacePtr());
spBrowser.Release();
}
}
} else {
puts("Shell windows failed to initialise");
}
}
Just call
EnumExplorers();
from anywhere and it will work. If you need to call it from another .cpp file, just create a new header file with
#pragma once
void EnumExplorers();
And include that file as normal.