Solved

How to get a byte array of a MS  Word document using C++ /  MFC

Posted on 2007-04-10
5
544 Views
Last Modified: 2013-11-20
Using C++ and ATL in MS Word 2003, how can I get a byte array of the entire current document to put into a database.  Yes, I know the filesize issue. I know how to embed into the database, but not sure how to get the byte array without first saving ther document.

Thanks!
0
Comment
Question by:craig20120
  • 2
  • 2
5 Comments
 
LVL 11

Expert Comment

by:DeepuAbrahamK
Comment Utility
May be this MS word automatioin would help you: read this link
http://www.codeproject.com/com/MSWACPP.asp

Best Regards,
DeepuAbrahamK
0
 

Author Comment

by:craig20120
Comment Utility
Thanks for the suggestion.  I know how to parse a document, I need to actually get a pointer to the entire contents of the document so if I emdedded the contents of that pointer in my database it is the actually Word document.  
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
Comment Utility
>>>> I need to actually get a pointer to the entire contents of the document
Do you need text only (A) or the document as an embedded OLE object (B) or the contents of the binary doc file as a BLOB in the database (C).

A and B can be made by using automation. Your DBMS should be able to store embedded OLE objects (MS ACCESS SQL SERVER) for B. C can be made by retrieving the file size by calling stat, allocating a buffer which is big enough to store the fie, opening the doc file in binary mode, reading the file to the buffer, storing the buffer as a BLOB:

       struct stat status = { 0 };
       if (stat("mydoc.doc", &status) == 0)
       {
              ifstream ifs("mydoc.doc", ios::in | ios::binary);
              char buf = new char[status.st_size];
              if (ifs.read(buf, status.st_size))
              {
                     ifs.close();
                     // store buf to dtabase
              }
         
             
       }

>>>> Yes, I know the filesize issue.
What is the filesize issue?

>>>> I know how to embed into the database
If you know where is the problem?

>>>> but not sure how to get the byte array
If embedding OLE objects you don't need to care for the byte array yourself.

>>>> without first saving ther document.
Why saving??? Isn't the document saved yet? Do you want to get the document while it isn't saved?

Regards, Alex

0
 

Author Comment

by:craig20120
Comment Utility
Evening Alex, either B or C would be good.  I have figured out how to copy the complete document to the clipboard, get the embeded object and then save it to my database. I would perfer to do C though Yes, without saving the document to the disk first.

It sounds like B is dealing with the embeded object like using the clipboard to.  Wondering if this way would be more straight forward though???
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 350 total points
Comment Utility
>>>> I would perfer to do C though Yes, without saving the document to the disk first.
Hmmm. Don't think it worked. The temporary save can't be used cause it is exclusively opened and it's contents doesn't need to be up-to-date. So, the only chance is to use automation to make a 'Save As...', read the file and delete it after read.

Regards, Alex
 
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now