Solved

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

Posted on 2007-04-10
5
574 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
ID: 18887344
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
ID: 18889109
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
ID: 18900186
>>>> 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
ID: 18903347
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
ID: 18905132
>>>> 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

830 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