|
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
ifstream in_fp;
DISPPARAMS dpNoArgs = {NULL, NULL, 0, 0};
VARIANT vResult; OLECHAR FAR* szFunction;
IDispatch* pDispApp;
IDispatch* pDispXlBooks;
DISPID dispid_Books; 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];
MultiByteToWideChar(CP_ACP, 0, szFileName, strlen(szFileName)+1,
wszFileName, sizeof(wszFileName)/sizeof(wszFileName[0]));
bstrFileName = ::SysAllocString(wszFileName);
::CoInitialize(NULL);
CLSID clsid;
CLSIDFromProgID(L"Powerpoint.Application", &clsid);
IUnknown* pUnk;
HRESULT hr = ::CoCreateInstance( clsid, NULL,
CLSCTX_SERVER, IID_IUnknown, (void**) &pUnk);
hr = pUnk->QueryInterface(IID_IDispatch, (void**)&pDispApp);
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;
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();
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; vArgsOpen[3].vt = VT_ERROR;
vArgsOpen[3].scode = DISP_E_PARAMNOTFOUND; vArgsOpen[2].vt = VT_BOOL;
vArgsOpen[2].scode = TRUE; vArgsOpen[1].vt = VT_ERROR;
vArgsOpen[1].scode = DISP_E_PARAMNOTFOUND; vArgsOpen[0].vt = VT_BSTR;
vArgsOpen[0].bstrVal = bstrPassWord;
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))
{
}
else
{
}
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);
::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.
|
|
|
|
|
You should check the HRESULT return value of each function call and break execution upon failure. Then you know which call fails first and you can check the passed parameters.
|
|
|
|
|
its fail when I m trying to "open"
and same this working fine for word and excel files.
|
|
|
|
|
I have not use OLE automation with PowerPoint so far. But the errorQuote: "invalid number of parameters" indicates that the PowerPoint Open() method has other parameters than Excel or Word.
See https://support.microsoft.com/kb/222758/en-us[^] for the Presentations.Open() method.
|
|
|
|
|
please help me or ole automation with powerpoint...
|
|
|
|
|
|
so there is no option to open password protected PPT files in automation?
|
|
|
|
|
Sorry, I don't know. You will need to check the documentation details.
|
|
|
|
|
|
Need to dynamically create a matrix of strings in VC++. Did it in a class fifteen years ago. Now I don't seem to be able to make it work. Hope to produce a simple template class as I once did. I've lost alot of traction in C++ since that grad.class. Thanks in advance for any guidance.
|
|
|
|
|
Well it depends on your definition of a matrix of strings. Do you mean a 2-dimensional array of string ponters or something more complex?
Veni, vidi, abiit domum
|
|
|
|
|
Hey there,
I want to make a MFC app that will capture 6 frames per second from the webcam connected to the PC. And i want to get the frames as imageData, i.e., as bitmap or PNG. The idea is to get these frames/images and then update them live on a web browser, so that it gives a "look and feel" of live video streaming.
I did a sample MFC app that shows webcam stream and then use the capGrabFrame & capFileSaveDIB to save the bmp to disk. This all works fine.
But now rather than saving into disk, i need to get the Image Data, so that i could make changes and update in a browser window.
Also, not sure whether it's possible to get 6 frames per second from the webcam.
Is this possible?
Please guide me with some code.
Thanks in advance.
|
|
|
|
|
It looks like you have gone down the Video For Windows route. You might want to consider stepping up to DirectShow instead. They are both old technologies, but VFW is just too old and annoying to deal with (we were using it on Windows 98).
Whether you will be able to achieve 6 FPS really depends on several factors, primarily if your camera supports that frame rate at your desired resolution.
You should be able to acquire the images as JPEGs or another bitmap format (RGB or YUV), but which formats are available depends completely on your camera.
Take a look at this totally awesome CP article: Realtime Webcam Sudoku Solver[^]
As I recall, it uses Video For Windows, so it should be easy for you to jump into the code and see how to access the image data.
For a DirectShow sample, check out this CP article: Video Preview and Frames Capture to Memory with SampleGrabber in Buffered Mode.[^]
And also browse through his other articles[^], it will not be a waste of your time.
Here are a couple more DirectShow related CP articles:
Simultaneous Previewing & Video Capture using DirectShow[^]
DirectX Video Stream and frame capture[^]
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
my printer is EPSON Stylus Photo R230 Series,IO is usb;
Anyone who has idea on how to retrieve status of printer hopefully can help me find the solution.
code:
HANDLE hPrinter = 0;
DWORD dwNeeded = 0;
PRINTER_INFO_2* pPrinterInfo = (PRINTER_INFO_2 *)malloc(0);
::OpenPrinter("EPSON Stylus Photo R230 Series", &hPrinter, NULL);
if (!::GetPrinter(hPrinter, 2, (LPBYTE)pPrinterInfo, 0, &dwNeeded)){
pPrinterInfo = (PRINTER_INFO_2 *)malloc(dwNeeded);
::GetPrinter(hPrinter, 2, (LPBYTE)pPrinterInfo, dwNeeded, &dwNeeded);
}
::ClosePrinter(hPrinter);
if (pPrinterInfo->Status == PRINTER_STATUS_PAPER_OUT){
free(pPrinterInfo);
return TRUE;
}
else{
free(pPrinterInfo);
return FALSE;
}
|
|
|
|
|
You can't get the actual status without sending a job to the printer. Only when the printer is accessed by the spooler API, the status is updated. You can't even check if the printer is connected and powered this way because OpenPrinter() and GetPrinter() will succeed and set the generic info fields like name and attributes as long as the printer is known.
|
|
|
|
|
Has idea on how to retrieve status of printer hopefully can help me find the solution?
I know application which can't get the IO status by running on ring3,so the status got is always zero.
|
|
|
|
|
Your code can retrieve the status. You may try to access the printer in some way so that the status is updated. But I have not done that and don't know how to do it.
|
|
|
|
|
Hi there. I am trying to use xxxx.lib file and all of it's xxxx.h files in my project. For the xxxx.h files I have set
Properties -> C/C++ -> General -> Additional Include Directories
and for the xxxx.lib files I have set
Properties -> Linker -> Input -> Additional Dependencies Other than these settings, I haven't done anything. So it says that it can not find certain methods and structures. What setting am I missing? Thanks for anything you share.
|
|
|
|
|
This can't be answered definitively without seeing the error messages. But it seems that you forgot to include the xxxx.h header file.
With VC, you can also add all necessary information to your source files without changing the project settings:
#include "[path_to_h]\xxxx.h"
#pragma comment(lib, "[path_to_lib]\\xxxx")
To avoid full paths, the library files can be copied to a subdirectory of your project directory (e.g. with subdirectory xxxx [path_to_lib] becomes .\\xxxx ).
|
|
|
|
|
Actually I am trying to use libavcodec library. As said earlier, I made their paths known to visual studio. I was trying to call function avcodec_find_encoder() but the error is shown. Here is what I am trying AND what I get
AVCodec* codec = avcodec_find_encoder((CodecID)5);
error LNK2019: unresolved external symbol "struct AVCodec * __cdecl avcodec_find_encoder(enum CodecID)" (avcodec_find_encoder@@YAPAUAVCodec@@W4CodecID@@@Z) referenced in function "public: void __thiscall ProjectName::FunctionName(char const *,int)
Apparently it means that it cann't find avcodec.h but both .h and .lib files are there.
|
|
|
|
|
That error is usually sourced by not linking against the module that contains the function (libavcodec in this case). Did you add libavcodec to your project settings (Linker - Input - Additional Dependicies)?
|
|
|
|
|
Jochen Arndt wrote: Did you add libavcodec to your project settings...
Oh yes. I added following line in the project setting ( also mentioned by you )
$(SolutionDir)\bin\lib\libavcodecD.lib;
|
|
|
|
|
To verify that the library is included, you can add the following line to one of your source files:
#pragma comment(lib, ".\\bin\\lib\\libavcodecD")
You may also enable the linker option /VERBOSE:LIB to show the libraries that are searched during the linking process. If the library is listed there, it is included.
If the error still occurs, the called function may be not located in that library (e.g. when there is a typing error). But avcodec_find_encoder() seems to be correct.
|
|
|
|
|
The error is till there.
However, I thank for the time you have spent answering me. One thing that may be of interest to you, I am using the library in a c++ project.
|
|
|
|
|
Where did you get the library from? Or did you build it yourself?
I ask this because a wrong library file is the last possible answer I can give you.
You can check the symbols that are exported by a library with the dumpbin utility:
dumpbin /exports filename
To use dumpbin from a command shell, open the command shell and execute vcvars32.bat which is located in the VC\bin directory of your Visual Studio installation.
|
|
|
|
|