Exception in GetStencilPath()

V

vicky

Hi All!

I am developing a VC++ project for automating MS-Visio 2003, when i am
trying to get stencil paths using function GetStencilPaths(), i have
following error:
COleException. SCODE: 800706ba.

I am working on Windows-XP (SP2), Visual Studio 6.0 and Visio-2003.

I am using following code to automate Visio:
//
******************************************************************************************************
CLSID
visio_clsid=
{ 0x00021a20, 0x0000, 0x0000, { 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x46 } };

IUnknown *pUnk=
NULL;
IVApplication
app;

GetActiveObject(visio_clsid, NULL,
&pUnk);

IDispatch *pDisp =
NULL;
if ( pUnk !=
NULL )
pUnk->QueryInterface(IID_IDispatch, (LPVOID *)
&pDisp);
if ( pDisp ==
NULL )
{
if ( !app.CreateDispatch
(visio_clsid) )

{
return -2;
}
}
else
{
app.AttachDispatch
(pDisp);
}
app.SetVisible(TRUE); //Visio invoked and
visible.

CString strStencilPaths = app.GetStencilPaths(); //Problem occurrs on
this line.
CString strXaStencilFolder = "c:\
\My_Stencil_Folder";

//Check if path is already
there,
if (strstr(strStencilPaths, strXaStencilFolder) ==
NULL)
{
strStencilPaths +=
";";
strStencilPaths +=
strXaStencilFolder;
app.SetStencilPaths
(strStencilPaths);
}
//
******************************************************************************************************

What causes this problem? Thanks in anticipation.

Regards,
Vicky
 
P

Paul Herber

CString strStencilPaths = app.GetStencilPaths(); //Problem occurrs on
this line.

First thing that comes to mind is to use a CStringW as the returned
data is Unicode.
 
V

vicky

Hi Paul!

Thanks for ur quick reply.
As I know through the function declaration and definition
"app.GetStencilPaths();" returns CString.
So, there won't be any issue related to unicode.

Regards,
Vicky
 
N

Nikolay Belyh

Probably you have some troubles with your COM wrappers. I think the
best way to automate Visio from unmanaged C++ (if there is such a way)
nowadays is the #import directive, and not that 10-years-old MFC stuff
(i.e. the wrapper generated with "Add Class" function of Visual
Studio). Also you might consider capturing a full error message some
way, since AFAIK nothing usefull can be figured out from that number
you provided...

Some snippet that shall work:

-----

// import visio type library
#import "libid:{00021A98-0000-0000-C000-000000000046}" no_namespace

{
IVApplicationPtr app;
app.GetActiveObject(__uuidof(Application));
if (!app)
app.CreateInstance(__uuidof(Application))

app->Visible = VARIANT_TRUE;
CString stencil_path = app->StencilPaths;
}
 
V

vicky

Hi Nikloay!

Thanks for ur reply.
the code which i've given you in my previous post is working correctly
in MFC Dialog based application, but, problem arises when i package
the code in MFC DLL.

I have logged the HRESULT values returned , and they are as follows:
-2147221021 : 0x800401E3 : Operation unavailable
-2147417848 : 0x80010108 : The object invoked has disconnected from
its clients.

What could be the problem? everything is working fine in exe but not
in DLL.

Regards,
Vicky
 
N

Nikolay Belyh

I have logged the HRESULT values returned , and they are as follows:
-2147221021 : 0x800401E3 : Operation unavailable
-2147417848 : 0x80010108 : The object invoked has disconnected from
its clients.

Probably this means, that Visio application you launched (i.e. the
"object invoked") has just crashed. I.e. probably the first call to
app.SetVisible() just crashes either Visio or your application.

Also, if an MFC application that is packed in a DLL, probably it would
be wise to add at the very beginning of your function in DLL:
 
P

Paul Herber

Hi Nikloay!

Thanks for ur reply.
the code which i've given you in my previous post is working correctly
in MFC Dialog based application, but, problem arises when i package
the code in MFC DLL.

I have logged the HRESULT values returned , and they are as follows:
-2147221021 : 0x800401E3 : Operation unavailable
-2147417848 : 0x80010108 : The object invoked has disconnected from
its clients.

What could be the problem? everything is working fine in exe but not
in DLL.

One thing to check, is this the only addon that is running?
It's very easy for me to reproduce a problem like this by having more
than one addon loading, one of which shows a modal start up dialog,
just like Visio itself can do under certain circumstances. If a modal
dialog box is being shown then the UI object is not available and
trying to access it will cause an exception. This includes trying to
access the path information, I've just tried it, an exception occurs.

All my addon startup code now does:

while (ready = false) do
begin
try
if Visio_Controller.Application.BuiltInMenus <> nil then
ready := true;
Forms.Application.ProcessMessages;
except;
end;
end;
try
UIObj := Visio_Controller.Application.CustomMenus;
if UIObj = nil then
UIObj := Visio_Controller.Application.BuiltInMenus;
except
UIObj := Visio_Controller.Application.BuiltInMenus;
end;
 
V

vicky

Hi Nikolay and Paul!

Thanks for ur responses guys.

Actually, The DLL is an MFC regular DLL which is being used for JAVA,
it means, it is a JNI DLL which has native functions which will be
called from JAVA.

Now, I am not invoking any dialog so there is no need of declaring
AFX_MANAGE_STATE(AfxGetStaticModuleState()), althoguh i did give it a
try but it was not of any use. I used CoInitilaize(NULL) to initialize
OLE dlls which is my very first line in code.

One interesting thing is happening that when the code in previous post
is running from EXE it uses VISIO instance which is already running to
show the diagram, BUT, when this code runs from DLL, it always open a
new instance of DLL. I figured out that GetActiveObject() is not
working correctly from DLL.

Hope this clarification will help you guys to sort out the problem.
Thanks a lot.


Kind Regards,
Vicky
 

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