Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <objbase.h>
- /* Compile using:
- * cl.exe /MD main.cpp /link /out:Test1.exe kernel32.lib user32.lib advapi32.lib ole32.lib
- */
- int main(int argc, char** argv) {
- HRESULT hr = CoInitializeEx(NULL, 0);
- if (FAILED(hr)) {
- fprintf(stderr, "Unable to initialize COM (HRESULT = 0x%X)\n", hr);
- return -1;
- }
- /* Will FAILED if you don't have Microsoft Excel installed */
- GUID guid;
- hr = CLSIDFromProgID(L"Excel.Application", &guid);
- if (FAILED(hr)) {
- fprintf(stderr, "Could not get Excel.Application CLSID\nMaybe you don't have Excel installation\nHRESULT = 0x%X\n", hr);
- CoUninitialize();
- return 0;
- }
- IDispatch *pDisp = NULL;
- if (FAILED(hr = CoCreateInstance(guid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (void**)&pDisp))) {
- fprintf(stderr, "CoCreateInstance() FAILED (HRESULT = 0x%X)\n", hr);
- CoUninitialize();
- return -1;
- }
- fprintf(stdout, "Got Microsoft Excel Application instance as IDispatch ( 0x%p )\n", pDisp);
- pDisp->Release();
- CoUninitialize();
- fprintf(stdout, "operations completed...\n");
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement