Question

I'm trying to open a new document (a document that I am creating) in my VSProject using the steps described here:

However I'm not having much success - the above link tells me that I should be calling IVsUIShell.CreateDocumentWindow however I get a return value of -2147024809 (FFFFFFFF80070057) and the output ppWindowFrame is null.

What am I doing wrong? Are there any examples on how to create a new document window using this method?

This is what I have so far:

int retval = rdt.FindAndLockDocument(
    (uint)_VSRDTFLAGS.RDT_EditLock, // dwRDTLockType
    myDocumentUniqueIdentifier, // pszMkDocument
    out hierachy, // ppHier
    out itemId, // pitemid
    out docData, // ppunkDocData
    out cookie); // pdwCookie

IVsWindowFrame windowFrame; 
Guid emptyGuid = Guid.Empty;
Guid editorType = new Guid(GuidList.VSPackageEditorFactoryString);

// I know that the document is not open
retval = shell.CreateDocumentWindow(
    0, // grfCDW
    myDocumentUniqueIdentifier, // pszMkDocument
    (IVsUIHierarchy)hierachy, // pUIH
    itemId, // itemid
    IntPtr.Zero, // punkDocView
    docData, // punkDocData
    ref editorType, // rguidEditorType
    "MyPhysicalView", // pszPhysicalView
    ref emptyGuid, // rguidCmdUI
    this, // psp
    "New document", // pszOwnerCaption
    "New document", // pszEditorCaption
    null, // pfDefaultPosition
    out windowFrame); // ppWindowFrame

The return value from FindAndLockDocument is 1 (S_FALSE), which I assume means that the document was not found. itemId is uint.MaxValue which is definitely a bad sign - do I need to create an entry in the running document table somehow before calling CreateDocumentWindow? If so how do I do this?

Any examples or samples which cover the above ground would be very helpful.

Was it helpful?

Solution

I finally managed this with the help of this thread on the MSDN forums:

My code now uses the IVsUIShellOpenDocument interface and the OpenDocumentViaProjectWithSpecific method - the following snippet is basic but actually works:

IVsUIShellOpenDocument shellOpenDocument = (IVsUIShellOpenDocument)GetService(typeof(IVsUIShellOpenDocument));

string mkDocument = "MyUniqueDocumentId";

// This is the GUID for the editor factory, i.e. the one that appears in the Guid attribute on your
// editor factory (that implements IVsEditorFactory): [Guid(GuidList.guid_VSPackageEditorFactory)]
Guid xmlGuid = GuidList.guid_VSPackageEditorFactory;

string physicalView = null;
Guid logicalViewGuid = VSConstants.LOGVIEWID_Primary;
Microsoft.VisualStudio.OLE.Interop.IServiceProvider ppSP;
IVsUIHierarchy ppHier;
uint pitemid;
IVsWindowFrame ppWindowFrame;

shellOpenDocument.OpenDocumentViaProjectWithSpecific(
    mkDocument,
    (uint)__VSSPECIFICEDITORFLAGS.VSSPECIFICEDITOR_DoOpen,
    ref xmlGuid,
    physicalView, 
    ref logicalViewGuid, 
    out ppSP, 
    out ppHier, 
    out pitemid, 
    out ppWindowFrame);

if (ppWindowFrame != null)
{
    ppWindowFrame.Show();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top