Click here to Skip to main content
15,891,706 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Delphi
uses Windows, SysUtils, Variants, Forms, ComObj, OleServer, WordXP;
 
...
...
...
 
 
 
function GetPowerPointText(fName:String): String;
var
  PP, PRE, SLI: OleVariant;
  i, j: Integer;

begin
  Result:='';
 

 try
    PP:=CreateOleObject('PowerPoint.Application');
  except
    MessageBox(0,'PowerPoint not Install.','Error',MB_OK);
    Exit;
  end;
 
  // 읽어올 파일이 있는지 체크
 if not FileExists(fName) then begin
    MessageBox(0,'파일이 없습니다.','Error',MB_OK);
    Exit;
 end;
 
 // 생성한 파워포인트 어플리케이션에서 파일을 읽음 = 프리젠테이션을 Open
  PRE:=PP.Presentations.Open(fName,False,True,False);
 
  
 for i:=1to PRE.Slides.Count do begin
    SLI:=PRE.Slides.Item(i);
 
   for j:=1to SLI.Shapes.Count do begin

      if (SLI.Shapes.Item(j).HasTextFrame) then
        Result:=Result+#13#10+SLI.Shapes.Item(j).TextFrame.TextRange.Text;
      Application.ProcessMessages;
    end; // for j
  end; // for i
 
 
  SLI:=Unassigned;
  PRE:=Unassigned;
  PP.Quit;
  PP:=Unassigned;
end;
Posted
Updated 24-Apr-12 23:42pm
v2
Comments
OriginalGriff 25-Apr-12 5:42am    
And your question is?
You seem to have forgotten to post that bit...
Use the "Improve question" widget to edit your question and provide better information.
qudghkwjd 25-Apr-12 5:46am    
sorry
qudghkwjd 25-Apr-12 5:54am    
i 'want change c++ code..
Jochen Arndt 25-Apr-12 5:43am    
Added code formatting and Delphi tag.
Griff has already asked for the question.

Do you want to translate the Delphi function into a C++ function? Delphi's compiler hides lots of tedious details and makes Automation easier. You will need to write hundreds of lines to achieve the same functionality using C++ with COM and plain APIs.

You may want to look into the example from Microsoft first.CppAutomatePowerPoint[^]. Also, you might be interested in http://msdn.microsoft.com/en-us/library/aa155776(v=office.10).aspx[^]. This one is old but it's still worth reading.

I just rewrote the first part of your codes. But it should help you grab the idea a bit.
C++
CoInitialize(NULL);

//------------PP:=CreateOleObject('PowerPoint.Application');-------

CLSID ClassID;
CLSIDFromProgID(TEXT("PowerPoint.Application"), &ClassID);

IUnknown *pUnk;
HRESULT hr = CoCreateInstance(ClassID, NULL, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**)&pUnk);
if (hr != S_OK)
	return 0;

IDispatch *pDisp;
hr = pUnk->QueryInterface(IID_IDispatch, (void**)&pDisp);
if (hr != S_OK)
{
	pUnk->Release();
	return 0;
}

//------------PRE:=PP.Presentations.Open(fName,False,True,False);
//Get Presentations first
OLECHAR* szPresentations = OLESTR("Presentations");
DISPID dispid_Presentations;
hr = pDisp->GetIDsOfNames(IID_NULL, &szPresentations, 1, LOCALE_USER_DEFAULT, &dispid_Presentations);
if (hr != S_OK)
{
	pDisp->Release();
	pUnk->Release();
	return 0;
}

DISPPARAMS dpNoArgs = {NULL, NULL, 0, 0};
VARIANT vResult;
IDispatch *pDispPresentations;
hr = pDisp->Invoke(dispid_Presentations, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &dpNoArgs, &vResult, NULL, NULL);
if (hr != S_OK)
{
	pDisp->Release();
	pUnk->Release();
	return 0;
}
pDispPresentations = vResult.pdispVal;

//Open the file 
VARIANT vArgsOpen[4];
for (int i = 0; i < 4; ++i)
{
	VariantInit(vArgsOpen+i);
}
vArgsOpen[0].vt = VT_BSTR;
vArgsOpen[0].bstrVal = SysAllocString(L"I need to go out for lunch.ppt");;
vArgsOpen[1].vt = VT_BOOL;
vArgsOpen[1].boolVal = FALSE;
vArgsOpen[2].vt = VT_BOOL;
vArgsOpen[2].boolVal = TRUE;
vArgsOpen[3].vt = VT_BOOL;
vArgsOpen[3].boolVal = FALSE;

DISPPARAMS dpOpen;
dpOpen.cArgs = 4;
dpOpen.cNamedArgs = 0;
dpOpen.rgvarg = vArgsOpen;

IDispatch *pDispPresentation;
OLECHAR* szOpen = OLESTR("Open");
DISPID dispid_Open;
hr = pDispPresentations->GetIDsOfNames(IID_NULL, &szOpen, 1, LOCALE_USER_DEFAULT, &dispid_Open);
if (hr != S_OK)
{
	pDisp->Release();
	pUnk->Release();
	pDispPresentations->Release();
	return 0;
}
hr = pDispPresentations->Invoke(dispid_Open, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dpOpen, &vResult, NULL, NULL);
SysFreeString(vArgsOpen[0].bstrVal);
if (hr != S_OK)
{
	pDisp->Release();
	pUnk->Release();
	pDispPresentations->Release();
	return 0;
}
pDispPresentation = vResult.pdispVal;

pDispPresentation->Release();
pDisp->Release();
pUnk->Release();
pDispPresentations->Release();

CoUninitialize();
return 1;		
 
Share this answer
 
Comments
Aescleal 28-Apr-12 15:55pm    
I gave you a three 'cause while I understand what you're up to in that code but perhaps you might like to use a modicum of abstraction (i.e. functions that describe what they're up to) rather than pile it into one stream of consciousness code.

As an example you could simplify about half your code with a decent COM pointer class. Imagine all those ->releases you could save by spending time either writing one or actually using one out of the box.
smags13 29-Apr-12 23:48pm    
Yes, I agree with you. That's why I asked him if it is necessary to use plain COM and API functions which is hard to write and read the codes. I thought it would be better to use plain functions of interfaces so that he would grab the idea of automation better and quicker, as he might be new to COM and Automation.

I should have pointed out that the codes is just illusion of who to use IDispatch and other interface and therefore how to automate, but it's not for any kinds of real development cases.
You could try using the class wizard in Microsoft Dev Studio to wrap the control in a C++ class. It handles the details fairly well, and will give you a shortcut to implementation.

It works fine in many cases.
 
Share this answer
 
Comments
smags13 28-Apr-12 3:12am    
Do you mean using MFC?
JackDingler 29-Apr-12 12:57pm    
Dev Studio has a class wizard that will generate code for controls.

The change this up between versions, but one way they all have in common is that if you add a custom control to a dialog, it will give you a picker and let you browse for the ole control. Then it will generate the class wrappers for you. You don't have to actually use it in a dialog though. The point is to activate the class wizard.
smags13 29-Apr-12 23:55pm    
Thanks, Jack. I suppose deploying MFC/ATL distributable along with the resulting executable is required, correct?
JackDingler 30-Apr-12 11:08am    
That could well be the case. You are wrapping the control in a COM+ interface.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900