Click here to Skip to main content
15,906,333 members
Home / Discussions / COM
   

COM

 
GeneralAccessing a file's properties from a VC++ application Pin
jopett5-Oct-03 20:35
jopett5-Oct-03 20:35 
GeneralRe: Accessing a file's properties from a VC++ application Pin
algol14-Oct-03 21:59
algol14-Oct-03 21:59 
GeneralCOM Dialog box Pin
Anthony98873-Oct-03 8:48
Anthony98873-Oct-03 8:48 
GeneralRe: COM Dialog box Pin
Abhishek Srivastava19-Oct-03 21:01
Abhishek Srivastava19-Oct-03 21:01 
GeneralUse of CommandButton Active X Pin
Jo Fredrickson2-Oct-03 20:37
Jo Fredrickson2-Oct-03 20:37 
GeneralRe: Use of CommandButton Active X Pin
Amit Dey8-Oct-03 10:41
Amit Dey8-Oct-03 10:41 
GeneralIApplication woes Pin
AndyP12-Oct-03 0:36
AndyP12-Oct-03 0:36 
GeneralRe: IApplication woes Pin
AndyP12-Oct-03 5:16
AndyP12-Oct-03 5:16 
How embarrassing, replying to my own posts. However, I have found a solution (probably wrong, but at least it works). I thought I'd post it here incase anyone else had similar novice difficulties.
The following code checks to see if there's an active visual studio running. If there isn't, then one is created using CoCreateInstance. Next, the specified file is opened, then the specified line is visited.
(note _HRESULT_SUCCESS is just a wee macro I use for testing HRESULT values. Also, you need to include atlbase.h, initguid.h,objmodel/appguid.h,objmodel/appauto.h,objmodel/textauto.h and objmodel/testguid.h).

Modification: Curses; had to remove <code>...</code> tags, because the template instanciations of CComPtr and CComQIPtr were not appearing Frown | :(

void _OpenFileAtLineInVS(const TCHAR* pFilename,const unsigned int Line)
{
CComPtr<IApplication> pApp = 0;
CComPtr<IUnknown> pUnkApp = 0;

if (_HRESULT_SUCCESS(GetActiveObject(CLSID_Application,0,&pUnkApp)))
{
_HRESULT_SUCCESS(pUnkApp->QueryInterface(IID_IApplication,(void**)&pApp));
}

if (pApp == 0)
{
_HRESULT_SUCCESS(CoCreateInstance(CLSID_Application,0,CLSCTX_SERVER,IID_IApplication,(void**)&pApp));
}

if (pApp != 0)
{
// Make sure visual studio is active and visible
pApp->put_Visible(VARIANT_TRUE);
pApp->put_Active(VARIANT_TRUE);

CComPtr<IDispatch> pDisp = NULL;

// Get the documents interface
pApp->get_Documents(&pDisp);
CComQIPtr<IDocuments, &IID_IDocuments> pDocs(pDisp);

pDisp = 0;

// Open the specified file
pDocs->Open(CComBSTR(pFilename),CComVariant("Auto"),CComVariant("False"),&pDisp);

// Get the active document (the newly opened file)
pDisp = 0;
pApp->get_ActiveDocument(&pDisp);
CComQIPtr<ITextDocument,&IID_ITextDocument> pActiveDoc(pDisp);
pDisp = 0;
pActiveDoc->get_Selection(&pDisp);

// Get the text selection object from the active document, and go to the appropriate line
CComQIPtr<ITextSelection,&IID_ITextSelection>(pDisp)->GoToLine(Line,CComVariant(dsMove));
}
}
GeneralAn Outlook plug-in issue Pin
dorutzu1-Oct-03 8:04
dorutzu1-Oct-03 8:04 
GeneralRe: An Outlook plug-in issue Pin
Mike Dimmick1-Oct-03 12:36
Mike Dimmick1-Oct-03 12:36 
GeneralRe: An Outlook plug-in issue Pin
dorutzu9-Oct-03 14:09
dorutzu9-Oct-03 14:09 
GeneralThread Pin
Anthony98871-Oct-03 3:55
Anthony98871-Oct-03 3:55 
GeneralRe: Thread Pin
billdwilson31-Oct-03 9:44
billdwilson31-Oct-03 9:44 
GeneralCOM-Marshaling-IUnknown as method param Pin
ceno1-Oct-03 3:29
ceno1-Oct-03 3:29 
GeneralAcrobat Distiller OLE/COM Automation Pin
HooK.NET1-Oct-03 1:49
HooK.NET1-Oct-03 1:49 
GeneralRe: Acrobat Distiller OLE/COM Automation Pin
Steve S1-Oct-03 3:12
Steve S1-Oct-03 3:12 
GeneralRe: Acrobat Distiller OLE/COM Automation Pin
HooK.NET1-Oct-03 3:29
HooK.NET1-Oct-03 3:29 
Generaltyplib marshalling or custom marshalling Pin
umarcool29-Sep-03 4:29
umarcool29-Sep-03 4:29 
QuestionHow to add a new protocol for Internet explorer? Pin
Robert Mao28-Sep-03 5:17
Robert Mao28-Sep-03 5:17 
AnswerRe: How to add a new protocol for Internet explorer? Pin
Tomas Petricek28-Sep-03 10:51
Tomas Petricek28-Sep-03 10:51 
GeneralQuestion about Com Process Pin
FeedFood27-Sep-03 0:01
sussFeedFood27-Sep-03 0:01 
GeneralRe: Question about Com Process Pin
umarcool29-Sep-03 19:14
umarcool29-Sep-03 19:14 
Generalunhandle exception using CreateDispatch Pin
danielferre26-Sep-03 2:04
danielferre26-Sep-03 2:04 
GeneralRe: unhandle exception using CreateDispatch Pin
Steve S26-Sep-03 4:34
Steve S26-Sep-03 4:34 
GeneralRe: unhandle exception using CreateDispatch Pin
danielferre26-Sep-03 6:12
danielferre26-Sep-03 6:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.