Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-04-10
5
Medium Priority
?
601 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:Deepu Abraham
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 1050 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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…
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

730 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