Solved

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

Posted on 2007-04-10
5
584 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

734 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