Click here to Skip to main content
15,904,023 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: rand() causing unresolved external symbol Pin
Stuart Dootson13-Aug-09 5:17
professionalStuart Dootson13-Aug-09 5:17 
GeneralRe: rand() causing unresolved external symbol Pin
Member 321680813-Aug-09 5:25
Member 321680813-Aug-09 5:25 
QuestionRe: rand() causing unresolved external symbol Pin
Randor 13-Aug-09 12:56
professional Randor 13-Aug-09 12:56 
AnswerRe: rand() causing unresolved external symbol Pin
Member 321680814-Aug-09 3:27
Member 321680814-Aug-09 3:27 
QuestionWord automation question Pin
sashoalm13-Aug-09 4:54
sashoalm13-Aug-09 4:54 
AnswerRe: Word automation question Pin
Stuart Dootson13-Aug-09 5:11
professionalStuart Dootson13-Aug-09 5:11 
GeneralRe: Word automation question Pin
sashoalm13-Aug-09 5:35
sashoalm13-Aug-09 5:35 
GeneralRe: Word automation question Pin
Stuart Dootson13-Aug-09 22:17
professionalStuart Dootson13-Aug-09 22:17 
Further to my previous answer...

It just so happens that I have a little sample app that automates Excel, so I modified it slightly to a) automate Word as well, and b) call a method on a thread (I use Boost.Threads for this because it makes it so much easier than raw Win32 threads). This app is quite happy to make Excel or Word method calls on a thread other than the one that created the Word/Excel instance - here's the code (missing some #includes, but you get the drift):

#include <boost/thread.hpp>
#import "libid:00020813-0000-0000-C000-000000000046" version("1.6") auto_search no_dual_interfaces rename("DialogBox", "excelDialogBox") rename("RGB", "excelRGB") rename("DocumentProperties", "excelDocumentProperties") rename("SearchPath", "excelSearchPath") rename("CopyFile", "excelCopyFile") rename("ReplaceText", "excelReplaceText")
#import "libid:00020905-0000-0000-C000-000000000046" version("1.6") auto_search no_dual_interfaces rename("RGB", "wordRGB") rename("ReplaceText", "wordReplaceText") rename("FindText", "wordFindText") rename("ExitWindows", "wordExitWindows")

void GetActiveDocName(Word::_ApplicationPtr const& wd, _bstr_t& name)
{
   try
   {
      name = wd->ActiveDocument->Name;
   }
   catch(_com_error& e)
   {
      name = L"No name";
   }
}

void GetActiveWorkbookName(Excel::_ApplicationPtr const& xl, _bstr_t& bs)
{
   if (Excel::_WorkbookPtr wb = xl->ActiveWorkbook)
   {
      try
      {
         bs = wb->FullName;
      }
      catch(_com_error& e)
      {
         bs = L"No name";
      }
   }
}

int _tmain(int argc, _TCHAR* argv[])
{
   CoInitializeEx(0, COINIT_MULTITHREADED);
   {
      Excel::_ApplicationPtr xl;
      if (SUCCEEDED(xl.CreateInstance(__uuidof(Excel::Application))))
      {
         // Make sure there's at least one workbook
         xl->Workbooks->Add();
         _bstr_t name;
         // Execute GetActiveWorkbookName(xl, name) on a separate thread
         boost::thread getName(GetActiveWorkbookName, boost::cref(xl), boost::ref(name));
         // Wait for the thread to terminate
         getName.join();
         std::cout << (char*)name << std::endl;
      }
      Word::_ApplicationPtr wd;
      if (SUCCEEDED(wd.CreateInstance(__uuidof(Word::Application))))
      {
         // Make sure there's at least one document
         wd->Documents->Add();
         _bstr_t name;
         // Execute GetActiveDocName(wd, name) on a separate thread
         boost::thread getName(GetActiveDocName, boost::cref(wd), boost::ref(name));
         // Wait for the thread to terminate
         getName.join();
         std::cout << (char*)name << std::endl;
      }
   }
   CoUninitialize();
   return 0;
}


This code, when run, displays correct names. So - it IS possible to call Word on a thread other than the one that instantiated it...

Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

QuestionStatic pointer Pin
kumar sanghvi13-Aug-09 4:22
kumar sanghvi13-Aug-09 4:22 
AnswerRe: Static pointer Pin
Cedric Moonen13-Aug-09 4:29
Cedric Moonen13-Aug-09 4:29 
GeneralRe: Static pointer Pin
kumar sanghvi13-Aug-09 5:03
kumar sanghvi13-Aug-09 5:03 
GeneralRe: Static pointer Pin
sashoalm13-Aug-09 21:00
sashoalm13-Aug-09 21:00 
QuestionSequencing or queuing parallel process [modified] Pin
s v joshi13-Aug-09 3:36
s v joshi13-Aug-09 3:36 
AnswerRe: Sequencing or queuing parallel process Pin
Iain Clarke, Warrior Programmer13-Aug-09 4:10
Iain Clarke, Warrior Programmer13-Aug-09 4:10 
AnswerRe: Sequencing or queuing parallel process Pin
Stuart Dootson13-Aug-09 5:09
professionalStuart Dootson13-Aug-09 5:09 
QuestionCFileDialog::HideControl() broken Pin
softwaremonkey13-Aug-09 2:47
softwaremonkey13-Aug-09 2:47 
AnswerRe: CFileDialog::HideControl() broken PinPopular
Stuart Dootson13-Aug-09 3:25
professionalStuart Dootson13-Aug-09 3:25 
GeneralRe: CFileDialog::HideControl() broken Pin
softwaremonkey13-Aug-09 4:30
softwaremonkey13-Aug-09 4:30 
AnswerRe: CFileDialog::HideControl() broken Pin
Iain Clarke, Warrior Programmer13-Aug-09 3:52
Iain Clarke, Warrior Programmer13-Aug-09 3:52 
QuestionStrange runtime behavior without breakpoint Pin
Tomas(cz)13-Aug-09 0:55
Tomas(cz)13-Aug-09 0:55 
AnswerRe: Strange runtime behavior without breakpoint Pin
Code-o-mat13-Aug-09 2:07
Code-o-mat13-Aug-09 2:07 
GeneralRe: Strange runtime behavior without breakpoint Pin
Tomas(cz)13-Aug-09 3:41
Tomas(cz)13-Aug-09 3:41 
QuestionCapture inactive desktop in windows Pin
Stifly13-Aug-09 0:36
Stifly13-Aug-09 0:36 
AnswerRe: Capture inactive desktop in windows Pin
Code-o-mat13-Aug-09 6:57
Code-o-mat13-Aug-09 6:57 
QuestionRandom Name Generator Pin
Chuck Vought13-Aug-09 0:30
Chuck Vought13-Aug-09 0:30 

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.