|
NO!!!!!!
Don't use T2BSTR. First off, it will leak a BSTR as you used it. MS strongly suggests that you use CComBSTR for conversions to and from BSTR.
Also, I think the API routine uses a const WCHAR *. Thus creating a BSTR not only means you are using the wrong data type, but you are also wasting computer resources creating the BSTR.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Another thing worth mentioning with these string conversion macros, is that they are potentially dangerous in loops, as they allocate memory on the stack, and not on the heap.
--
An eye for an eye will only make the world blind.
|
|
|
|
|
That isn't true for 7.0 and greater. The conversion macros became first class objects and avoid the whole loop issue.
I think...
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
From my atlconv.h (atl7/vs.net 2k3):
#define W2A(lpw) (\
((_lpw = lpw) == NULL) ? NULL : (\
_convert = (lstrlenW(_lpw)+1)*2,\
ATLW2AHELPER((LPSTR) alloca(_convert), _lpw, _convert, _acp))) They added the Cx2y-classes, and deprecated the macros, so that existing code wouldn't break.
--
An eye for an eye will only make the world blind.
|
|
|
|
|
How do I use this MACRO?
Thank you very much for your kind help
Bob
|
|
|
|
|
|
Thank you so much for your help.
However, there are some errors occur:
1. using the following order
#include <atlconv.h>
#include <stdafx.h>
#include <sapi.h>
it gives error C2065: 'A2W' : undeclared identifier
2. if #include <stdafx.h>
#include <sapi.h>
#include <atlconv.h>
It gives 14 errors with first one as:
d:\program files\microsoft visual studio\vc98\atl\include\atlconv.h(48) : error C2065: '_ASSERTE' : undeclared identifier.
|
|
|
|
|
Please check the Do not treat <'s as HTML tags checkbox and use <pre> tags so your includes show up properly.
I don't know which libraries you're using. Including atlconv.h will Just Work for MFC and ATL projects.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ
Strange things are afoot at the U+004B U+20DD
|
|
|
|
|
Hi Mike,
I just realize that the post I sent doesn't show the contents correctly.
(I didn't click "Do not treak <'s as HTML")
The include files are
#include <stdafx.h>
#include <sapi.h>
#include <atlconv.h>
where in stdafx.h:
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <stdio.h>
|
|
|
|
|
And there is always the WideCharToMultiByte and MultiByteToWideChar FUNCTIONS you can call... Avoiding the whole ATL issue altogether...
|
|
|
|
|
Thanks you so much.
It's exactly what I want and it works!
Bob
|
|
|
|
|
OK, my problem for some of you may seem silly but I'm a rookie at Windows API.
I've written a program - a simple database (it stores student's names and their marks). All of this information is contained in Edit controls. It all works fine but when I add more students to the list some of them aren't shown. So I have to make a vertical scrollbar. But I don't have any idea how to do it. I've found some description about SCROLLINFO structure but I don't know how to use it. I've added WM_VSCROLL to my window class, but it just shows up and do nothing. I would be very grateful if someone could help me.
I'm using Dev C++ if it matters.
And some info about this program - the number of students is indicated by a global variable int a. It is increased by a function void new_student(). Each control is 30 high + 10 of space. At the top of that list there are static controls which name the columns - they're the same size as Edits...
And sorry for my English
Edit: If you know some easier way to do the scrolling (by hitting some keys or something like that) please write it too
|
|
|
|
|
Hi, I want to simulate a keypress using SendInput(). I am trying to send the letter 'a' to the programme VLC(VideoLAN) to adjust the volume.
Can anyone please show me a full example of something like this, using either SendInput(), SendMessage or any other way? I am using Visual C++. I have googled for this for three days now, and I can't find any good examples
Thanks in advance!
pete
|
|
|
|
|
|
How can I change the content of the status bar of the main frame in view.cpp ?
Thanks!
|
|
|
|
|
Last I read it was very difficult to alter the text in pane 0. This is because the MFC framework is always writing something to it, so even if you wrote something else to it, it would only last a fraction of a second until MFC changed it. Depending on what you are doing, it might be better to create a second pane and write to it.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
With the following steps:
1.Define a value,such as ID_FO_INDEX_MOUSEPOS.
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_FO_INDEX_MOUSEPOS,
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
2.Add a update message to your view.
afx_msg void OnUpdateMousePos(CCmdUI *pCmdUI);
ON_UPDATE_COMMAND_UI(ID_FO_INDEX_MOUSEPOS, OnUpdateMousePos)
3.Change it with the following style:
void CFOPCanvasCore::OnUpdateMousePos(CCmdUI *pCmdUI)
{
pCmdUI->SetText(m_IndMousePosString);
}
Jack
---------------------------------------------------------------------------------
XD++ MFC/C++ Flow/Diagram Library -- http://www.ucancode.net
|
|
|
|
|
You'll also need a stringtable entry for ID_FO_INDEX_MOUSEPOS in the project's .rc file.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Is there a way to open up a word document as read-only when it's not a read-only file to begin with. I opened up my file using CreateProcess. Is there a way to do this? Thanks!
|
|
|
|
|
CreateProcess() does not open files !!!!!!!
if you want to open a file with the ReadOnly option, you could do this :
std::ifstream file("theFile.txt");
or
fopen("theFile.txt", "r");
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I tried the following and still won't open up. I want to open it up in MS Word which was why I used CreateProcess. What did I do wrong? Thanks!
FILE * pFile;
pFile = fopen (filename,"r");
if (pFile!=NULL)
{
fputs ("fopen example",pFile);
fclose (pFile);
}
|
|
|
|
|
Is using ShellExecute() out of the question?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
No but how is it different from CreateProcess? There seems to be no parameters that specify it as read-only.
|
|
|
|
|
I see, you are trying to open with word and not with your own program for reading. What you want to do will probably need to use word OLE automation. I would suggest doing some searching for just that, it's not as simple as just executing the program to do this. It's actually not much more code but understanding the concepts is a bit more complex. I haven't done this sort of thing in a long time so I don't know the code off hand, but I'm sure a quick google search will find something.
-- Rocky Dean Pulley
|
|
|
|
|
I found a simpler way. Before opening up the document in Word, I used GetFileAttributes() to get its file attribute. If the returned value is not read-only, I called SetFileAttributes to set it so and then use CreateProcess to open it up within Word. Much simpler. Thanks for your help though.
|
|
|
|