Леонид
Я переписал мой код так:
// (C) Copyright 2002-2005 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
//-----------------------------------------------------------------------------
//----- acrxEntryPoint.h
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
//#include "excel_defs.h"
#define USE_PROGID 1
#define USE_LIBID 0
//
// Delete the *.tlh files when changing import qualifiers
//
#if USE_PROGID
#import "progid:Excel.Sheet" auto_search auto_rename rename_search_namespace("Office10")
#elif USE_LIBID
#import "libid:{00020813-0000-0000-C000-000000000046}" auto_search auto_rename version(1.3) lcid(0) no_search_namespace
#else
#pragma message ("Make sure the path to excel.exe is correct")
#import "C:\Program Files\Microsoft Office\OFFICE11\excel.exe" auto_search auto_rename dual_interfaces
#endif
void dump_com_error(_com_error &e)
{
_tprintf(_T("Oops - hit an error!\n"));
_tprintf(_T("\a\tCode = %08lx\n"), e.Error());
_tprintf(_T("\a\tCode meaning = %s\n"), e.ErrorMessage());
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
_tprintf(_T("\a\tSource = %s\n"), (LPCTSTR) bstrSource);
_tprintf(_T("\a\tDescription = %s\n"), (LPCTSTR) bstrDescription);
}
// If this is placed in the scope of the smart pointers, they must be
// explicitly Release(d) before CoUninitialize() is called. If any reference
// count is non-zero, a protection fault will occur.
struct StartOle {
StartOle() { CoInitialize(NULL); }
~StartOle() { CoUninitialize(); }
} _inst_StartOle;
//-----------------------------------------------------------------------------
#define szRDS _RXST("")
//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class COrCAD2App : public AcRxArxApp {
public:
COrCAD2App () : AcRxArxApp () {}
virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
// TODO: Load dependencies here
// You *must* call On_kInitAppMsg here
AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;
// TODO: Add your initialization code here
return (retCode) ;
}
virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
// TODO: Add your code here
// You *must* call On_kUnloadAppMsg here
AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;
// TODO: Unload dependencies here
return (retCode) ;
}
virtual void RegisterServerComponents () {
}
// - OrCAD2.LDATA command (do not rename)
static void OrCAD2LDATA(void)
{
/**
CApplication app;
CDialogs dlgs;
CDialog0 dlg;
if(!app.CreateDispatch("Excel.Application")) //запустити сервер
{
AfxMessageBox("Помилка при старт? Excel!");;
return;
}
else
app.put_Visible(TRUE); //? зробити його видимим**/
//dlgs = app.get_Dialogs();
//dlg = dlgs.get_Item(long(32));
//dlg.Show;
using namespace Excel;
_ApplicationPtr pXL;
try {
pXL.CreateInstance(L"Excel.Application");
pXL->Visible[0] = VARIANT_TRUE;
WorkbooksPtr pBooks = pXL->Workbooks;
_WorkbookPtr pBook = pBooks->Add((long)xlWorksheet);
_WorksheetPtr pSheet = pXL->ActiveSheet;
try {
// This one will fail; it is done on purpose to demonstrate the error.
pSheet->Name = "Market Share?";
} catch (_com_error &e) {
dump_com_error(e);
}
pSheet->Name = "Market Share!";
// When using parameterized properties, optional args must be explicitly dealt with.
pSheet->Range["A2"][vtMissing]->Value2 = "Company A";
pSheet->Range["B2"][vtMissing]->Value2 = "Company B";
pSheet->Range["C2"][vtMissing]->Value2 = "Company C";
pSheet->Range["D2"][vtMissing]->Value2 = "Company D";
// Of course, you can call a parameterized property as a method and then optional args are implicit.
pSheet->GetRange("A3")->Value2 = 75.0;
pSheet->GetRange("B3")->Value2 = 14.0;
pSheet->GetRange("C3")->Value2 = 7.0;
pSheet->GetRange("D3")->Value2 = 4.0;
Sleep(1000);
RangePtr pRange = pSheet->Range["A2:D3"][vtMissing];
_ChartPtr pChart = pBook->Charts->Add();
pChart->ChartWizard((Range*) pRange, (long) xl3DPie, 7L, (long) xlRows,
1L, 0L, 2L, "Market Share");
Sleep(6000);
pBook->Saved[0] = VARIANT_TRUE;
pXL->Quit();
} catch(_com_error &e) {
dump_com_error(e);
}
}
// - OrCAD2.SDATA command (do not rename)
static void OrCAD2SDATA(void)
{
// Add your code for command OrCAD2.SDATA here
}
} ;
//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(COrCAD2App)
ACED_ARXCOMMAND_ENTRY_AUTO(COrCAD2App, OrCAD2, LDATA, LDATA, ACRX_CMD_TRANSPARENT, NULL)
ACED_ARXCOMMAND_ENTRY_AUTO(COrCAD2App, OrCAD2, SDATA, SDATA, ACRX_CMD_TRANSPARENT, NULL)
Когда же я запустил и ввел в AutoCAD мою команду LDATA, то на экране появился Excel и в нем выводились данные и график. Потом Excel самопроизвольно закрылся а AutoCAD снова повис (А чтоб он был здоровым!!!)