Click here to Skip to main content
15,893,368 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Relative path for #include directive - how to specify subdirectory on "down"level Pin
Randor 1-Feb-14 21:20
professional Randor 1-Feb-14 21:20 
GeneralRe: Relative path for #include directive - how to specify subdirectory on "down"level Pin
Vaclav_2-Feb-14 3:50
Vaclav_2-Feb-14 3:50 
GeneralRe: Relative path for #include directive - how to specify subdirectory on "down"level Pin
Richard MacCutchan1-Feb-14 21:24
mveRichard MacCutchan1-Feb-14 21:24 
GeneralSOLVED Re: Relative path for #include directive - how to specify subdirectory on "down"level Pin
Vaclav_3-Feb-14 4:14
Vaclav_3-Feb-14 4:14 
QuestionBuilding UI Automation in C++ for MFC applications?? Pin
Member 1031937631-Jan-14 2:24
Member 1031937631-Jan-14 2:24 
AnswerRe: Building UI Automation in C++ for MFC applications?? Pin
Richard MacCutchan31-Jan-14 2:51
mveRichard MacCutchan31-Jan-14 2:51 
AnswerRe: Building UI Automation in C++ for MFC applications?? Pin
Randor 1-Feb-14 21:28
professional Randor 1-Feb-14 21:28 
QuestionProblem to open ppt file using automation. Pin
Le@rner31-Jan-14 0:43
Le@rner31-Jan-14 0:43 
hi help me to open ppt file using automation.

this working well for excel and word files but ppt files are not open from this.

can u please correct me where I m wrong

C++
//for ppt files

ifstream in_fp;
	DISPPARAMS dpNoArgs = {NULL, NULL, 0, 0};
	VARIANT vResult;	// used to hold variant results
	OLECHAR FAR* szFunction;
	IDispatch* pDispApp;
	IDispatch* pDispXlBooks;
	DISPID dispid_Books; 	//Documents property of application object
	DISPID dispid_Quit;
	BSTR bstrFileName = ::SysAllocString(OLESTR("filename"));
	BSTR bstrPassWord = ::SysAllocString(OLESTR("pass"));
 
	CString error_str=_T("");
	in_fp.open(file_name, ios::in);
	if (!in_fp || file_name.GetLength() > MAX_PATH)
	{
		error_str.Format(_T("error loading %s\n"), file_name);
		AfxMessageBox(error_str);
		return ;
	}
 
	string ss = string(CT2CA(file_name));
 
	const char *szFileName = ss.c_str();
 
	wchar_t wszFileName[MAX_PATH+1];
 
	//convert file name to bstr for use with COM
	MultiByteToWideChar(CP_ACP, 0, szFileName, strlen(szFileName)+1,
			wszFileName, sizeof(wszFileName)/sizeof(wszFileName[0]));
 
	bstrFileName = ::SysAllocString(wszFileName);
	
	// COM work starts here

	//Initialize COM
	::CoInitialize(NULL);
 
 
	//get the CLSID for the Excel Application Object
	CLSID clsid;
 
//for word files 
//use "Word.Application"

//and for excel files
//use "Excel.Application"

	CLSIDFromProgID(L"Powerpoint.Application", &clsid);
 
	//get a pointer to the Objects IUnknown interface and Create
	//an instance of the Excel Application.

	IUnknown* pUnk;
	HRESULT hr = ::CoCreateInstance( clsid, NULL,
			CLSCTX_SERVER, IID_IUnknown, (void**) &pUnk);
 
	
 
	hr = pUnk->QueryInterface(IID_IDispatch, (void**)&pDispApp);
 
	
//for word files 
//use "Documents"

//and for excel files
//use "Workbooks"

	szFunction = OLESTR("Presentations");
	hr = pDispApp->GetIDsOfNames (IID_NULL, &szFunction, 1,
			LOCALE_USER_DEFAULT, &dispid_Books);
 
	hr = pDispApp->Invoke (dispid_Books, IID_NULL,
			LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET,
			&dpNoArgs, &vResult, NULL, NULL);
 
	pDispXlBooks = vResult.pdispVal;
 
	//DISPPARAMS for Open method

	DISPID dispid_Open;
	VARIANT vArgsOpen[5];
	DISPPARAMS dpOpen;
	dpOpen.cArgs = 5;
	dpOpen.cNamedArgs = 0;
	dpOpen.rgvarg = vArgsOpen;
	
	wchar_t wszPassWord[MAX_PATH];
 
	
	ss = string(CT2CA(Password));
 
	const char *pwd_entry = ss.c_str();
 
	//again convert to bstr
	MultiByteToWideChar(CP_ACP, 0, pwd_entry, -1,
			wszPassWord, sizeof(wszPassWord)/sizeof(wszPassWord[0]));
 
	bstrPassWord = ::SysAllocString(wszPassWord);
		
	vArgsOpen[4].vt = VT_BSTR;
	vArgsOpen[4].bstrVal = bstrFileName;		//Filename
	vArgsOpen[3].vt = VT_ERROR;
	vArgsOpen[3].scode = DISP_E_PARAMNOTFOUND;	//Updatelinks - ommitted
	vArgsOpen[2].vt = VT_BOOL;
	vArgsOpen[2].scode = TRUE;					//Open ReadOnly
	vArgsOpen[1].vt = VT_ERROR;
	vArgsOpen[1].scode = DISP_E_PARAMNOTFOUND;  //file format - ommitted
	vArgsOpen[0].vt = VT_BSTR;
	vArgsOpen[0].bstrVal = bstrPassWord;		//the file password;

	//Invoke the Open method
	szFunction = OLESTR("Open");
	hr = pDispXlBooks->GetIDsOfNames(IID_NULL, &szFunction, 1, 
			                            LOCALE_USER_DEFAULT, &dispid_Open);
	hr = pDispXlBooks->Invoke(dispid_Open, IID_NULL, 
			                    LOCALE_USER_DEFAULT, DISPATCH_METHOD, 
								&dpOpen, NULL, NULL, NULL);
	
 
	if (!FAILED(hr)) 
	{
		//file open ok
	}
	else
	{
//its return error "invalid number of parameters"
		//file not open
	}
	
	//Invoke the Quit method

    szFunction = OLESTR("Quit");
    hr = pDispApp->GetIDsOfNames(IID_NULL, &szFunction, 1, 
                                 LOCALE_USER_DEFAULT, &dispid_Quit);
    hr = pDispApp->Invoke (dispid_Quit, IID_NULL, 
                           LOCALE_USER_DEFAULT, DISPATCH_METHOD,
                           &dpNoArgs, NULL, NULL, NULL);
 
	//Clean-up

	::SysFreeString(bstrFileName);
	::SysFreeString(bstrPassWord);
 
	pDispXlBooks->Release();
	pDispApp->Release();
	pUnk->Release();
 
	::CoUninitialize();

its return error "invalid number of parameters"
please help me thanks in advance.

modified 31-Jan-14 7:41am.

SuggestionRe: Problem to open ppt file using automation. Pin
Jochen Arndt31-Jan-14 1:34
professionalJochen Arndt31-Jan-14 1:34 
GeneralRe: Problem to open ppt file using automation. Pin
Le@rner31-Jan-14 1:42
Le@rner31-Jan-14 1:42 
GeneralRe: Problem to open ppt file using automation. Pin
Jochen Arndt31-Jan-14 2:01
professionalJochen Arndt31-Jan-14 2:01 
GeneralRe: Problem to open ppt file using automation. Pin
Le@rner1-Feb-14 1:16
Le@rner1-Feb-14 1:16 
GeneralRe: Problem to open ppt file using automation. Pin
Richard MacCutchan1-Feb-14 2:12
mveRichard MacCutchan1-Feb-14 2:12 
GeneralRe: Problem to open ppt file using automation. Pin
Le@rner20-Feb-14 1:19
Le@rner20-Feb-14 1:19 
GeneralRe: Problem to open ppt file using automation. Pin
Richard MacCutchan20-Feb-14 2:29
mveRichard MacCutchan20-Feb-14 2:29 
GeneralRe: Problem to open ppt file using automation. Pin
Le@rner20-Feb-14 18:36
Le@rner20-Feb-14 18:36 
QuestionVC++ Matrix Pin
Member 171997130-Jan-14 11:38
Member 171997130-Jan-14 11:38 
QuestionRe: VC++ Matrix Pin
Richard MacCutchan31-Jan-14 0:32
mveRichard MacCutchan31-Jan-14 0:32 
QuestionGetting Frames from Webcam Pin
Don Guy29-Jan-14 14:01
Don Guy29-Jan-14 14:01 
AnswerRe: Getting Frames from Webcam Pin
SoMad29-Jan-14 15:16
professionalSoMad29-Jan-14 15:16 
QuestionVc++ Using Getprinter() to get printer status like NoPaper or more,but status always is 0 Pin
hello dearbaby28-Jan-14 2:05
hello dearbaby28-Jan-14 2:05 
AnswerRe: Vc++ Using Getprinter() to get printer status like NoPaper or more,but status always is 0 Pin
Jochen Arndt28-Jan-14 2:57
professionalJochen Arndt28-Jan-14 2:57 
GeneralRe: Vc++ Using Getprinter() to get printer status like NoPaper or more,but status always is 0 Pin
hello dearbaby28-Jan-14 10:01
hello dearbaby28-Jan-14 10:01 
GeneralRe: Vc++ Using Getprinter() to get printer status like NoPaper or more,but status always is 0 Pin
Jochen Arndt28-Jan-14 20:52
professionalJochen Arndt28-Jan-14 20:52 
QuestionUnresolved External Symbols ---- Using .Lib Pin
Django_Untaken27-Jan-14 18:13
Django_Untaken27-Jan-14 18:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.