Opening Word Documents Using C++

closed account (LN7oGNh0)
I want to write a program that allows me too write the path of a document and then open it. (also so that I can edit it.) I've tried a couple times, but i think the problem is is that i'm using a Win32 console application instead of something else. And if that is the problem, what one should I use?

Thank.
Last edited on
closed account (LN7oGNh0)
OK... no one seems to be answering... Here is a program that I made. (There probably are some problems with it. Also, I have only done it for one document.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <ShellAPI.h>

using namespace std;

int main()
{
	cout << "Type the number and pres enter to open the following documents:";
	cout << "\n 1 = nadding value";
	
	int choice;
	cin >> choice;
	
	do
	{
		if (choice = 1)
		{
			ShellExecute(this->m_hWnd,"open",
			"adding value.doc","C:\\Users\\Haziqu\\Documents\\School Work\\Business\\adding value.doc",SW_SHOW);
		}
		else 
		{
			cout << "Please enter a valid number";
		}
	}while(choice != 1);

cin.get()	
return 0;
}



At the moment, when I hover over 'ShellExecute' it says it is undefined.
Also when I hover over 'this' it says that this may only be used in a noon-static member function.
Lastly, when I hover over 'SW_SHOW' it says that this is not defined.

The program is supposed to keep looping until the user chooses '1' to open the program.

PLEASE ANSWER!

thank you.



EDIT: I just ran the program, and a load of errors just came up! Obviously I am doing something (or more likely) or a lot of things wrong.
Last edited on
> and a load of errors just came up!
I suggest you to read the errors.
If you don't understand them, then post with the referenced code.

> this may only be used in a noon-static member function.
¿what do you think that is this? http://cplusplus.com/doc/tutorial/classes2/
closed account (LN7oGNh0)
This is all so confusing! I made a much simpler code... but it doesnt work. It just comes up with a blank console window. doesnt open the word document.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <fstream>
using namespace std;

int main () {

  fstream filestr;

  filestr.open ("test.txt", fstream::in | fstream::out | fstream::app);

  filestr.close();


  return 0;
}


Luckily no errors!

How come its not opening the document!

Last edited on
> doesnt open the word document.
¿how are you checking that?
As long as the file exists and you do have permission, it should open.
perror() may help you
closed account (LN7oGNh0)
Ya, I did that using the example code, (I put my file name in there.)

1
2
3
4
5
6
7
8
FILE * pFile;
  pFile=fopen ("adding value.doc","rb");
  if (pFile==NULL)
    perror ("The following error occurred");
  else
    fclose (pFile);
  cin.get();
  return 0;


DO I have to put the path of the document?
closed account (LN7oGNh0)
Also, is it alright if I am using a console application for this sort of stuff?
Topic archived. No new replies allowed.