m_pDTE->ExecuteCommand does not WORK !!?? 
Author Message
 m_pDTE->ExecuteCommand does not WORK !!??

Hy, im writting an addin in VC7 , and i try to open a new
document from the studio (out of the code), or open the
print dialog. but it doesnt works!
I have a Valid DTE pointer in my app, but the
executecommand function has no effect . in the msdn
doc,it is written, that the 2. arg is optional, but the
compiler gives an error, when only 1 arg is given. so i
tryed the following:

m_pDTE->ExecuteCommand((BSTR) "File.NewFile",(BSTR)"");

it has no effect! (but compiles)

anybody has some advice for me??

thanx a lot!!!!



Sun, 24 Jul 2005 17:49:37 GMT  
 m_pDTE->ExecuteCommand does not WORK !!??


Quote:
> Hy, im writting an addin in VC7 , and i try to open a new
> document from the studio (out of the code), or open the
> print dialog. but it doesnt works!
> I have a Valid DTE pointer in my app, but the
> executecommand function has no effect . in the msdn
> doc,it is written, that the 2. arg is optional, but the
> compiler gives an error, when only 1 arg is given. so i
> tryed the following:

> m_pDTE->ExecuteCommand((BSTR) "File.NewFile",(BSTR)"");

> it has no effect! (but compiles)

> anybody has some advice for me??

Cease believing that you can use a cast to
convert a const char * to a BSTR and get
anything that will work right when passed
to a function expecting an actual BSTR.

The compiler's type checking will do you a
lot of good, but only where you do not tell
the compiler to suspend its checks, as you
have done in the above code.

--
-Larry Brasfield
(address munged, s/sn/h/ to reply)



Sun, 24 Jul 2005 18:06:29 GMT  
 m_pDTE->ExecuteCommand does not WORK !!??
JEPEE!! thanx a lot, now it works!!
i casted it like this:

LPCSTR strTXT="File.NewFile";;
USES_CONVERSION ;
BSTR bstrText;                  
bstrText=A2BSTR(strTXT);

m_pDTE->ExecuteCommand(bstrText,(BSTR)"");

do you know by the way also, how i can open a new file in
the new file dialogue as well?
is ther something like the "SEND_KEYS" command in VB ?

thanx,greez!

Quote:
>-----Original Message-----
>In article <016101c2ccfb$e51b62b0


Quote:

>> Hy, im writting an addin in VC7 , and i try to open a
new
>> document from the studio (out of the code), or open
the
>> print dialog. but it doesnt works!
>> I have a Valid DTE pointer in my app, but the
>> executecommand function has no effect . in the msdn
>> doc,it is written, that the 2. arg is optional, but
the
>> compiler gives an error, when only 1 arg is given. so
i
>> tryed the following:

>> m_pDTE->ExecuteCommand((BSTR) "File.NewFile",(BSTR)"");

>> it has no effect! (but compiles)

>> anybody has some advice for me??

>Cease believing that you can use a cast to
>convert a const char * to a BSTR and get
>anything that will work right when passed
>to a function expecting an actual BSTR.

>The compiler's type checking will do you a
>lot of good, but only where you do not tell
>the compiler to suspend its checks, as you
>have done in the above code.

>--
>-Larry Brasfield
>(address munged, s/sn/h/ to reply)
>.



Sun, 24 Jul 2005 18:32:08 GMT  
 m_pDTE->ExecuteCommand does not WORK !!??


Quote:
> JEPEE!! thanx a lot, now it works!!
> i casted it like this:

> LPCSTR strTXT="File.NewFile";;
> USES_CONVERSION ;
> BSTR bstrText;                      
> bstrText=A2BSTR(strTXT);

> m_pDTE->ExecuteCommand(bstrText,(BSTR)"");

You might want to learn about the static_cast
and reinterpret_cast keywords in C++.  One
provides a way to say "convert this value, and
do not just reinterpret some bits", while the
other lets you say "reinterpret these bits, I
know exactly what needs doing, so just do it."

Using them properly avoids the kind of problem
you experienced with your code and is part of
good coding practise in many (some) organizations.

Quote:
> do you know by the way also, how i can open a new file in
> the new file dialogue as well?
> is ther something like the "SEND_KEYS" command in VB ?

SendKeys(), (or whatever it's called), is simply
a way to inject Windows messages into a given
window's message queue.  Lookup the PostMessage()
and SendMessage() API's.

Quote:
> thanx,greez!

You're welcome.

--
-Larry Brasfield
(address munged, s/sn/h/ to reply)



Mon, 25 Jul 2005 12:39:40 GMT  
 m_pDTE->ExecuteCommand does not WORK !!??


Quote:
> JEPEE!! thanx a lot, now it works!!
> i casted it like this:

> LPCSTR strTXT="File.NewFile";;
> USES_CONVERSION ;
> BSTR bstrText;
> bstrText=A2BSTR(strTXT);

> m_pDTE->ExecuteCommand(bstrText,(BSTR)"");

You're still casting a char * to a BSTR. I know it works now, probably
because the second parameter is not used.

Like this it looks cleaner:

CComBSTR bstrTXT=L"File.NewFile";
m_pDTE->ExecuteCommand(bstrTXT, CComBSTR(L""));

You can find CComBSTR in atlbase.h

Quote:
> do you know by the way also, how i can open a new file in
> the new file dialogue as well?
> is ther something like the "SEND_KEYS" command in VB ?

> thanx,greez!

> >-----Original Message-----
> >In article <016101c2ccfb$e51b62b0


> >> Hy, im writting an addin in VC7 , and i try to open a
> new
> >> document from the studio (out of the code), or open
> the
> >> print dialog. but it doesnt works!
> >> I have a Valid DTE pointer in my app, but the
> >> executecommand function has no effect . in the msdn
> >> doc,it is written, that the 2. arg is optional, but
> the
> >> compiler gives an error, when only 1 arg is given. so
> i
> >> tryed the following:

> >> m_pDTE->ExecuteCommand((BSTR) "File.NewFile",(BSTR)"");

> >> it has no effect! (but compiles)

> >> anybody has some advice for me??

> >Cease believing that you can use a cast to
> >convert a const char * to a BSTR and get
> >anything that will work right when passed
> >to a function expecting an actual BSTR.

> >The compiler's type checking will do you a
> >lot of good, but only where you do not tell
> >the compiler to suspend its checks, as you
> >have done in the above code.

> >--
> >-Larry Brasfield
> >(address munged, s/sn/h/ to reply)
> >.



Wed, 27 Jul 2005 05:10:51 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. m_pDTE->ExecuteCommand Function does not work!!

2. C++/ATL/ADO - Intellisense not working (statement completion options) not working

3. LVN_GETINFOTIP does not work for iSubItem > 0

4. <Help> button not working

5. struct.array works - struct->pointer not

6. #include <wincrypt.h> not working

7. pCmdUI->SetCheck(1) not working

8. Help: AfxGetApp()->OnIdle(-1); not working anymore

9. iterator_traits<iter> does not work

10. why IXMLDOMDocument->load does not work???!!!

11. >>>>>>Not enough C/UNIX people in NYC!

12. Where is the rough work done?

 

 
Powered by phpBB® Forum Software