Problems with Drop() function.

H

Haakon S.

I have an application programmed in VC++ 6.0 and I'm trying to incorporate
the Visio ActiveX Drawing Control in a separate window. When I try to use the
CVPage:: Drop() function I get an error message when the program exits. In
debug mode:

"Unhandled exception in MyFile.exe (PE.DLL) 0xC0000005: Access Violation".

Everything else works fine. When I have dropped the object to the drawing
with page.Drop(master,X,Y), I can save the drawing, reopen it, etc. No other
error messages is reported except this irritating one when the application is
closing. It is only occuring if I have invoked Drop() at least once.

BTW. Is it possible to get proper documentation for the control with VC++,
or do I have to read VB or C# code?
 
S

Shahzad Godil

Drop is working fine in my VB.Net based application using using this code.
Just make sure that stencil is also opened from which you are dropping. I
copied that code "DropMaster" from SDK and it is working fine.

Shahzad Godil
Karachi-Pakistan.
 
H

Haakon S.

Thanks for your reply, Shahzad.

The thing is that I use the document stencil. There is not an open, separate
stencil window. The user chooses a type of shape from a toolbar, and when he
clicks the drawing afterwards, the shape is dropped onto the drawing. Seems
to work fine.

Do you see anything wrong with this setup, or do you have any other ideas
about the problem?
 
S

Shahzad Godil

I am not sure about your exact problem. But this Visio SDK code is
perfectly working. Also see, its code. It is going to open stencil
document before using page.drop. I think in your case, stencil is not
opened. Just try this code to drop shape on your page instead of your own.

Thanks
Shahzad Godil
Karachi-Pakistan
MSN Messenger : (e-mail address removed)


'// DropMaster.vb
'// <copyright>Copyright (c) Microsoft Corporation. All rights reserved.
'// </copyright>
'// <summary>This module demonstrates how to drop a master onto a page at a
'// specific location.</summary>

Imports System

Namespace Microsoft.Samples.Visio.VBNet

Module DropMaster

'// <summary>This function looks for the document with the name
'// specified in stencilName in the Documents collection and, if the
'// document is not in the collection, opens it as a docked stencil.
It
'// then gets the master, using its universal name masterNameU, and
'// drops it on the specified page.</summary>
'// <param name="pageToDrop">Page where the master will be dropped
'// </param>
'// <param name="masterNameU">Universal name of the master in the
'// stencil</param>
'// <param name="stencilName">Name of the stencil from which the
master
'// is to be found</param>
'// <param name="pinX">X-coordinate of the pin in the specified
units
'// </param>
'// <param name="pinY">Y-coordinate of the pin in the specified
units
'// </param>
'// <param name="units">Units used by pinX and pinY</param>
'// <returns>Shape that was created by dropping the master on the
page
'// indicated by the page parameter</returns>
Public Function DropMasterOnPage( _
ByVal pageToDrop As Microsoft.Office.Interop.Visio.Page, _
ByVal masterNameU As String, _
ByVal stencilName As String, _
ByVal pinX As Integer, _
ByVal pinY As Integer, _
ByVal units As Object) As Microsoft.Office.Interop.Visio.Shape

Dim visioApplication As
Microsoft.Office.Interop.Visio.Application
Dim visioDocuments As Microsoft.Office.Interop.Visio.Documents
Dim stencil As Microsoft.Office.Interop.Visio.Document
Dim masterInStencil As Microsoft.Office.Interop.Visio.Master
Dim droppedShape As Microsoft.Office.Interop.Visio.Shape =
Nothing
Dim cellPinX As Microsoft.Office.Interop.Visio.Cell
Dim cellPinY As Microsoft.Office.Interop.Visio.Cell
Dim pinXInternal As Double
Dim pinYInternal As Double

visioApplication = CType(pageToDrop.Application, _
Microsoft.Office.Interop.Visio.Application)

Try

' Verify that all incoming string parameters are not of zero
' length, except for the ones that have default values as ""
' and the output parameters.
If (masterNameU.Length() = 0) Then
Throw New System.ArgumentNullException("masterNameU", _
"Zero length string input.")
End If

If (stencilName.Length() = 0) Then
Throw New System.ArgumentNullException("stencilName", _
"Zero length string input.")
End If

' Find the stencil in the Documents collection by name.
visioDocuments = visioApplication.Documents

Try
stencil = visioDocuments.Item(stencilName)
Catch

' The stencil is not in the collection; open
' it as a docked stencil.
stencil = visioDocuments.OpenEx(stencilName, _
CShort(Microsoft.Office.Interop.Visio. _
VisOpenSaveArgs.visOpenDocked))
End Try

' Get a master from the stencil by its universal name.
masterInStencil = stencil.Masters.ItemU(masterNameU)

' Convert the PinX and PinY into internal units.
pinXInternal = visioApplication.ConvertResult(pinX, units, _
Microsoft.Office.Interop.Visio.VisUnitCodes.visInches)

pinYInternal = visioApplication.ConvertResult(pinY, units, _
Microsoft.Office.Interop.Visio.VisUnitCodes.visInches)

' Drop the master on the page that is passed in.
' Set the PinX and PinY using pinXInternal
' and pinYInternal respectively.
droppedShape = pageToDrop.Drop(masterInStencil,
pinXInternal, _
pinYInternal)

' Update the units for PinX and PinY of the shape.
cellPinX = droppedShape.CellsSRC( _
CShort(Microsoft.Office.Interop.Visio. _
VisSectionIndices.visSectionObject), _
CShort(Microsoft.Office.Interop.Visio. _
VisRowIndices.visRowXFormOut), _
CShort(Microsoft.Office.Interop.Visio. _
VisCellIndices.visXFormPinX))

cellPinY = droppedShape.CellsSRC( _
CShort(Microsoft.Office.Interop.Visio. _
VisSectionIndices.visSectionObject), _
CShort(Microsoft.Office.Interop.Visio. _
VisRowIndices.visRowXFormOut), _
CShort(Microsoft.Office.Interop.Visio. _
VisCellIndices.visXFormPinY))

cellPinX.Result(units) = pinX
cellPinY.Result(units) = pinY

Catch err As Exception

droppedShape = Nothing
System.Diagnostics.Debug.WriteLine(err.Message)
End Try

Return droppedShape

End Function
End Module
End Namespace
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top