emitchell
asked on
Where can I find CoInitializeEx(...)
I am using the clipboard for the first time and following
Swanke's book "Visual C++ MFC Programming by Example.",
example 76.
This serializes my doc to the clipboard:
...
CSharedFile file(GMEM_MOVEABLE|GMEM_DD ESHARE);
CArchive storeArchive(&file
, CArchive::store | CArchive::bNoFlushOnDelete );
TRY {
Serialize(storeArchive, m_selections);
// flush and close the memory file
storeArchive.Close();
}
CATCH_ALL(e)
{
...
}
END_CATCH_ALL
// pick out the memory file
HGLOBAL hMem = file.Detach();
if(!hMem) return;
// now stick this file into the clip board. the data source object
// will be deleted when the clipboard is emptied
COleDataSource* pDS = new COleDataSource();
pDS->CacheGlobalData(theAp p.GetDocCl ipboardFor mat(), hMem);
pDS->SetClipboard();
}
When I get the the clip board part, I get an exception thrown with the message that I haven't called CoInitialize().
When I look in the doc, it says that I shouldn't use this in any new apps but should call CoInitializeEx(NULL). My problem is that I can't find this routine. No header file in MFC 6.0 seems to contain it and their is only one reference to CoInitialize(...) when I do a find on the MFC source code.
I have put the call to CoInitialize(NULL) in the InitInstance of the main app and that seems to work.
However, my questions are:
1. Should I be using CoInitializeEx(NULL)?
2. If so, which header file defines it?
Swanke's book "Visual C++ MFC Programming by Example.",
example 76.
This serializes my doc to the clipboard:
...
CSharedFile file(GMEM_MOVEABLE|GMEM_DD
CArchive storeArchive(&file
, CArchive::store | CArchive::bNoFlushOnDelete
TRY {
Serialize(storeArchive, m_selections);
// flush and close the memory file
storeArchive.Close();
}
CATCH_ALL(e)
{
...
}
END_CATCH_ALL
// pick out the memory file
HGLOBAL hMem = file.Detach();
if(!hMem) return;
// now stick this file into the clip board. the data source object
// will be deleted when the clipboard is emptied
COleDataSource* pDS = new COleDataSource();
pDS->CacheGlobalData(theAp
pDS->SetClipboard();
}
When I get the the clip board part, I get an exception thrown with the message that I haven't called CoInitialize().
When I look in the doc, it says that I shouldn't use this in any new apps but should call CoInitializeEx(NULL). My problem is that I can't find this routine. No header file in MFC 6.0 seems to contain it and their is only one reference to CoInitialize(...) when I do a find on the MFC source code.
I have put the call to CoInitialize(NULL) in the InitInstance of the main app and that seems to work.
However, my questions are:
1. Should I be using CoInitializeEx(NULL)?
2. If so, which header file defines it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
#if (_WIN32_WINNT >= 0x0400 ) || defined(_WIN32_DCOM) // DCOM
WINOLEAPI CoInitializeEx(LPVOID pvReserved, DWORD dwCoInit);
#endif // DCOM
When I define _WIN32_DCOM to make it active my main app compiles correctly.
I assume the MSVisual Studio wizard would have defined this correctly if I had asked for the right thing when I had created the project. I didn't realise that the clipboard needed access to DCOM.
Thanks for the help. Solved my problem