Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / May 2006

Tip: Looking for answers? Try searching our database.

Attempting to automate Visual_Studio_2005

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JeffRelf - 02 May 2006 05:21 GMT
Hi  All,  The VC++ 8.0 program below compiles in Visual_Studio_2005.
It's attempting to automate Visual_Studio_2005 to do:

 DTE.ItemOperations.OpenFile("C:\__\X\In.TXT")
 
Invoke(OpenFile)  returns DISP_E_MEMBERNOTFOUND, 0x80020003.
C:\__\X\In.TXT does exist.

Similar code works fine when I automate Excel, so why doesn't it work in VS ?
....+.+.+

#pragma warning( disable:  4127 4244 4305 4430 4508 4701 4702 4706 4996  )
#undef _DEBUG
#define UNICODE
#define _WIN32_WINNT 0x0501
#define WIN32_LEAN_AND_MEAN
#include <Windows.H>
#include <StdIO.H>
#include <Ole2.H>

#define  Loop( N )  int J = - 1, LLL = N ; while ( ++ J < LLL )
#define  Str  swprintf
#define  Rel( X ) ( ! X ? 0 : (short) X == -1 ? X = 0 : ( X->Release(), X = 0))
#define FrV( X )  \
 ( X.vt == VT_DISPATCH ? 0 : VariantClear( & X ), memset( & X, 0, sizeof X ) )

typedef unsigned char  uchar ;  typedef unsigned short  ushort ;  
typedef unsigned long  ulong ;  typedef unsigned int  uint ;  
typedef uchar  * _LnP ;  typedef char  * __LnP ;
typedef wchar_t  * LnP ;  typedef  LnP  * LnA ;  
const int Sz_Ptr = sizeof( _LnP ), Sz_Char = sizeof ( wchar_t );

typedef IDispatch  * OleT ;  OleT VS ;  VARIANT OleRV, Var, Var2 ;
wchar_t  Error [ 400 ];

_Call…( int IdenType, OleT Container, LnP  Macro, int  Cnt_Params, _LnP SP ) {
 FrV( OleRV );  HRESULT rv ;
 if ( ! Container || ( short ) Container == -1 )  return ;
 DISPID  IdenID = 0 ;
 rv = Container->GetIDsOfNames( IID_NULL, & Macro
 , 1, LOCALE_USER_DEFAULT, & IdenID );
 if ( FAILED( rv ) ) {
   Str( Error, L"0x%08lx, Was _%s_ misspelled ?"
   , rv, Macro);  return ;  }
 VARIANT  * B_Args = new  VARIANT [ Cnt_Params + 1 ]
 , * P_Args = B_Args + Cnt_Params ;
 Loop( Cnt_Params )
   * -- P_Args = * ( VARIANT * ) SP, SP += sizeof VARIANT ;
 DISPPARAMS  ParamList = { 0 };  
 ParamList.cArgs = Cnt_Params ;  ParamList.rgvarg = B_Args ;
 if ( IdenType & DISPATCH_PROPERTYPUT ) {  ParamList.cNamedArgs = 1 ;  
   DISPID dispidNamed = DISPID_PROPERTYPUT;
   ParamList.rgdispidNamedArgs = & dispidNamed ;  }
 rv = Container->Invoke( IdenID, IID_NULL
 , LOCALE_SYSTEM_DEFAULT, IdenType, & ParamList, & OleRV, 0, 0 );
 delete [] B_Args ;
 if ( FAILED( rv ) )
   Str( Error, L"0x%08lx, _%s_ Needs more/less/better parameters ?"
   , rv, Macro );
 if ( rv < 0 || OleRV.vt <= 1 || OleRV.vt == VT_ERROR )  FrV( OleRV );  }

Call( OleT Container, LnP  Macro ) {  
 _Call…( DISPATCH_METHOD, Container, Macro, 0, 0 );  }

Call…( OleT Container, LnP  Macro, int Cnt_Params, ...) {
 _Call…( DISPATCH_PROPERTYPUT
 , Container, Macro, Cnt_Params, ( _LnP ) & Cnt_Params + Sz_Ptr );  
 FrV( Var );  }

Call…RV( OleT Container, LnP  Macro, int Cnt_Params, ... ) {
 _Call…( DISPATCH_PROPERTYGET
 , Container, Macro, Cnt_Params, ( _LnP ) & Cnt_Params + Sz_Ptr );
 FrV( Var );  }

__stdcall WinMain( HINSTANCE, HINSTANCE, LPSTR, int ) {
 CoInitialize( 0 );  CLSID  clsid ;  
 CLSIDFromProgID( L"VisualStudio.DTE", & clsid );  
 IUnknown  * _VS ;
 GetActiveObject( clsid, 0, ( IUnknown * * ) & _VS );  VS = 0;
 if ( _VS )  _VS->QueryInterface( IID_IDispatch, (void **) & VS );
 if ( ! VS ) {   Rel( _VS );  return ; }
 //  DTE.ItemOperations.OpenFile("C:\__\X\In.TXT")
 OleT  ItemOperations ;
 Call…RV( VS, L"ItemOperations", 0 );  
 if ( ! ( ItemOperations = OleRV.pdispVal ) )  goto Clean_Up ;

 Var.vt = VT_BSTR;  Var.bstrVal = SysAllocString( L"C:\\__\\X\\In.TXT" );
 Call…RV( ItemOperations, L"OpenFile", 1, Var );  
 //  OleRV is now blank,  Error:  DISP_E_MEMBERNOTFOUND, 20003

 Clean_Up:  Rel( VS ); Rel( _VS );
}  
Eric Gisse - 02 May 2006 06:17 GMT
Jeff...Relf wrote:

[snip]

KEEP YOUR sh.t OUT OF SCI.PHYSICS
JeffRelf - 02 May 2006 13:20 GMT
RE:  Automating Visual_Studio_2005 to do:
  DTE.ItemOperations.OpenFile("C:\__\X\In.TXT")
 
I found a solution, shown below, that used the ATL.
I don't know why the OLE2 method didn't work like it does for Excel.
....+.+.+

#pragma warning( disable:  4430 4508  )
#include <ATLBase.H>
//  import DTE from LIBID
#import "libid:80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2" version("8.0") lcid("0") raw_interfaces_only named_guids
using namespace EnvDTE;
CComPtr<EnvDTE::_DTE> VS;

__stdcall WinMain( HINSTANCE, HINSTANCE, LPSTR, int ) {
 CoInitialize( 0 );  CLSID  clsid ;  
 CLSIDFromProgID( L"VisualStudio.DTE", & clsid );   IUnknown  * _VS = 0 ;
 GetActiveObject( clsid, 0, ( IUnknown * * ) & _VS );  VS = 0;
 if ( ! _VS )  return ;
 _VS->QueryInterface( __uuidof(EnvDTE::_DTE), ( void ** ) & VS );
 if ( ! VS )  return ;
 HRESULT rv ;  CComPtr<ItemOperations> operations ;
 //  DTE.ItemOperations.OpenFile("C:\__\X\In.TXT")
 rv = VS->get_ItemOperations( & operations );
 if ( rv || ! operations )  return ;
 Window  * Tab ;  BSTR  File = SysAllocString( L"C:\\__\\X\\In.TXT" );
 operations->OpenFile( File, 0, & Tab );
 SysFreeString( File );   }  
John Bailo - 02 May 2006 15:15 GMT
Jeff…Relf wrote:

> RE:  Automating Visual_Studio_2005 to do:
>    DTE.ItemOperations.OpenFile("C:\__\X\In.TXT")
[quoted text clipped - 25 lines]
>   operations->OpenFile( File, 0, & Tab );
>   SysFreeString( File );   }

So now you can open a file.

Signature

Texeme Textcasting powers
http://www.you-read-it-here-first.com

JeffRelf - 02 May 2006 19:18 GMT
Hi  John_Bailo,  Re:  How the VC++ 8.0 code I showed had to be ATL, not OLE2,
in order to truly automate Visual_Studio_2005,

You told me:  So now you can open a file.

Yea, I'm just talented like that.
I'm wondering why OLE2 wouldn't do it.
I'll look deeper into it when I get the time.

Hey John, it looks like I'll be doing some work for a real live pimp
and porn producer... odd huh ?

I'm doing some emergency coding for the www.ABA.COM right now,
for the Chinese version of the Banker's games I wrote in C++.

I'm also planning on working with T.J., a billionaire,
making offers by email to buy around 20 thousand tons of alluminum ingots
or scrap copper to 19 potential buyers around the world.

I have to check the cash price at U.S. docks vs
the cash price at Korean/Venezuelan docks,
making offers that will yield 50 cents a pound in gross income.

I might make millions from it, and learn about shipping
and the arbitrage of actual commodities, not derivatives.
T.J. might see me in Seattle soon.
John A. Bailo - 02 May 2006 19:49 GMT
Jeff…Relf wrote:

> I might make millions from it, and learn about shipping
> and the arbitrage of actual commodities, not derivatives.
> T.J. might see me in Seattle soon.

Here's something that fits your worldview:

http://news.yahoo.com/news?tmpl=story&u=/ap/20060502/ap_on_he_me/sick_america_1M
iddle-Aged


Americans Sicker Than British

CHICAGO - Middle-aged, white Americans are much sicker than their
counterparts in England, startling new research shows, despite U.S.
health care spending per person that is more than double what Britain
spends.

A higher rate of Americans tested positive for diabetes and heart
disease than the British. Americans also self-reported more diabetes,
heart attacks, strokes, lung disease and cancer.

The gap between countries holds true for educated and uneducated, rich
and poor.

"At every point in the social hierarchy there is more illness in the
United States than in England and the differences are really dramatic,"
said study co-author Dr. Michael Marmot, an epidemiologist at University
College London in England.
T Wake - 02 May 2006 20:10 GMT
> RE:  Automating Visual_Studio_2005 to do:
>   DTE.ItemOperations.OpenFile("C:\__\X\In.TXT")
>
> I found a solution, shown below, that used the ATL.
> I don't know why the OLE2 method didn't work like it does for Excel.
> ....+.+.+

Hi Jeff,

I assume you still haven't fixed your news reader as not only was this *not*
sent to your blog, you even added yet another group who aren't interested to
it.

It is especially odd as you have repeatedly told Eric Gisse and myself that
you never post to COLA any more.

Maybe you need to work on it some more.

Signature

For Google Groups users this may be important
http://blinkynet.net/comp/uip5.html

T Wake - 02 May 2006 20:08 GMT
> Hi  All,  The VC++ 8.0 program below compiles in Visual_Studio_2005.
> It's attempting to automate Visual_Studio_2005 to do:

Hi Relf...Ffej,

Your news reader seems to be playing up again and you posted to USENET
instead of your blog. I am sure you didn't mean to send this to
news://sci.physics.

Thanks.

Signature

For Google Groups users this may be important
http://blinkynet.net/comp/uip5.html


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.