Excel automation in C++

Pages: 12
Could some please share a working example of C++ code which performs the following:

- connects to running Excel if any, otherwise throws an exception,
- connects to current worksheet, otherwise throws an exception,
- read at least one cell from connected worksheet if any.

I hope someone did things like that before and would kindly share the code. Example should use C++ only, while Excel should be any 2003/2007/2010. Any approach can be used COM, OLE, MSAA.
Thank you.

(PS: pray, please do not refer to some link or say something like "google is your friend", I already browse a lot and found no appropriate example)
Last edited on
Sorry, but I must point it out: Googling the exact title of this thread yields a Microsoft-provided link as second result that shows C++ code that starts MS Excel (any installed version), adds a workbook and fills some cells in the active sheet. What have you been googling before???
To "webJose",
you absolutely right, but watch carefully what you wrote "result that shows C++ code that starts MS Excel" while I do not need to start any Excel Instance, I need to connect to existing one if any, otherwise throw exception and pass by.
On the other hand if MS example is giving to you a source which can be easily reworked to what I need I would greatly appreciate if you show me how.
Well, you'll hardly find an exact example of what you want, exactly, right? The code presented there is quite suitable to your needs. If you had googled correctly, your question today would have been "I have this C++ sample code from MS that creates a new instance of Excel, but I need to connect to an existing one". Then you would have received the answer: Use GetActiveObject() (http://msdn.microsoft.com/en-us/library/windows/desktop/ms221467(v=vs.85).aspx ) to retrieve the running instance from the ROT (Running Object Table). Note that this function may not return you the one you need if there is more than one Excel process running, in which case you'll probably have to enumerate the ROT. Google for "enumerating the ROT" for more information.

See? A lot of difference there.

Now, in order to accomplish what you want you need to know what properties and methods the Excel objects expose. Do you know them? If not I guess you can use OleView (comes with Visual Studio or the Windows SDK) to examine Excel's type library, or your can use some other tool that can read type libraries. Or you are welcome to explore the MSDN library (http://msdn.microsoft.com/library ). The ActiveSheet property will give you the current worksheet, hopefully. Remember that Excel sheets are not necessarily WORKsheets; they could be graphic sheets, for example.

But assuming ActiveSheet works just dandy for you, you just obtain the Range object of the cell you want to read (the MS sample uses the Range property so you have sample code to retrieve a range object), and then you obtain its value using the Value property. The MS sample uses this property to set values, so you must use DISPATCH_PROPERTYGET instead.
webJose,
it looks pretty simple all you say, but still I can't compile a sample from those resources. Unfortunately I have a very poor experience of Windows programming, thus all these COM and OLE looks weird to me.
I would appreciate a code snippet I could start learning from, at least something which captures Excel currently running and gets it's ActiveSheet. (Let's simplify here and say that we have one Excel window with one workbook and one worksheet which is active)
Thank you.
If you do go the GetActiveObject route, be aware that Excel can be a bit dozy when it comes to registering itself in the Running Object Table:
"GetObject or GetActiveObject cannot find a running Office application"
http://support.microsoft.com/kb/238610

And only the first instance of the Excel app registers itself in the ROT, as the moniker for Excel is always the same.

How To Attach to a Running Instance of an Office Application
http://support.microsoft.com/kb/238975

But Office apps also register their documents in the ROT, so you can enumerate them, instead.
Last edited on
Even though the example is quite good to show how to perform Automation, it has a serious problem: It incorrectly uses the Windows API function macro names with ANSI strings. It then omits the fact that you need to #include <cstdio> for the sprintf() function. Other than that, it compiles fine.

More explicitly: Because of the serious problem, you must compile the project forcing an ANSI build. If you are using Visual Studio from Microsoft, all projects default to Unicode and not ANSI. Either change that in the project properties or #undef UNICODE and #undef _UNICODE. After this and #including <cstdio>, the program compiles.

To be even more explicit:

1. Create a new empty C++ project of type console.
2. Add a new source file. Call it main.cpp.
3. #undef _UNICODE and UNICODE or change the project settings.
4. #include <ole2.h> as instructed by the MS code.
5. #include <cstdio>
6. Copy the AutoWrap() function.
7. Add the int main() function.
8. Copy the other code inside main().
9. Compile.

After that, study the Excel object model in order to understand the different properties and methods, and then exchange the call to CoCreateInstance() with a call to GetActiveObject(). At this point you can use the Excel object given by this function to enumerate the Workbooks collection to find the one you look for, or you can just obtain the active workbook via the ActiveWorkbook property.

Now you have a workbook. Either enumerate the Sheets collection (or there might be a Worksheets collection that holds only sheets of type worksheet, which is better) and settle for one of the worksheets, or use the ActiveSheet property on the workbook object to get the active sheet. Finally obtain the range you want by modifying the MS-provided sample code.

I understand that all these might look weird, but alas, that's how it is. This is how Automation looks like in C++.

BTW, other higher-level languages provide nice wrappers for Automation. You could do what you want to do very easily with a simple VB script! In VBScript you could do what you need in under 20 lines.
Hello
WebJose, I assume you apply to the following link as an example: http://support.microsoft.com/kb/216686/en-us?fr=1
I also used the way provided by Andywesteken: http://support.microsoft.com/kb/238975
And here is a code snippet I'd like to question about:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int main(void)
{
   CoInitialize(NULL);

   CLSID clsid;
   HRESULT hr = CLSIDFromProgID(L"Excel.Application", &clsid);
   if(FAILED(hr)) {
      return -1;
   }

   IUnknown *pUnk = NULL;
   hr = GetActiveObject(clsid, NULL, (IUnknown**)&pUnk);
   if(FAILED(hr)) {
      return -2;
   }
   ...


What I can't understand is how GetActiveObject can return "Success" is I do not have Excel currently running?

I never used VB or VBScript. Also I suspect that in other language this task could be easier and intuitively understandable. However I have a strong restriction to use C++ only.
Last edited on
Look for Excel.exe in Task Manager. It is there.
Yes.
Sure it was there in the Processes. I killed Excel and code began to FAIL, which is correct.
Well now it becomes more and more clear for me. Thank you.
I will try to proceed from here and post additional questions if any into this topic.
Last edited on
I believe its a property of the "Application" object in Excel to set 'Visible' to either true or false. That's also another reason you are getting an S_OK return and not seeing anything. Try setting the visible property to true and it should become visible as soon as you run your code, same as if you started it with a shortcut or double clicked on the exe

As WebJose said, other languages have built in COM implementations that make everything a lot easier with COM. I've always used PowerBASIC in the Excel work I do, and it only takes a few lines of code to start Excel (there is an option to start a new instance, or use an already running instance if one can be found) , make it visible, create worksheets or iterate through them, read/write cells, etc.

One thing about Excel - I think it can only be run through what is termed in COM the IDispatch interface. I have it on good authority that one can't successfully make direct VTable interface calls on it. When I get a chance I'd like to check that out for myself and verify it. Direct interface calls on object methods through a VTable are much faster than the IDispatch late binding technique. However, the difference is considerably less on out of process servers, which is what Excel is.
I just checked the Excel type library using OleView and indeed all interfaces a dispinterfaces, meaning no VTable access as freddie1 stated. Oddly enough, MS Word's type library does declare dual interfaces, meaning VTable access.
Yea, I've seen posts about that too over in the PowerBASIC forums (about the direct interface calls with Word). That was a new feature of the PowerBASIC compiler a couple versions ago. Before that it just did dispinterface calls. I'd like to update some of my programs at work to use the direct VTable calls when I get a chance.

You seem to be a COM guy too WebJose. You might be interested in something I'm working on right now. I've nearly finished a Type Lib Browser tool that creates the interface header files necessary to connect to a COM component. In fact, I'm typing this post in a Code::Blocks created program that hosts the "Shell.Explorer" object, i.e., Internet Explorer in ieframe.dll. I created an instance of it in a window and navigated to this site. Here is my auto-generated IWebBrowser interface...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
interface IWebBrowser : IDispatch
{
 virtual HRESULT __stdcall GoBack(void)=0;
 virtual HRESULT __stdcall GoForward(void)=0;
 virtual HRESULT __stdcall GoHome(void)=0;
 virtual HRESULT __stdcall GoSearch(void)=0;
 virtual HRESULT __stdcall Navigate(BSTR URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers)=0;
 virtual HRESULT __stdcall Refresh(void)=0;
 virtual HRESULT __stdcall Refresh2(VARIANT* Level)=0;
 virtual HRESULT __stdcall Stop(void)=0;
 virtual HRESULT __stdcall GetApplication(IDispatch** ppDisp)=0;
 virtual HRESULT __stdcall GetParent(IDispatch** ppDisp)=0;
 virtual HRESULT __stdcall GetContainer(IDispatch** ppDisp)=0;
 virtual HRESULT __stdcall GetDocument(IDispatch** ppDisp)=0;
 virtual HRESULT __stdcall GetTopLevelContainer(VARIANT_BOOL* pBool)=0;
 virtual HRESULT __stdcall GetType(BSTR* Type)=0;
 virtual HRESULT __stdcall GetLeft(LONG* pl)=0;
 virtual HRESULT __stdcall SetLeft(LONG pl)=0;
 virtual HRESULT __stdcall GetTop(LONG* pl)=0;
 virtual HRESULT __stdcall SetTop(LONG pl)=0;
 virtual HRESULT __stdcall GetWidth(LONG* pl)=0;
 virtual HRESULT __stdcall SetWidth(LONG pl)=0;
 virtual HRESULT __stdcall GetHeight(LONG* pl)=0;
 virtual HRESULT __stdcall SetHeight(LONG pl)=0;
 virtual HRESULT __stdcall GetLocationName(BSTR* LocationName)=0;
 virtual HRESULT __stdcall GetLocationURL(BSTR* LocationURL)=0;
 virtual HRESULT __stdcall GetBusy(VARIANT_BOOL* pBool)=0;
};


I'm pretty excited about it. I'll post the code when I get it ready. My program is 9728 bytes only!!!!
Last edited on
Looks very interesting, freedie, but you say it generates header files. I guess for unmanaged C++, right? If so shouldn't that be a class? Looks more like a hybrid between IDL and C++.
Its pure, unmanaged, Win32 C++. Objbase.h defines the word 'interface' to be a struct. So, this...

1
2
3
4
5
6
interface IWebBrowser : IDispatch
{
 ...
 ...
 virtual HRESULT __stdcall Navigate(BSTR URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers)=0;


...is really this...

1
2
3
4
struct IWebBrowser : IDispatch
{
  ....
  virtual HRESULT __stdcall Navigate(BSTR URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers)=0;


The 'class' keyword would work equally as well as struct or interface, however, then it would be necessary to clutter up the declarations with the 'public' keyword (I think).

So the ediface above simply defines for the client of ieframe.dll (Internet Explorer) a block of memory of a size of 128 bytes (25 X 4 + 7 X 4, i.e., IWebBrowser has 25 methods, and IDispatch 7), because there are 27 virtual functions.

Clicking a button to auto-generate a proper header is a million times easier than converting an OleView Idl dump to compilable C++.

Last edited on
Ah, I see. I was unaware about the interface keyword being defined like that, plus I was unaware that the keyword "public" was not needed for structs.

So yes, I like the idea a lot. What I wouldn't mind having too is of course the GUID's for coclasses and interfaces, enumerations and other data types. I also hope that the tool can properly show inheritance of other interfaces? Like IWebBrowser2 inheriting from IWebBrowser.
Yes, I have to code that yet about adding the GUIDs to the interface header. Of course, they're accessable from the type library and just need to be read. Tell you what, here is my 9216 byte Web Browser (I'm using it now to post) I just created. IWebBrowser.h is the auto-generated file...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//Main.h
#ifndef Main_h
#define Main_h

#define dim(x) (sizeof(x) / sizeof(x[0]))
typedef HRESULT (__stdcall* PFNATLAXWININIT)(void);
typedef HRESULT (__stdcall* PFNATLAXCREATECONTROL)(LPCOLESTR lpszName, HWND hWnd, IStream* pStream, IUnknown** ppUnkContainer);
typedef HRESULT (__stdcall* PFNATLAXGETCONTROL)(HWND hContainer, IUnknown** ppIUnknown);

typedef struct WindowsEventArguments
{
 HWND                         hWnd;
 WPARAM                       wParam;
 LPARAM                       lParam;
 HINSTANCE                    hIns;
}WndEventArgs, *lpWndEventArgs;

long fnWndProc_OnCreate       (lpWndEventArgs Wea);
long fnWndProc_OnCommand      (lpWndEventArgs Wea);
long fnWndProc_OnDestroy      (lpWndEventArgs Wea);

struct EVENTHANDLER
{
 unsigned int                 iMsg;
 long                         (*fnPtr)(lpWndEventArgs);
};

const EVENTHANDLER EventHandler[]=
{
 {WM_CREATE,                  fnWndProc_OnCreate},
 {WM_COMMAND,                 fnWndProc_OnCommand},
 {WM_DESTROY,                 fnWndProc_OnDestroy}
};

#define ID_CONTAINER          1250
#define BTN_NAVIGATE          1255
#define ID_URL                1265

#endif


continued...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#define  UNICODE                                              //Main.cpp - Web Browser Demo
#define  _UNICODE
#include <windows.h>
#include <tchar.h>
#include <cstdio>
#include "Main.h"
#include "IWebBrowser.h"
const IID IID_WebExplorer  = {0xEAB22AC1,0x30C1,0x11CF,{0xA7,0xEB,0x00,0x00,0xC0,0x5B,0xAE,0x0B}};
HINSTANCE hAtlIns          = NULL;


struct StartOLEProcess                                        // The reason this strange thing - 'StartOLEProcess' is here is that in testing this
{                                                             // thing with Windows 2000/XP I was getting crashes at program termination, i.e., 'x'ing
 StartOLEProcess()                                            // out to end program, caused presumably by either CoUninitialize() or FreeLibrary() not
 {                                                            // synchronizing well with this process's termination code.  So note here that an
  TCHAR szBuffer[256];                                        // instance of StartOLEProcess named 'InitializeOLE' will be created before WinMain()
  CoInitialize(NULL);                                         // even starts, and its destructor will be called after WinMain() exits.  I put the
  GetCurrentDirectory(256,szBuffer);                          // CoInitialize(), LoadLibrary(), CoUninitialize(), and FreeLibrary() calls in this
  _tcscat(szBuffer,_T("\\Atl90.dll"));                        // object's Constructor and Destructor calls, and that seemed to solve the problem.  One
  hAtlIns=LoadLibrary(szBuffer);                              // does what one must, I suppose!
 }

 ~StartOLEProcess()
 {
  CoUninitialize();
  if(hAtlIns)
     FreeLibrary(hAtlIns);
 }
}InitializeOLE;


long fnWndProc_OnCreate(lpWndEventArgs Wea)
{
 PFNATLAXCREATECONTROL pAtlCreateControl=NULL;
 PFNATLAXGETCONTROL pAtlAxGetControl=NULL;
 PFNATLAXWININIT pAtlAxWinInit=NULL;
 IUnknown* ppUnkContainer=NULL;
 IWebBrowser* pWebBrowser=NULL;
 IUnknown* pUnkIExplorer=NULL;
 HWND hCtrl,hContainer;
 BSTR strProgId;
 HRESULT hr;

 Wea->hIns=((LPCREATESTRUCT)Wea->lParam)->hInstance;
 hContainer=CreateWindow(_T("static"),_T(""),WS_CHILD|WS_VISIBLE,0,35,1180,750,Wea->hWnd,(HMENU)ID_CONTAINER,Wea->hIns,0);
 if(hAtlIns)
 {
    pAtlAxWinInit=(PFNATLAXWININIT)GetProcAddress(hAtlIns,"AtlAxWinInit");
    if(pAtlAxWinInit)
    {
       hr=pAtlAxWinInit();
       if(SUCCEEDED(hr))
       {
          pAtlCreateControl=(PFNATLAXCREATECONTROL)GetProcAddress(hAtlIns,"AtlAxCreateControl");
          if(pAtlCreateControl)
          {
             strProgId=SysAllocString(_T("Shell.Explorer"));
             hr=pAtlCreateControl(strProgId,hContainer,NULL,&ppUnkContainer);
             if(SUCCEEDED(hr))
             {
                SetWindowLong(Wea->hWnd,0,(long)ppUnkContainer);
                pAtlAxGetControl=(PFNATLAXGETCONTROL)GetProcAddress(hAtlIns,"AtlAxGetControl");
                if(pAtlAxGetControl)
                {
                   hr=pAtlAxGetControl(hContainer,&pUnkIExplorer);
                   if(SUCCEEDED(hr))
                   {
                      SetWindowLong(Wea->hWnd,4,(long)pUnkIExplorer);
                      hr=pUnkIExplorer->QueryInterface(IID_WebExplorer,(void**)&pWebBrowser);
                      if(SUCCEEDED(hr))
                         SetWindowLong(Wea->hWnd,8,(long)pWebBrowser);
                      else
                         return 0;
                      hCtrl=CreateWindowEx(WS_EX_CLIENTEDGE,_T("edit"),_T(""),WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL,5,5,1000,25,Wea->hWnd,(HMENU)ID_URL,Wea->hIns,0);
                      hCtrl=CreateWindow(_T("button"),_T("Navigate"),WS_CHILD|WS_VISIBLE,1050,5,80,25,Wea->hWnd,(HMENU)BTN_NAVIGATE,Wea->hIns,0);
                   }
                }
             }
          }
       }
    }
 }

 return 0;
}


long fnWndProc_OnCommand(lpWndEventArgs Wea)
{
 if(LOWORD(Wea->wParam)==BTN_NAVIGATE)
 {
    TCHAR szBuffer[256];
    HWND hEdit=GetDlgItem(Wea->hWnd,ID_URL);
    GetWindowText(hEdit,szBuffer,256);
    IWebBrowser* pWebBrowser=NULL;
    pWebBrowser=(IWebBrowser*)GetWindowLong(Wea->hWnd,8);
    BSTR strUrl;
    strUrl=SysAllocString(szBuffer);
    if(pWebBrowser)
       pWebBrowser->Navigate(strUrl,NULL,NULL,NULL,NULL);
    SysFreeString(strUrl);
 }

 return 0;
}


long fnWndProc_OnDestroy(lpWndEventArgs Wea)
{
 IUnknown* pUnkIExplorer=NULL;
 IUnknown* ppUnkContainer=NULL;
 IWebBrowser* pWebBrowser=NULL;

 pWebBrowser=(IWebBrowser*)GetWindowLong(Wea->hWnd,8);
 if(pWebBrowser)
    pWebBrowser->Release();
 pUnkIExplorer=(IUnknown*)GetWindowLong(Wea->hWnd,4);
 if(pUnkIExplorer)
    pUnkIExplorer->Release();
 ppUnkContainer=(IUnknown*)GetWindowLong(Wea->hWnd,0);
 if(ppUnkContainer)
    ppUnkContainer->Release();
 PostQuitMessage(0);

 return 0;
}


LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{

 WndEventArgs Wea;

 for(unsigned int i=0; i<dim(EventHandler); i++)
 {
     if(EventHandler[i].iMsg==msg)
     {
        Wea.hWnd=hwnd, Wea.lParam=lParam, Wea.wParam=wParam;
        return (*EventHandler[i].fnPtr)(&Wea);
     }
 }

 return (DefWindowProc(hwnd, msg, wParam, lParam));
}


int WINAPI WinMain(HINSTANCE hIns, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
 TCHAR szClassName[]=_T("Form1");
 WNDCLASSEX wc;
 MSG messages;
 HWND hWnd;

 wc.lpszClassName=szClassName;                wc.lpfnWndProc=fnWndProc;
 wc.cbSize=sizeof (WNDCLASSEX);               wc.style=CS_DBLCLKS;
 wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);     wc.hInstance=hIns;
 wc.hIconSm=LoadIcon(NULL, IDI_APPLICATION);  wc.hCursor=LoadCursor(NULL,IDC_ARROW);
 wc.hbrBackground=(HBRUSH)COLOR_BTNSHADOW;    wc.cbWndExtra=12;
 wc.lpszMenuName=NULL;                        wc.cbClsExtra=0;
 RegisterClassEx(&wc);
 hWnd=CreateWindowEx(0,szClassName,szClassName,WS_OVERLAPPEDWINDOW,100,15,1200,830,HWND_DESKTOP,0,hIns,0);
 ShowWindow(hWnd,iShow);
 while(GetMessage(&messages,NULL,0,0))
 {
    TranslateMessage(&messages);
    DispatchMessage(&messages);
 }

 return messages.wParam;
}
I'll probably have to break this up...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#ifndef SHDocVw_h
#define SHDocVw_h

typedef interface IWebBrowser IWebBrowser;
typedef interface DWebBrowserEvents DWebBrowserEvents;
typedef interface IWebBrowserApp IWebBrowserApp;
typedef interface IWebBrowser2 IWebBrowser2;
typedef interface DWebBrowserEvents2 DWebBrowserEvents2;
typedef interface DShellWindowsEvents DShellWindowsEvents;
typedef interface IShellWindows IShellWindows;
typedef interface IShellUIHelper IShellUIHelper;
typedef interface IShellUIHelper2 IShellUIHelper2;
typedef interface IShellUIHelper3 IShellUIHelper3;
typedef interface DShellNameSpaceEvents DShellNameSpaceEvents;
typedef interface IShellFavoritesNameSpace IShellFavoritesNameSpace;
typedef interface IShellNameSpace IShellNameSpace;
typedef interface IScriptErrorList IScriptErrorList;


typedef enum CommandStateChangeConstants
{
 CSC_UPDATECOMMANDS              = -1,
 CSC_NAVIGATEFORWARD             = 1,
 CSC_NAVIGATEBACK                = 2
}CommandStateChangeConstants;


typedef enum OLECMDID
{
 OLECMDID_OPEN                   = 1,
 OLECMDID_NEW                    = 2,
 OLECMDID_SAVE                   = 3,
 OLECMDID_SAVEAS                 = 4,
 OLECMDID_SAVECOPYAS             = 5,
 OLECMDID_PRINT                  = 6,
 OLECMDID_PRINTPREVIEW           = 7,
 OLECMDID_PAGESETUP              = 8,
 OLECMDID_SPELL                  = 9,
 OLECMDID_PROPERTIES             = 10,
 OLECMDID_CUT                    = 11,
 OLECMDID_COPY                   = 12,
 OLECMDID_PASTE                  = 13,
 OLECMDID_PASTESPECIAL           = 14,
 OLECMDID_UNDO                   = 15,
 OLECMDID_REDO                   = 16,
 OLECMDID_SELECTALL              = 17,
 OLECMDID_CLEARSELECTION         = 18,
 OLECMDID_ZOOM                   = 19,
 OLECMDID_GETZOOMRANGE           = 20,
 OLECMDID_UPDATECOMMANDS         = 21,
 OLECMDID_REFRESH                = 22,
 OLECMDID_STOP                   = 23,
 OLECMDID_HIDETOOLBARS           = 24,
 OLECMDID_SETPROGRESSMAX         = 25,
 OLECMDID_SETPROGRESSPOS         = 26,
 OLECMDID_SETPROGRESSTEXT        = 27,
 OLECMDID_SETTITLE               = 28,
 OLECMDID_SETDOWNLOADSTATE       = 29,
 OLECMDID_STOPDOWNLOAD           = 30,
 OLECMDID_ONTOOLBARACTIVATED     = 31,
 OLECMDID_FIND                   = 32,
 OLECMDID_DELETE                 = 33,
 OLECMDID_HTTPEQUIV              = 34,
 OLECMDID_HTTPEQUIV_DONE         = 35,
 OLECMDID_ENABLE_INTERACTION     = 36,
 OLECMDID_ONUNLOAD               = 37,
 OLECMDID_PROPERTYBAG2           = 38,
 OLECMDID_PREREFRESH             = 39,
 OLECMDID_SHOWSCRIPTERROR        = 40,
 OLECMDID_SHOWMESSAGE            = 41,
 OLECMDID_SHOWFIND               = 42,
 OLECMDID_SHOWPAGESETUP          = 43,
 OLECMDID_SHOWPRINT              = 44,
 OLECMDID_CLOSE                  = 45,
 OLECMDID_ALLOWUILESSSAVEAS      = 46,
 OLECMDID_DONTDOWNLOADCSS        = 47,
 OLECMDID_UPDATEPAGESTATUS       = 48,
 OLECMDID_PRINT2                 = 49,
 OLECMDID_PRINTPREVIEW2          = 50,
 OLECMDID_SETPRINTTEMPLATE       = 51,
 OLECMDID_GETPRINTTEMPLATE       = 52,
 OLECMDID_PAGEACTIONBLOCKED      = 55,
 OLECMDID_PAGEACTIONUIQUERY      = 56,
 OLECMDID_FOCUSVIEWCONTROLS      = 57,
 OLECMDID_FOCUSVIEWCONTROLSQUERY = 58,
 OLECMDID_SHOWPAGEACTIONMENU     = 59,
 OLECMDID_ADDTRAVELENTRY         = 60,
 OLECMDID_UPDATETRAVELENTRY      = 61,
 OLECMDID_UPDATEBACKFORWARDSTATE = 62,
 OLECMDID_OPTICAL_ZOOM           = 63,
 OLECMDID_OPTICAL_GETZOOMRANGE   = 64,
 OLECMDID_WINDOWSTATECHANGED     = 65,
 OLECMDID_ACTIVEXINSTALLSCOPE    = 66,
 OLECMDID_UPDATETRAVELENTRY_DATARECOVERY= 67
}OLECMDID;


typedef enum OLECMDF
{
 OLECMDF_SUPPORTED               = 1,
 OLECMDF_ENABLED                 = 2,
 OLECMDF_LATCHED                 = 4,
 OLECMDF_NINCHED                 = 8,
 OLECMDF_INVISIBLE               = 16,
 OLECMDF_DEFHIDEONCTXTMENU       = 32
}OLECMDF;


typedef enum OLECMDEXECOPT
{
 OLECMDEXECOPT_DODEFAULT         = 0,
 OLECMDEXECOPT_PROMPTUSER        = 1,
 OLECMDEXECOPT_DONTPROMPTUSER    = 2,
 OLECMDEXECOPT_SHOWHELP          = 3
}OLECMDEXECOPT;


typedef enum tagREADYSTATE
{
 READYSTATE_UNINITIALIZED        = 0,
 READYSTATE_LOADING              = 1,
 READYSTATE_LOADED               = 2,
 READYSTATE_INTERACTIVE          = 3,
 READYSTATE_COMPLETE             = 4
}tagREADYSTATE;


typedef enum SecureLockIconConstants
{
 secureLockIconUnsecure          = 0,
 secureLockIconMixed             = 1,
 secureLockIconSecureUnknownBits = 2,
 secureLockIconSecure40Bit       = 3,
 secureLockIconSecure56Bit       = 4,
 secureLockIconSecureFortezza    = 5,
 secureLockIconSecure128Bit      = 6
}SecureLockIconConstants;


typedef enum NewProcessCauseConstants
{
 ProtectedModeRedirect           = 1
}NewProcessCauseConstants;


typedef enum ShellWindowTypeConstants
{
 SWC_EXPLORER                    = 0,
 SWC_BROWSER                     = 1,
 SWC_3RDPARTY                    = 2,
 SWC_CALLBACK                    = 4,
 SWC_DESKTOP                     = 8
}ShellWindowTypeConstants;


typedef enum ShellWindowFindWindowOptions
{
 SWFO_NEEDDISPATCH               = 1,
 SWFO_INCLUDEPENDING             = 2,
 SWFO_COOKIEPASSED               = 4
}ShellWindowFindWindowOptions;


interface IWebBrowser : IDispatch
{
 virtual HRESULT __stdcall GoBack(void)=0;
 virtual HRESULT __stdcall GoForward(void)=0;
 virtual HRESULT __stdcall GoHome(void)=0;
 virtual HRESULT __stdcall GoSearch(void)=0;
 virtual HRESULT __stdcall Navigate(BSTR URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers)=0;
 virtual HRESULT __stdcall Refresh(void)=0;
 virtual HRESULT __stdcall Refresh2(VARIANT* Level)=0;
 virtual HRESULT __stdcall Stop(void)=0;
 virtual HRESULT __stdcall GetApplication(IDispatch** ppDisp)=0;
 virtual HRESULT __stdcall GetParent(IDispatch** ppDisp)=0;
 virtual HRESULT __stdcall GetContainer(IDispatch** ppDisp)=0;
 virtual HRESULT __stdcall GetDocument(IDispatch** ppDisp)=0;
 virtual HRESULT __stdcall GetTopLevelContainer(VARIANT_BOOL* pBool)=0;
 virtual HRESULT __stdcall GetType(BSTR* Type)=0;
 virtual HRESULT __stdcall GetLeft(LONG* pl)=0;
 virtual HRESULT __stdcall SetLeft(LONG pl)=0;
 virtual HRESULT __stdcall GetTop(LONG* pl)=0;
 virtual HRESULT __stdcall SetTop(LONG pl)=0;
 virtual HRESULT __stdcall GetWidth(LONG* pl)=0;
 virtual HRESULT __stdcall SetWidth(LONG pl)=0;
 virtual HRESULT __stdcall GetHeight(LONG* pl)=0;
 virtual HRESULT __stdcall SetHeight(LONG pl)=0;
 virtual HRESULT __stdcall GetLocationName(BSTR* LocationName)=0;
 virtual HRESULT __stdcall GetLocationURL(BSTR* LocationURL)=0;
 virtual HRESULT __stdcall GetBusy(VARIANT_BOOL* pBool)=0;
};


interface IWebBrowserApp : IWebBrowser
{
 virtual HRESULT __stdcall Quit(void)=0;
 virtual HRESULT __stdcall ClientToWindow(int* pcx, int* pcy)=0;
 virtual HRESULT __stdcall PutProperty(BSTR Property, VARIANT vtValue)=0;
 virtual HRESULT __stdcall GetProperty(BSTR Property, VARIANT* pvtValue)=0;
 virtual HRESULT __stdcall GetName(BSTR* Name)=0;
 virtual HRESULT __stdcall GetHWND(LONG* pHWND)=0;
 virtual HRESULT __stdcall GetFullName(BSTR* FullName)=0;
 virtual HRESULT __stdcall GetPath(BSTR* Path)=0;
 virtual HRESULT __stdcall GetVisible(VARIANT_BOOL* pBool)=0;
 virtual HRESULT __stdcall SetVisible(VARIANT_BOOL pBool)=0;
 virtual HRESULT __stdcall GetStatusBar(VARIANT_BOOL* pBool)=0;
 virtual HRESULT __stdcall SetStatusBar(VARIANT_BOOL pBool)=0;
 virtual HRESULT __stdcall GetStatusText(BSTR* StatusText)=0;
 virtual HRESULT __stdcall SetStatusText(BSTR StatusText)=0;
 virtual HRESULT __stdcall GetToolBar(int* Value)=0;
 virtual HRESULT __stdcall SetToolBar(int Value)=0;
 virtual HRESULT __stdcall GetMenuBar(VARIANT_BOOL* Value)=0;
 virtual HRESULT __stdcall SetMenuBar(VARIANT_BOOL Value)=0;
 virtual HRESULT __stdcall GetFullScreen(VARIANT_BOOL* pbFullScreen)=0;
 virtual HRESULT __stdcall SetFullScreen(VARIANT_BOOL pbFullScreen)=0;
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
interface IWebBrowser2 : IWebBrowserApp
{
 virtual HRESULT __stdcall Navigate2(VARIANT* URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers)=0;
 virtual HRESULT __stdcall QueryStatusWB(OLECMDID cmdID, OLECMDF* pcmdf)=0;
 virtual HRESULT __stdcall ExecWB(OLECMDID cmdID, OLECMDEXECOPT cmdexecopt, VARIANT* pvaIn, VARIANT* pvaOut)=0;
 virtual HRESULT __stdcall ShowBrowserBar(VARIANT* pvaClsid, VARIANT* pvarShow, VARIANT* pvarSize)=0;
 virtual HRESULT __stdcall GetReadyState(tagREADYSTATE* plReadyState)=0;
 virtual HRESULT __stdcall GetOffline(VARIANT_BOOL* pbOffline)=0;
 virtual HRESULT __stdcall SetOffline(VARIANT_BOOL pbOffline)=0;
 virtual HRESULT __stdcall GetSilent(VARIANT_BOOL* pbSilent)=0;
 virtual HRESULT __stdcall SetSilent(VARIANT_BOOL pbSilent)=0;
 virtual HRESULT __stdcall GetRegisterAsBrowser(VARIANT_BOOL* pbRegister)=0;
 virtual HRESULT __stdcall SetRegisterAsBrowser(VARIANT_BOOL pbRegister)=0;
 virtual HRESULT __stdcall GetRegisterAsDropTarget(VARIANT_BOOL* pbRegister)=0;
 virtual HRESULT __stdcall SetRegisterAsDropTarget(VARIANT_BOOL pbRegister)=0;
 virtual HRESULT __stdcall GetTheaterMode(VARIANT_BOOL* pbRegister)=0;
 virtual HRESULT __stdcall SetTheaterMode(VARIANT_BOOL pbRegister)=0;
 virtual HRESULT __stdcall GetAddressBar(VARIANT_BOOL* Value)=0;
 virtual HRESULT __stdcall SetAddressBar(VARIANT_BOOL Value)=0;
 virtual HRESULT __stdcall GetResizable(VARIANT_BOOL* Value)=0;
 virtual HRESULT __stdcall SetResizable(VARIANT_BOOL Value)=0;
};


interface IShellWindows : IDispatch
{
 virtual HRESULT __stdcall GetCount(LONG* Count)=0;
 virtual HRESULT __stdcall Item(VARIANT index, IDispatch** Folder)=0;
 virtual HRESULT __stdcall _NewEnum(IUnknown** ppunk)=0;
 virtual HRESULT __stdcall Register(IDispatch* pid, LONG HWND, int swClass, LONG* plCookie)=0;
 virtual HRESULT __stdcall RegisterPending(LONG lThreadId, VARIANT* pvarloc, VARIANT* pvarlocRoot, int swClass, LONG* plCookie)=0;
 virtual HRESULT __stdcall Revoke(LONG lCookie)=0;
 virtual HRESULT __stdcall OnNavigate(LONG lCookie, VARIANT* pvarloc)=0;
 virtual HRESULT __stdcall OnActivated(LONG lCookie, VARIANT_BOOL fActive)=0;
 virtual HRESULT __stdcall FindWindowSW(VARIANT* pvarloc, VARIANT* pvarlocRoot, int swClass, LONG* pHWND, int swfwOptions, IDispatch** ppdispOut)=0;
 virtual HRESULT __stdcall OnCreated(LONG lCookie, IUnknown* punk)=0;
 virtual HRESULT __stdcall ProcessAttachDetach(VARIANT_BOOL fAttach)=0;
};


interface IShellUIHelper : IDispatch
{
 virtual HRESULT __stdcall ResetFirstBootMode(void)=0;
 virtual HRESULT __stdcall ResetSafeMode(void)=0;
 virtual HRESULT __stdcall RefreshOfflineDesktop(void)=0;
 virtual HRESULT __stdcall AddFavorite(BSTR URL, VARIANT* Title)=0;
 virtual HRESULT __stdcall AddChannel(BSTR URL)=0;
 virtual HRESULT __stdcall AddDesktopComponent(BSTR URL, BSTR Type, VARIANT* Left, VARIANT* Top, VARIANT* Width, VARIANT* Height)=0;
 virtual HRESULT __stdcall IsSubscribed(BSTR URL, VARIANT_BOOL* pBool)=0;
 virtual HRESULT __stdcall NavigateAndFind(BSTR URL, BSTR strQuery, VARIANT* varTargetFrame)=0;
 virtual HRESULT __stdcall ImportExportFavorites(VARIANT_BOOL fImport, BSTR strImpExpPath)=0;
 virtual HRESULT __stdcall AutoCompleteSaveForm(VARIANT* Form)=0;
 virtual HRESULT __stdcall AutoScan(BSTR strSearch, BSTR strFailureUrl, VARIANT* pvarTargetFrame)=0;
 virtual HRESULT __stdcall AutoCompleteAttach(VARIANT* Reserved)=0;
 virtual HRESULT __stdcall ShowBrowserUI(BSTR bstrName, VARIANT* pvarIn, VARIANT* pvarOut)=0;
};


interface IShellUIHelper2 : IShellUIHelper
{
 virtual HRESULT __stdcall AddSearchProvider(BSTR URL)=0;
 virtual HRESULT __stdcall RunOnceShown(void)=0;
 virtual HRESULT __stdcall SkipRunOnce(void)=0;
 virtual HRESULT __stdcall CustomizeSettings(VARIANT_BOOL fSQM, VARIANT_BOOL fPhishing, BSTR bstrLocale)=0;
 virtual HRESULT __stdcall SqmEnabled(VARIANT_BOOL* pfEnabled)=0;
 virtual HRESULT __stdcall PhishingEnabled(VARIANT_BOOL* pfEnabled)=0;
 virtual HRESULT __stdcall BrandImageUri(BSTR* pbstrUri)=0;
 virtual HRESULT __stdcall SkipTabsWelcome(void)=0;
 virtual HRESULT __stdcall DiagnoseConnection(void)=0;
 virtual HRESULT __stdcall CustomizeClearType(VARIANT_BOOL fSet)=0;
 virtual HRESULT __stdcall IsSearchProviderInstalled(BSTR URL, unsigned int* pdwResult)=0;
 virtual HRESULT __stdcall IsSearchMigrated(VARIANT_BOOL* pfMigrated)=0;
 virtual HRESULT __stdcall DefaultSearchProvider(BSTR* pbstrName)=0;
 virtual HRESULT __stdcall RunOnceRequiredSettingsComplete(VARIANT_BOOL fComplete)=0;
 virtual HRESULT __stdcall RunOnceHasShown(VARIANT_BOOL* pfShown)=0;
 virtual HRESULT __stdcall SearchGuideUrl(BSTR* pbstrUrl)=0;
};


interface IShellUIHelper3 : IShellUIHelper2
{
 virtual HRESULT __stdcall AddService(BSTR URL)=0;
 virtual HRESULT __stdcall IsServiceInstalled(BSTR URL, BSTR Verb, unsigned int* pdwResult)=0;
 virtual HRESULT __stdcall InPrivateFilteringEnabled(VARIANT_BOOL* pfEnabled)=0;
 virtual HRESULT __stdcall AddToFavoritesBar(BSTR URL, BSTR Title, VARIANT* Type)=0;
 virtual HRESULT __stdcall BuildNewTabPage(void)=0;
 virtual HRESULT __stdcall SetRecentlyClosedVisible(VARIANT_BOOL fVisible)=0;
 virtual HRESULT __stdcall SetActivitiesVisible(VARIANT_BOOL fVisible)=0;
 virtual HRESULT __stdcall ContentDiscoveryReset(void)=0;
 virtual HRESULT __stdcall IsSuggestedSitesEnabled(VARIANT_BOOL* pfEnabled)=0;
 virtual HRESULT __stdcall EnableSuggestedSites(VARIANT_BOOL fEnable)=0;
 virtual HRESULT __stdcall NavigateToSuggestedSites(BSTR bstrRelativeUrl)=0;
 virtual HRESULT __stdcall ShowTabsHelp(void)=0;
 virtual HRESULT __stdcall ShowInPrivateHelp(void)=0;
};


interface IShellFavoritesNameSpace : IDispatch
{
 virtual HRESULT __stdcall MoveSelectionUp(void)=0;
 virtual HRESULT __stdcall MoveSelectionDown(void)=0;
 virtual HRESULT __stdcall ResetSort(void)=0;
 virtual HRESULT __stdcall NewFolder(void)=0;
 virtual HRESULT __stdcall Synchronize(void)=0;
 virtual HRESULT __stdcall Import(void)=0;
 virtual HRESULT __stdcall Export(void)=0;
 virtual HRESULT __stdcall InvokeContextMenuCommand(BSTR strCommand)=0;
 virtual HRESULT __stdcall MoveSelectionTo(void)=0;
 virtual HRESULT __stdcall GetSubscriptionsEnabled(VARIANT_BOOL* pBool)=0;
 virtual HRESULT __stdcall CreateSubscriptionForSelection(VARIANT_BOOL* pBool)=0;
 virtual HRESULT __stdcall DeleteSubscriptionForSelection(VARIANT_BOOL* pBool)=0;
 virtual HRESULT __stdcall SetRoot(BSTR bstrFullPath)=0;
};
Pages: 12