|
No initialize is needed,
here is the code access the outlook:
void CXPowerUIView::importFromOutlook()
{
_ApplicationPtr pApp;
_ItemsPtr pItems;
MAPIFolderPtr pFolder;
_ContactItemPtr pContact;
HRESULT hr;
try
{
hr=pApp.CreateInstance(__uuidof(Application));
if (FAILED(hr))
{
MessageBox(_T("Unable to instantiate Outlook."),_T("Outlook Error"),MB_OK);
return;
}
...........
}
This are the 2 ways I call it:
direct:
importFromOutlook();
from thread:
outlookHandle = CreateEvent(NULL, FALSE, FALSE, NULL);
outlookImportThread = ys_thread_create(2000, OutlookThreadFunc, NULL);
void* OutlookThreadFunc(void* pParam)
{
pThisView->importFromOutlook();
return NULL;
}
only direct one is working :/
|
|
|
|
|
And what does the HRESULT hr tell you? Just a blindshot here, add this to your thread:
CoInitializeex(NULL, COINIT_MULTITHREADED); at the beginning and CoUninitialize at the end. Like:
void* OutlookThreadFunc(void* pParam)
{
CoInitializeEx(NULL, COINIT_MULTITHREADED);
pThisView->importFromOutlook();
CoUninitialize();
return NULL;
}
That _ApplicationPtr::CreateInstance is probably using COM and as far as i know you have to initialize COM in every thread you intend to use it in.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
|
Hi,
I am working on Excel Automation Project.
using GetActiveobject , getting one instance of Excel.exe. But need to track/access any number of instances which are opened.
Initally I am checking all the processes in task manager, if Excel.exe is running, then I will loop through to get the active Excel object using GetActiveObject.
But only one instance I am able to access. How to track other instance of Excel.exe's.
Regards,
KTTransfer.
|
|
|
|
|
This code by a coder dude called NarVish gets the Windows Handles
from process id of excel instance instances.
BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
DWORD dwThreadId, dwProcessId;
HINSTANCE hInstance;
char String[255];
HANDLE hProcess;
dwThreadId = GetWindowThreadProcessId(hWnd, &dwProcessId);
}
int _tmain(int argc, _TCHAR* argv[])
{
HWND hwnd = (HWND)FindWindow(_T("XLMAIN"), NULL);
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
if( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return 1;
cProcesses = cbNeeded / sizeof(DWORD);
for (i=0; i<cProcesses; i++ )
{
if( aProcesses[i] != 0 )
{
TCHAR szProcessName[MAX_PATH] = _T("<unknown>");
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, aProcesses[i] );
if ( NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if( EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName, sizeof(szProcessName)/sizeof(TCHAR) );
if(_wcsicmp(szProcessName,L"EXCEL.EXE") == 0)
{
cout<< szProcessName << "--" << aProcesses[i] <<endl;
Excel::Window* pWindow = NULL;
pid = aProcesses[i];
EnumWindows( EnumWindowsProc, NULL);
HRESULT hr = AccessibleObjectFromWindow(hwnd, OBJID_NATIVEOM, __uuidof(Excel::Window), (void**)&pWindow);
if (hr == S_OK)
{
}
}
}
}
_tprintf( TEXT("%s (PID: %u)\n"), szProcessName, aProcesses[i] );
CloseHandle( hProcess );
}
}
return 0;
}
|
|
|
|
|
Do you need the COM instances or just the process handles?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
I need COM instance.
Excel::_ApplicationPtr.
|
|
|
|
|
This code might help you. Call get_Application function of the obtained document IDispatch to get its application's IDispatch.
void COffCntrDispCtrl::GetDocDispatch()
{
if(m_pDocDisp != NULL) return;
IBindCtx *pbc;
HRESULT hr = CreateBindCtx(0, &pbc);
if(FAILED(hr)) {
DoErr("CreateBindCtx()", hr);
return;
}
IRunningObjectTable *prot;
hr = pbc->GetRunningObjectTable(&prot);
if(FAILED(hr)) {
DoErr("GetRunningObjectTable()", hr);
pbc->Release();
return;
}
IEnumMoniker *pem;
hr = prot->EnumRunning(&pem);
if(FAILED(hr)) {
DoErr("EnumRunning()", hr);
prot->Release();
pbc->Release();
return;
}
pem->Reset();
ULONG fetched;
IMoniker *pmon;
int n = 0;
while(pem->Next(1, &pmon, &fetched) == S_OK) {
LPOLESTR pName;
pmon->GetDisplayName(pbc, NULL, &pName);
char szName[512];
WideCharToMultiByte(CP_ACP, 0, pName, -1, szName, 512, NULL,
NULL);
if(!strcmp(szName, m_szDocName)) {
DoMsg("Found document in ROT!");
IDispatch *pDisp;
hr = pmon->BindToObject(pbc, NULL, IID_IDispatch, (void
**)&pDisp);
if(!FAILED(hr)) {
m_pDocDisp = pDisp;
sprintf(buf, "Document IDispatch = %08lx",
m_pDocDisp);
DoMsg(buf);
}
else {
DoErr("BindToObject()", hr);
}
}
pmon->Release();
if(m_pDocDisp != NULL) break;
}
pem->Release();
prot->Release();
pbc->Release();
}
void COffCntrDispCtrl::TestDispatch()
{
ASSERT(m_pDocDisp);
COleDispatchDriver doc(m_pDocDisp);
DISPID dispID = 0;
unsigned short *ucPtr = L"Name";
HRESULT hr = m_pDocDisp->GetIDsOfNames(IID_NULL, &ucPtr, 1,
LOCALE_USER_DEFAULT, &dispID);
ASSERT(!FAILED(hr));
CString name;
doc.GetProperty(dispID, VT_BSTR, &name);
AfxMessageBox(
CString("Document name is ") + name,
MB_SETFOREGROUND
);
}
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
I am working on a similar problem. I know the HWND for each Excel instance and implemented the MFC ActiveX control you mention above. However, I have not used an ActiveX control in C++ before. Do you know how I can get m_pDocDisp? I tried putting just the code above in my native C++ / Excel C API application and it doesn't find it.
http://www.codeproject.com/Messages/3730176/Get-Document-IDispatch-in-native-Cplusplus-possibl.aspx
|
|
|
|
|
Hi All,
I have an application generated by the VS2005 AppWizard so that it has Automation enabled and I've setup the interface so it all works correctly.
However, I also have the app accepting command line parameters when starting from the command line(which it mainly is since it's fired up from a Java servlet).
The app gets called so many times I only want one instance of it to exist at a time so as to cut down on system resource usage.
What I want to do is register the IDispatch of the automation object with the ROT when the app is first started up with the command line. That way when a user starts the app again I can check with the ROT to see if an instance of my app is running. If it is, I just get the IDispatch out of the ROT and pass the parameter values to the running instance via the methods on it. I then shut down my app before I've completed assigning all the necessary resources to it.
So my question is: How do I get the IDispatch to my app if it has been started with the command line?
Thanks very much for any help
Thomas
Cheers
Tom
Philosophy: The art of never getting beyond the concept of life.
Religion: Morality taking credit for the work of luck.
|
|
|
|
|
hello guys i need a project or rich examples for my projects ,and i have to deliver it this Thursday
and thank you very much
|
|
|
|
|
Wrong forum.
Be more specific and post to C++ CLI forum.
Life is a stage and we are all actors!
|
|
|
|
|
alright
i am on my way
|
|
|
|
|
Hi,
I have single Dialog Templates with all controls using for 3 differnt types.
For Controller-EditBox should be shown
For Indicator-ComboBox should be shown
For Switch-RadioButton should be shown.
So when i invoke dialog for controller it will show editbox,indicator will show combobox .
And What i want, if i invoke controller,then i will invoke indicator without closing the controller.
THis is funcntinality i want.
But what happened,after i clicked controller,when i click indicator it shows edit box only not ComBobox.
If i first open indicator,and then controller shows only ComboBox not EditBox.
How can i get that.
I use UpdateData() in OnInitDialog,But no use.
BOOL CFacePlate::OnInitDialog()
{
CDialog::OnInitDialog();
UpdateData(FALSE);
if(oTagBase->GetTagType()==CONTROLLER)
{
GetDlgItem(IDC_STATECOMBO)->ShowWindow(SW_HIDE);
}
if(oTagBase->GetTagType()==INDICATOR)
{
GetDlgItem(IDC_SPVALUE)->ShowWindow(SW_HIDE);
}
I have lot of controls like this.So i coded only to hide controls and not to show.
Is there any solution?
Anu
|
|
|
|
|
I would recommend you reading this article.
Life is a stage and we are all actors!
|
|
|
|
|
You have lot of controls?
Why don't you use a function?
Example:
void CFacePlate::SetDlgItemVisible(int idCtrl, int iTagType)
{
if (oTagBase->GetTagType() == iTagType)
{
GetDlgItem(idCtrl)->ShowWindow(SW_SHOW);
}
else
{
GetDlgItem(idCtrl)->ShowWindow(SW_HIDE);
}
}
BOOL CFacePlate::OnInitDialog()
{
CDialog::OnInitDialog();
SetDlgItemVisible(IDC_STATECOMBO, INDICATOR);
SetDlgItemVisible(IDC_SPVALUE, CONTROLLER);
}
|
|
|
|
|
Anu_Bala wrote: UpdateData(FALSE);
Remove this. It's rarely needed.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
HI,
I written one application using MFC Appwizard exe.In that application iam browsing a file in my PC and Parsing into required form and loading in a database table. Till now my application working fine.
But the requirement changed as i need to take the input from Commandline and need to Run the application as batch file.
MY Requirement is i need to take two parameters in commandline
one is File path and Another one is Table Name.
I need your Guidance.
Thanks,
Krishna.
|
|
|
|
|
|
|
The official MFC way is to:
- derive a class from CCommandLineInfo and overide CCommandLineInfo::ParseParam
- call CWinApp::ParseCommandLine in your overide of CWinApp::InitInstance using an instance of your class derived from CCommandLineInfo.
When a new instance of your application starts CWinApp::ParseCommandLine slices the command line into tokens and chucks each on in turn into "YourDerivedClass"::ParseParam. ParseParam can do whatever it likes with the tokens it gets - raise or lower flags, set global state, you name it.
If you want a simple class to explore these concepts try this for size:
class simple_command_line_parser : public CCommandLineInfo
{
public:
void ParseParam( const wchar_t* parameter, BOOL, BOOL )
{
::AfxMessageBox( parameter );
}
};
All it does is display the parameters it recieves in a message box. You'd use it by adding the following two line to your App's InitInstance:
simple_command_line_parser sclp;
ParseCommandLine( sclp );
Anyway, hope that helps!
Ash
|
|
|
|
|
this makes absolutley no sense as to why this is happening...
Here is the scenerio:
I have an INI file that gets uploaded into some product durring the test.
I have to modify the INI file before upload, so I do so using WritePrivateProfileString(x,x,x,x). Return value is good, no errors.
Read the settings I just changed in the INI file via the GetPrivateProfileString(x,x,x,x), values returned match what I changed them to,
ok, stop there.. (via breakpoint or messagebox)
Now, go into windows explorer and open the INI file and none of the data in the INI file has changed per the write command.
Now, exit the program, or stop it if in the enviornment. Now go and read the INI data from the INI file in windows explorer.. The data is now changed.
Or you can simplely write some data to a bogus file and it will force the INI file to get updated...
OK, now the reason this is such a problem is that after I modify the INI file I have to start the upload process, but I can't because the upload procss graps the file from windows, except the file hasn't been updated yet to the values I wrote using the writeprivateprofilestring command.
This makes no sense to me. Why is windows waiting to update the actual file? Is the a command I need to send to force windows to release the cach so that the file gets updated?
Hopefully someone can explaing what is going on here... Any information will help.. I hope I am so confused by this....
|
|
|
|
|
See the description here[^], particularly the paragraph that states:
The system keeps a cached version of the most recent registry file mapping to improve performance. If all parameters are NULL, the function flushes the cache. While the system is editing the cached version of the file, processes that edit the file itself will use the original file until the cache has been cleared.
It's time for a new signature.
|
|
|
|
|
Sounds like a caching issue. Would it help to call RegCloseKey() when done writing?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Dear friends,
how to create blank wmv file in visual c++ witout using any tools..
I tried different way, didn't get any result. so if anyone know about this
give some ideas of creation of blank wmv file
i am looking forward..
regards
Mohanchandra
|
|
|
|
|