Just started using this compiler - with my old VC6 code, but it seems to think a directory is readonly when it isnt? - any ideas?
this is at/after the last the line of the file

compiler output:
c:\data\dev\cms\3.0.0.0\code\word\src\word.cpp(220) : fatal error C1083: Cannot open include file: 'c:\data\dev\cms\3.0.0.0\code\word\src': Permission denied

Recommended Answers

All 9 Replies

Another reason you might get that error is

  • The file is already exclusively opened by another program
  • Some anti-virus programs cause that problem

Try rebooting your computer to see if that corrects the problem.

Maybe you should take a look at the following link: http://msdn.microsoft.com/en-us/library/et4zwx34(VS.71).aspx

Can you also post all the includes you did in word.cpp?
Can you also list the contents of your 'c:\data\dev\cms\3.0.0.0\code\word\src' ?

Thanks - I already perused said article, and I guess the reason must be there but I can't see it.
Effectively this is a straight lift of a VC6 workspace which did compile.

Got to be an easy one - I just can't see it, thanks for your help!

// Word1.cpp: implementation of the CWord class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Word.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////


CWord::CWord(): saved(false), app(__uuidof(Word::Application))
{
	//Logger ol("CWord::CWord()");
	//if(!mApp.m_lpDispatch &&!mApp.CreateDispatch("Word.Application"))
	//{
	//	AfxMessageBox("Couldn't start Word and get an application 0bject");
	//	return;
	//}
	//LPDISPATCH pdisp=NULL;

	// Open The Documents collection
	//if( mDocs.m_lpDispatch==NULL)
	//{
	//	pdisp=mApp.GetDocuments();
	//	ASSERT(pdisp);
	//	mDocs=pdisp;
	//}
}


CWord::~CWord()
{
	Close();
}


long CWord::GetNumFields()
{
	//return mFormFields.GetCount();
	return doc->FormFields->GetCount();
}


bool CWord::PopulateField( long field, const char* text)
{
	Logger ol("CWord::PopulateField( nField:%d, strText:%s)",field, text);
	CString name;
	CString s;
	long type=0;
	COleVariant varIndex((short) 0);
	long count = GetNumFields();

	if( field >= count || field < 0)
	{
		/*ol.*/LogAndMsg( E_ERROR, "Error on form %s trying to print %s to field %d.\n\
								   There are only %d form fields on the form", (const char*)(_bstr_t)doc->GetName(), text, field, count);
		return false;
	}

	try
	{
		//ol.Log("About to iterate the fields, count=%d",nCount);
		if( count != 0)
		{
			varIndex = field;
			//LPDISPATCH pdisp=mFormFields.Item( &varIndex);
			//ASSERT(pdisp);
			//form_field=pdisp;
			form_field = doc->FormFields->Item(varIndex);
			name = (const char*)form_field->GetName();
			type = form_field->GetType();

			switch(type)
			{
			case 70: // text field
				form_field->Result.Assign(_bstr_t(text));//SetResult( text);
				break;

			default:
				s.Format("Doc %s: Can't populate field %d type=%d is not a text box",doc->GetName(), field, type);
				LogAndMsg(E_ERROR, s);
				return false;
			}
			//ol.Log("field: %d, type: %d, name: %s", nIndex, lType, strName);
		}

		//doc.SetSaved( TRUE);
	}
	catch(_com_error e)
	{
		GetError(e);
		DumpError(e, CONTEXT, 1046, "Error populating field %d with %s in MS Word", field, text);
		return false;
	}
	catch(...)
	{
		AfxMessageBox("unknown exception occurred");
		return false;
	}

	return true;
}



bool CWord::Open( const char* doc_path)
{
	_variant_t file(doc_path);
	Logger ol("CWord.Open( c %s)",doc_path);
	//LPDISPATCH pdisp;

	try
	{
		//if(doc.m_lpDispatch!=NULL)
		//	doc.m_lpDispatch->Release();

		doc = app->Documents->Open(	& file,		// FileName, 
							& covOptional,	// VARIANT* ConfirmConversions, 
							& covFalse,		// VARIANT* ReadOnly, 
							& covFalse,		// VARIANT* AddToRecentFiles, 
							& covOptional,	// VARIANT* PasswordDocument, 
							& covOptional,	// VARIANT* PasswordTemplate, 
							& covOptional,	// VARIANT* Revert, 
							& covOptional,	// VARIANT* WritePasswordDocument, 
							& covOptional,	// VARIANT* WritePasswordTemplate, 
							& covOptional,	// VARIANT* Format, 
							& covOptional,	// VARIANT* Encoding, 
							& covOptional);	// VARIANT* Visible

//		ASSERT(pdisp);

		// Attach doc and mFormfields
//		if(!Init( pdisp))
//		{
//			ASSERT(FALSE);
//		}
	}
	catch(_com_error e)
	{
		LogAndMsg(E_ERROR, "Error opening %s\t %s", doc_path, GetError(e));
		return false;
	}
	catch(...)
	{
		LogAndMsg(E_ERROR, "Caught unknown error trying to open %s", doc_path);
		return false;
	}
	return true;
}


// Once connected to a document
// get the forms collection
//
bool CWord::Init( /*LPDISPATCH pdisp*/)
{
	//ASSERT(pdisp);
	//doc=pdisp;
/*
	if( mFormFields.m_lpDispatch==NULL)
	{
		pdisp=doc.GetFormFields();
		ASSERT(pdisp);
		mFormFields=pdisp;
	}
*/

	return true;
}


void CWord::SetVisible( bool show)//=true
{
	app->Visible = ( show ? TRUE : FALSE);
}


Word::FormField& CWord::GetFormField(long field)
{
	_variant_t v = field;
	form_field = doc->FormFields->Item(&v);
	return form_field;
}


bool CWord::Print()
{
//	mD0c.PrintOut(VARIANT* Background, VARIANT* Append, VARIANT* Range, VARIANT* OutputFileName, 
//				  VARIANT* From, VARIANT* To, VARIANT* Item, VARIANT* Copies, VARIANT* Pages, 
//				  VARIANT* PageType, VARIANT* PrintToFile, VARIANT* Collate, 
//				  VARIANT* ActivePrinterMacGX, VARIANT* ManualDuplexPrint, VARIANT* PrintZoomColumn, 
//				  VARIANT* PrintZoomRow, VARIANT* PrintZoomPaperWidth, VARIANT* PrintZoomPaperHeight);
	doc->PrintOut();
	return true;
}


void CWord::Close( )  // =true
{
	_variant_t vSaveChanges( (short)saved);
	//form_field.ReleaseDispatch();
	//mFormFields.ReleaseDispatch();
	//doc.ReleaseDispatch();
	//mDocs.ReleaseDispatch();

	app->Quit( &vSaveChanges);
	//mApp.DetachDispatch();
}

Here is a listing of the dir:

c:\Data\Dev\CMS\3.0.0.0\Code\word\src>attrib
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\ClassDiagram1.cd
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\Common.h
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\mso.tlh
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\mso.tli
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\mssccprj.scc
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\msword.tlh
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\msword.tli
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\Resource.h
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\StdAfx.cpp
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\StdAfx.h
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\vbe6ext.tlh
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\vbe6ext.tli
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\vssver.scc
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\Word.cpp
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\Word.def
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\Word.dsp
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\Word.h
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\Word.rc
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\Word1.h
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\WordApp.cpp
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\WordApp.h
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\Wordd.def
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\~AutoRecover.Word.vcproj
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\~AutoRecover.Word.vcproj.MARS.Terry.user
A            C:\Data\Dev\CMS\3.0.0.0\Code\word\src\~AutoRecover.Word.vcproj.Terry-PC.Terry.user

using Attrib

I have tried a reboot - and it doesnt go, I have also tried on XP as well as Windows & - with VC2008 Still same thing

Whats strange is that other components compile ...

mmm
in the code if I uncomment this line I get the error:
(Here I have returned a dummy value just to compile - and we don't get the permissions error)
If I replace the ret 1 with the commented code I do ...

long CWord::GetNumFields()
{
    return 1;// doc->FormFields->GetCount();
}

I didn't notice you are using VC++ 6.0 compiler. Yes, I have had that same problem many times. I was also using Nortin Antivirus, and the problem went away when I turned Norton off. I know of several other people who had the same problem with Norton antivirus conflicts with that compiler. Fortunately I don't use either any more.

If you post word.h we could compile and test your programs.

Dear dragon many thanks 4 your help.
Yes I was using VC6 previously, and have just ported the code to my new machine running VC2008 - In the process I have dragged this little bit of code from the old method using IDispatch Wrappers to #import. ... and most certainly broke it - but it is during this fix the problem occurred.

Since other components compile, I wonder if there is a name clash since the Project is called Word, the file is word.cpp and the namespace is Word::

I aggree I hate Symantec with avengence aever since I insatlled Norton Anti virus which promptly broke my home network, uninstalled Norton and guess what - still mashed the network because apparently the uninstall does not really uninstall....

If you have the time I will forward said compoent - not very big
Sorry 4 delay just installed winzip: - windows 7 and Winzip don't really like each other that much it seems!
Attached:
ta!

Have you already tried to move all your project's include files to the directory of your compiler's include files?
(Please make sure you don't overwrite or delete any existing compiler files !);)
Maybe not the best solution, but it's only to see if it works ... :?:

Sorry for tardy delay, been away, many thanks for help!

It seems to me to do with the document object: as soon as the comiler derefs this e.g. to compile:
doc->FormFields;
then I get the error.
Just
doc;

does not give error, indeed any doc->xx seems to give the error

So I guess it must be something to do wi the doc object.
strange - any ideas?

No I have not tried to move the header files - not sure what I would gain

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.