|
cast to (LPCTSTR) instead
|
|
|
|
|
The normal plain old C-String most function want is char* or const char* . That is a signed type.
Microsoft uses a specific macro named TCHAR , which boils down to char* in non-unicode and to (2 Byte-)wchar_t in Unicode builds. Very handy.
Likewise, TSTR denotes a null-terminated string consisting of TCHAR.
A pointer to a constant string consisting of TCHAR is called a LPCTSTR (long pointer to constant TSTR ).
The CString-class wraps the TCHAR s from you, and has a conversion operator to be used in place of a constant TSTR .
So, when you stop using unsigned char and start using TCHAR , you problems will go away automagically.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
Priya_Sundar wrote: However, here i am not able to store it back to 'String'.
Why does that surprise you? No memory has been allocated for String . As it stands now, it points to wherever. try:
String = new unsigned char[result.GetLength() + 1];
strcpy(String, result);
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
sorry for the delayed post.
i was actually in a meeting.
to your problem,
Priya_Sundar wrote: However, here i am not able to store it back to 'String'. i am getting various compiler errors like
the quickest solution is ,
for(int i=0;i less than n;i++)
{
String[i]=cString.Getat(i);//or cString[i] must also should work.
}
gud luck.
-- modified at 10:08 Thursday 11th October, 2007
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
i think the topic got far diverted here.
|
|
|
|
|
OK firstly we need to establish the meaning of 'delete' in this context. In C++ delete tends to means 'free the memory'. You certainly can't 'free the memory' currently being used by the '{' and the '}' so in C++ terms you can't 'delete' the first and last characters.
What you want is to end up with String pointing at "abcdef". You could do this with 2 lines
<br />
String++;<br />
String[6] = '\0';<br />
This will make the charatcer pointer point at the next character and then 'blank out' the end '}' (which is 6 characters on from the 'a' that String now points at) by replacing it with a NULL
There is one problem with this of course. You now have no way to free the string memory as the original value of String is lost. If your string is on the heap you will need to solve this. Enjoy.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
use a temporary buffer and use the CRT function strcpy() to copy what you want in the origin string
or if you use C++, you'd better look into the std::string STL class
|
|
|
|
|
i tried something like this
<br />
::string gidstring = String;<br />
gidstring = gidstring.substr(1, gidstring.length() - 2);<br />
But ended up with compiler error:
"error C2039: 'string' : is not a member of '`global namespace''"
inspite of including the <string.h> header file.
how to proceed??
Priya Sundar
|
|
|
|
|
why did you write ::string , thereby explicitly requesting string in the global namespace?
You probably wanted to write std::string .
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
What about...
unsigned char *srcString = "{abcdef}";
unsigned char *dstString = "";
memcpy (srcString+1, dstString, (srcString.length () - 2));
If it works you can still free the memory and delete the pointer avoiding the problem that Matthew said.
Up to that point you can work with *dstString as it was your original one.
Hope it helps
P.S. Im not sure if it works, I just asked about buffers and how to get parts of the memory two/three days ago, and this is something that I get from the answers I received.
-- modified at 6:29 Thursday 11th October, 2007
I forgot...
with the srcString + X you specify the first character you want without changing the "value" of where the pointer points.
at dsstString you can make the same leaving some intial chars unmodified adding X to his base adress
the last is the number of chars of the first string you wanna copy in the second
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
I want to use this function to get close event from WORD(like DoModal() in Dialog). My code like this:
---------------------------------------------------------------------------------------------
COleDispatchDriver DocProperties(pDispatch, FALSE);
_variant_t Property((long)Word::wdPropertyPages);
_variant_t Result;
DocProperties.InvokeHelper(DISPID_....,
DISPATCH_...,
VT_BSTRT,
(void*)&Result,
(BYTE*)VTS_VARIANT,
&Property);
---------------------------------------------------------------------------------------------
Is it correct idea? And what I have to input for 3 first parameters? Thank you.
|
|
|
|
|
hai,
iam using a 64 bit integer in my application.
now my problem is if i want to print its hexa value into a string, like
str.Format("%x",value);
it is printing only lsb 32 bits.
how can i achieve this using a single type specifier like %x.
how ever,
i got it solved with the following technique.
UINT64 value=0xabcdefef;
CString str;
unsigned long value1,value2;
value1=value>>32;
value2=value;
str.Format("%x%x",value1,value2);
can any body please suggest me what is the type specifier for unsigned int 64.
thanks in advance.
-- modified at 4:59 Thursday 11th October, 2007
|
|
|
|
|
I am not sure about but... can it help casting the value to (_UINT64)? I mean
str.Format (_T("%x"), (UINT64) value);
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
|
thanks nibu,
what i was looking for was exctly that.
|
|
|
|
|
Hello friends,
I require to show the dc into the Picture Control as a bitmap.
For that I am using the code like below, but only shows blank bitmap in the Picture control.
HDC DeskDC = GetDC(NULL);
HDC hdcStatic = GetDC(hWndStatic);
HBITMAP hb = CreateCompatibleBitmap(hdcStatic,200,200);
SelectObject(hdcStatic,hb);
SetWindowLong(hWndStatic,GWL_STYLE,(GetWindowLong(hWndStatic,GWL_STYLE) & ~SS_TYPEMASK) | SS_BITMAP) ;
BitBlt(hdcStatic,0,0,200,200,DeskDC,0,0,SRCCOPY);
SendMessage(hWndStatic, STM_SETIMAGE , IMAGE_BITMAP,(LPARAM)hb);
Please tell me if you know what is going wrong.
|
|
|
|
|
What are you trying to do???
You want the bitmap to be a copy of a a 200x200 rect of the screen?
That's fine.
You should select the hb bitmap back out of the memory DC before you
hand it off to the static (picture) control.
<font color="Red">HGDIOBJ hOldBM = </font>SelectObject(hdcStatic,hb);
SetWindowLong(hWndStatic,GWL_STYLE,(GetWindowLong(hWndStatic,GWL_STYLE) & ~SS_TYPEMASK) | SS_BITMAP) ;
BitBlt(hdcStatic,0,0,200,200,DeskDC,0,0,SRCCOPY);
<font color="Red">SelectObject(hdcStatic, hOldBM);</font>
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thnk you vary much for you help. But still I am not able to perform the thing.
I am doing something like this as you have told me to do.
But getting NULL in hOLdBM. and So getting BLANK Image (black Image)
HDC DeskDC = GetDC(NULL);
HDC hdcStatic = GetDC(hWndStatic);
HBITMAP hb = CreateCompatibleBitmap(hdcStatic,200,200);
HGDIOBJ hOldBM = SelectObject(hdcStatic,hb);
SelectObject(hdcStatic, hOldBM);
SetWindowLong(hWndStatic,GWL_STYLE,(GetWindowLong(hWndStatic,GWL_STYLE) & ~SS_TYPEMASK) | SS_BITMAP) ;
BitBlt(hdcStatic,0,0,200,200,DeskDC,0,0,SRCCOPY);
SelectObject(hdcStatic, hOldBM);
SendMessage(hWndStatic, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hOldBM);
SendMessage(hWndStatic, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hb);
-- modified at 2:00 Friday 12th October, 2007
|
|
|
|
|
Try this
HDC DeskDC = GetDC(NULL);
HDC hdcMem = CreateCompatibleDC(0);
HBITMAP hb = CreateCompatibleBitmap(<font color="Red">DeskDC</font>,200,200); <font color="Red">
HGDIOBJ hOldBM = SelectObject(hdcMem,hb);
BitBlt(hdcMem,0,0,200,200,DeskDC,0,0,SRCCOPY);
SelectObject(hdcMem, hOldBM);
SetWindowLong(hWndStatic,GWL_STYLE,(GetWindowLong(hWndStatic,GWL_STYLE) & ~SS_TYPEMASK) | SS_BITMAP) ;
SendMessage(hWndStatic, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hb); *edit* Fixed my bug
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Thnx a lot.
It works. But it displays only monochrome bitmap. I.e. the image I m gettting in static control is Blak and white image.
|
|
|
|
|
I screwed up - see my modified post. Sorry about that
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thnx a lot for you help
I just made the little change and its working..................
HDC DeskDC = GetDC(NULL);
HDC hdcMem = CreateCompatibleDC(DeskDC);
HBITMAP hb = CreateCompatibleBitmap(DeskDC,200,200);
HGDIOBJ hOldBM = SelectObject(hdcMem,hb);
BitBlt(hdcMem,0,0,200,200,DeskDC,0,0,SRCCOPY);
SelectObject(hdcMem, hOldBM);
SetWindowLong(hWndStatic,GWL_STYLE,(GetWindowLong(hWndStatic,GWL_STYLE) & ~SS_TYPEMASK) | SS_BITMAP) ;
SendMessage(hWndStatic, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hb);
|
|
|
|
|
You found it....good
Cheers!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thnx,
but I am not getting what you mean by attaching the bitmap.
Is that mean to create a new bitmap in resource and use that with SelectObject() . If I use this I am getting only that bitmap in the Static control and Not the Image of BitBlt .
|
|
|
|
|
Thnx again.
But I think your code will display the (device Contex) on the Dialog or window you want. That will be cleared when window will be refreshed.
What I want is to display the DC (Device Context ) permanently
i.e. taking it first in bitmap file and then displaying that in Static Picture control.
But I am not able do with the code i have posted. It show only Black Screen (i.e. There is noting in the bitmap).
I dont know how do show the DC permanent. If there is any other simple way please tell me
|
|
|
|
|