|
George_George wrote: Do you have any documents support this claim? Even if we turn off string pooling?
C++ specifications? See below.
George_George wrote: I read your referred article, I think it has nothing to do with OLESTR, but dealing with write to const data? Right?
You're wrong.
First of all OLESTR are string literals [^].
Have you read "Const Storage and String Literals" section, it reports the following excerpt:
The C++ standard (section lex.string) states:
1 A string literal is a sequence of characters (as defined in
_lex.ccon_) surrounded by double quotes, optionally beginning with the
letter L, as in "..." or L"...". A string literal that does not begin
with L is an ordinary string literal, also referred to as a narrow
string literal. An ordinary string literal has type "array of n const
char" and static storage duration [...]
Static storage duration means that memory for literals is allocated when the program begins running and is freed when the program terminates.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Thanks CPallini!
Question answered. You are so knowledgable.
regards,
George
|
|
|
|
|
Well, I've Google, after all.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Cool, CPallini!
regards,
George
|
|
|
|
|
Perhaps this will help:
#include "stdafx.h"
#include <iostream>
#include <windows.h>
using namespace std;
bool IsOnStack(const void *pData)
{
DWORD StackBase;
DWORD StackLimit;
__asm
{
MOV EAX, DWORD PTR FS:[0x04]
MOV StackBase, EAX
MOV EAX, DWORD PTR FS:[0x08]
MOV StackLimit, EAX
}
DWORD Address = reinterpret_cast<DWORD>(pData);
return (Address >= StackLimit) && (Address < StackBase);
}
const char* PrintStack(const void *pData)
{
return IsOnStack(pData) ? ": Stack" : ": Not on Stack";
}
int main(int argc, char* argv[])
{
const char *pString1 = "String1";
cout << pString1 << PrintStack(pString1) << endl;
char String2[] = "String2";
cout << String2 << PrintStack(String2) << endl;
return 0;
}
Output is:
String1: Not on Stack
String2: Stack
Steve
|
|
|
|
|
Cool, Steve.
MOV EAX, DWORD PTR FS:[0x04]
MOV StackBase, EAX
MOV EAX, DWORD PTR FS:[0x08]
MOV StackLimit, EAX
What is function of FS:[0x04] and FS:[0x08]?
regards,
George
|
|
|
|
|
Do a Google search on the "Thread Information Block" (TIB) or, as it's also known as, the "Thread Environment Block" (TEB).
Steve
|
|
|
|
|
|
|
Thanks Hamid,
I think this link does not relat to my question. My question is whether or not the OLESTR variable is on stack or on heap. Any comments or ideas?
regards,
George
|
|
|
|
|
Oh I think it was my mistake.
|
|
|
|
|
It is ok, Hamid!
At least you have made us to find something new.
regards,
George
|
|
|
|
|
I glad it was al little help for you.
|
|
|
|
|
I have one static library named c.lib, in which there is a global member int gC;
Two other modules, a.exe and b.dll(regular dll using mfc), link to c.lib.
I found that the address of gC is different in a.exe between in b.dll.
Is it strange?
How can I make only one global int gC?(but used both in c.lib, b.dll, and a.exe)
|
|
|
|
|
How you are refering or Declaring the variable gC for a.exe and c.lib ?
|
|
|
|
|
I define int gC in a cpp file in the static library project.
In b.dll and a.exe, when I want to use gC, I use extern int gC ;
|
|
|
|
|
code_discuss wrote: found that the address of gC is different in a.exe between in b.dll.
Is it strange?
No, because the individual modules get their own personal instance of the variable.
Two of the possible solutions are
1) Put the common static library code in a DLL instead.
2) Use conditional compilation to only create the variable in on module (i.e. in the DLL module only)
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi all,
I am want to create Editor window in my application using MFC.
Please help how to start with this.
It include feautures like inserting break points and highligting it.
I am using Visual Studio 2005 environment.
Regards
Suhi
|
|
|
|
|
Well, that's a rather vague question. Please take a look at the posting guidelines at the top of this forum.
It all depends of what you knows. If you are new to MFC, then I strongly suggest reading a good book on the subject. If you know MFC, then you should ask a more precise question.
|
|
|
|
|
I think you can find articles on the codeproject about it.
|
|
|
|
|
hi!
I have an MFC application which is taking i/p from mouse,
when i put this application on the Tablet PC, as
input device is stylus this application doesn't work, while
other applications works properly,
what changes i need to do in the application, suggest any
tutorials that could help me out.
|
|
|
|
|
|
how to render32 bit bmp with alpha chanel on devicecontext
Trioum
|
|
|
|
|
You can use the AlphaBlend() function...
Here's an example:
LONG lImageWidth = 640;
LONG lImageHeight = 480;
WORD wBitsPerPixel = 32;
LONG lBytesPerRow = lImageWidth * 4;
BYTE* pBitmapBits;
BITMAPINFO bmi;
memset(&bmi, 0, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = lImageWidth;
bmi.bmiHeader.biHeight = lImageHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = wBitsPerPixel;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = lBytesPerRow * lImageHeight;
HDC hdc = ::CreateCompatibleDC(0);
HBITMAP hBitmap = ::CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&pBitmapBits, NULL, 0);
if (hBitmap)
{
<font color="Green">
RGBQUAD *pCurPixel = (RGBQUAD *)pBitmapBits;
int PixelCount = lImageWidth * lImageHeight;
while (PixelCount > 0)
{
(*pCurPixel).rgbRed = 0x00;
(*pCurPixel).rgbGreen = 0x00;
(*pCurPixel).rgbBlue = 0xA0;
(*pCurPixel).rgbReserved = 0x80; <font color="Green">
pCurPixel++;
PixelCount--;
}
HGDIOBJ hOldBitmap = ::SelectObject(hdc, hBitmap);
HDC hClientDC = ::GetDC(*this);
HPEN hPen = ::CreatePen(PS_SOLID, 10, RGB(255,0,128));
HGDIOBJ hOldPen = ::SelectObject(hClientDC, hPen);
::MoveToEx(hClientDC, 0, 0, NULL);
::LineTo(hClientDC, 650, 490);
::SelectObject(hClientDC, hOldPen);
::DeleteObject(hPen);
BLENDFUNCTION bf;
bf.BlendOp = AC_SRC_OVER;
bf.BlendFlags = 0;
bf.SourceConstantAlpha = 0xFF;
bf.AlphaFormat = AC_SRC_ALPHA;
::AlphaBlend(hClientDC, 0, 0, lImageWidth, lImageHeight,
hdc, 0, 0, lImageWidth, lImageHeight, bf);
::ReleaseDC(*this, hClientDC);
::SelectObject(hdc, hOldBitmap);
::DeleteObject(hBitmap);
}
::DeleteDC(hdc);
Using GDI+ it's easier
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I am use both code using GDI and GDI+ but alpha channel portion of image
appeared as white
Trioum
|
|
|
|
|