Re: GetWindowThreadProcessId return 0
Hi Joseph!
Dear..Thanks for ur reply. I think, i was unable to clear the
problem. Let me explain it.
Actually, i am developing a regular MFC DLL project to automate
visio-2003. This DLL is being called from JAVA using JNI. Our java
project is a plugin for eclipse, in which we used to show different
diagrams like data flow diagrams, data model diagrams etc. By using
the details, provided by Java in a file, i drop the shapes from my
stencil (stencil is respecive to diagram i.e. there are stencils for
DFD, DMD resp.) and connect them using connector. This is the whole
story.
Now, i am coming to my problem, when my java application is running
and user wants to export any diagram say DFD
to visio, if, visio is not running i opened Visio and draw the
shapes.
If there are more instances of visio opened then i use GetActiveObject
(.....) to get any active instance of Visio, after getting IUnknown
pointer to this activated instance, i opened a new document and start
drawing shapes.
For instance, i mean , Visio is running as independent application
more that one.
I am using ROTVIEWER from VC++ tools to see entries in ROT.
When i used the code from my MFC EXE, it works fine, the cldsi entry
of Visio is there in ROT and won't lost for consequent exports of
diagrams. BUT, when i used it from DLL, first time CLSID is there
then for next export , it losts.
I have gone thru some forums, documents, tutorials and came to know
that if any appliction window is activated then it will register
itself in ROT. I tried it by activating Visio window manually and saw
the entry of CLSID again in ROT.
Following code is being used to check whether visio is already running
or not, if visio is already running then it grabs that instance and
start drawing shapes by opening a new Document.
// Code Starts
CoInitialize(NULL);
....
....
....
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.
....
....
....
CoUninitialize();
//Code Ends
GetActiveObject Works fine from MFC EXE but gives error on using from
MFC regular DLL.
Following error code returned when using GetActiveObject() from DLL.
HResult:-2147221021 (800401e3)
What causes this problem? Plz help me to sort out the problem.
Thanks.
Regards,
Vicky