|
|
By default, a dialog's OnOK() handler will be called when you "press" the Enter key from within an edit control. If you would rather the edit control do something else, check out the ES_WANTRETURN style.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
char buffer[50]
int offset =3;
char Buffer[250];
sprintf_s(&buffer[offset],offset,"%s",Buffer);
When we use the above funcation and application crashed with the folloing message
---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!
Program: xyz.exe
File: f:\dd\vctools\crt_bld\self_x86\crt\src\vsprintf.c Line: 244 Expression: ("Buffer too small", 0)
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
---------------------------
Abort Retry Ignore
---------------------------
OS used : Windows 7 32bit OS
Microsoft Visual Studio 2008 (VC++)
Version 9.0.30729.1SP
|
|
|
|
|
Second parameter of sprintf_s is the size of destination buffer.
If length of formatted string is greater than the size of source buffer, sprintf_s will create debug assertion.
If length of string in Buffer is less than 3, then it will not create an debug assertion.
Here you can change the second parameter of sprintf_s to 47,by considering offset in buffer.
|
|
|
|
|
char buffer[50]
int offset =3;
char Buffer[250];
OR
char buffer[50]
int offset =3;
char Buffer[50];
Is working fine with VS6.0, but when the same code is compiled with VS2008 I am still getting the same error as mentioned above.
|
|
|
|
|
Which function is used in VC6.0 ? Is it sprintf() or sprintf_s() ?
If it is sprintf(), then nothing to wonder, becausee sprintfdoesnot check the output buffer size.
|
|
|
|
|
Member 9353776 wrote: sprintf_s(&buffer[offset],offset,"%s",Buffer);
Here you are stating your destination buffer has size 3 (parameter 2 of sprintf_s (see MSDN[^]). If the source buffer (namely Buffer ) contains a string with more than 3 characters then you get the assertion.
Veni, vidi, vici.
|
|
|
|
|
char buffer[50]
int offset =3;
char Buffer[250];
OR
char buffer[50]
int offset =3;
char Buffer[50];
Is working fine with VS6.0, but when the same code is compiled with VS2008 I am still getting the same error as mentioned above.
|
|
|
|
|
Short answer: You sprintf statement is plain wrong if 'it is working fine' maybe by accident.
Somewhat longer answer: If you have a 50 bytes buffer, why don't you pass 50 instead of 3 ? Why are you using the misleading name offset for passing a size?
Veni, vidi, vici.
|
|
|
|
|
First thing is that, trust the implementation made by Microsoft. This is a very primitive function and you will have to read the documentation first.
Second you can your strcpy_s or strcat_s (if you're concatenating). sprint_s is not really a choice string copy.
Third your strings must be null terminated.
To understand this better, I am illustrating this with a code example
char buffer[12]= {0};
int offset =3;
char Buffer[50] = "Hello World";
sprintf_s(buffer,sizeof(buffer), "%s", Buffer);
in the above example buffer has 12 character in legnth and Hello World String contains 11 characters + null terminated. Anything less than 12 character size will raise assertion buffer too small. for sprintf_s only the number of characters being copied only matters. not really the original size of the buffers.
-Sarath.
Rate the answers and close your posts if it's answered
|
|
|
|
|
I have fixed the issue,
I am very much thankful to all your replies
|
|
|
|
|
I can just find the BIOS offset(0xFE000)using SMBIOS structures,but do not know the detail of the info it disp in WinHex tool.
|
|
|
|
|
Take a look at some of these links[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Hello. I'm currently extending an options risk application that makes use of Gunnar Bolle's neat little charting control. I'm trying to get a handle on the functionality by looking at the code but it would GREATLY speed things up if I could communicate with someone who is versed in the control. What I need to do is pretty basic; labeling, editing, scaling, etc. Any help would be greatly appreciated.
|
|
|
|
|
You could try posting a message in the forum at the end of the article so he sees it.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I already tried that. I'm thinking of putting out an international APB.
|
|
|
|
|
I have the follow code :
CSize sizeDoc = pDoc->GetBitmapSize();
CDC MemDC, TempDC;
MemDC.CreateCompatibleDC(pDC);
TempDC.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = MemDC.SelectObject(&pDoc->GetBitmap());
pDC->SetStretchBltMode(HALFTONE);
TempDC.StretchBlt(0, 0, sizeLog.cx, sizeLog.cy, &MemDC, 0, 0, sizeDoc.cx, sizeDoc.cy, SRCCOPY);
pDC->StretchBlt(0, 0, sizeLog.cx, sizeLog.cy, &TempDC, 0, 0, sizeDoc.cx, sizeDoc.cy, SRCCOPY);
pDC->SelectObject(pOldBitmap);
and on view I see nothing ... what I'm doing wrong ? TempDC don't have the same structure like MemDC ? Because if I do so:
CSize sizeDoc = pDoc->GetBitmapSize();
CDC MemDC, TempDC;
MemDC.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = MemDC.SelectObject(&pDoc->GetBitmap());
pDC->SetStretchBltMode(HALFTONE);
pDC->StretchBlt(0, 0, sizeLog.cx, sizeLog.cy, &MemDC, 0, 0, sizeDoc.cx, sizeDoc.cy, SRCCOPY);
pDC->SelectObject(pOldBitmap);
everything it's ok ...
|
|
|
|
|
CSize sizeDoc = pDoc->GetBitmapSize();
CDC MemDC, TempDC;
MemDC.CreateCompatibleDC(pDC);
TempDC.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = MemDC.SelectObject(&pDoc->GetBitmap());
pDC->SetStretchBltMode(HALFTONE);
TempDC.StretchBlt(0, 0, sizeLog.cx, sizeLog.cy, &MemDC, 0, 0, sizeDoc.cx, sizeDoc.cy, SRCCOPY);
pDC->StretchBlt(0, 0, sizeLog.cx, sizeLog.cy, &TempDC, 0, 0, sizeDoc.cx, sizeDoc.cy, SRCCOPY);
pDC->SelectObject(pOldBitmap);
When a memory device context is created, GDI automatically selects a 1-by-1 monochrome stock bitmap for it. GDI output functions can be used with a memory device context only if a bitmap has been created and selected into that context.
Here TempDC is not attached to any Bitmap, and therefore GDI function StretchBlt will not draw to TempDC.
You have to create a Bitmap compatible to your DC, and attach the same to temperory memory DC.
CSize sizeDoc = pDoc->GetBitmapSize();
CDC MemDC, TempDC;
MemDC.CreateCompatibleDC(pDC);
TempDC.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = MemDC.SelectObject(&pDoc->GetBitmap());
pDC->SetStretchBltMode(HALFTONE);
HDC hdc = ::GetDC(NULL);
HBITMAP hScreenBmp = CreateCompatibleBitmap( hdc , nWidth, m_nImageHeight );
TempDC.SelectObject( hScreenBmp );
TempDC.StretchBlt(0, 0, sizeLog.cx, sizeLog.cy, &MemDC, 0, 0, sizeDoc.cx, sizeDoc.cy, SRCCOPY);
pDC->StretchBlt(0, 0, sizeLog.cx, sizeLog.cy, &TempDC, 0, 0, sizeDoc.cx, sizeDoc.cy, SRCCOPY);
pDC->SelectObject(pOldBitmap);
|
|
|
|
|
Thank you so much, is working now.
|
|
|
|
|
private:
PROCESSENTRY32 * m_proc;
char * m_filename;
bool m_stringupdated;
Process::Process()
{
m_proc = new PROCESSENTRY32;
m_proc->dwSize = sizeof(PROCESSENTRY32);
m_stringupdated = false;
m_filename = NULL;
}
Process::~Process()
{
delete m_proc;
if(m_filename)
delete [] m_filename;
}
Process * allo = new Process();
allo->~Process();
VLD reports:
Visual Leak Detector Version 2.2.3 installed.
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 1 at 0x005A2100: 12 bytes ----------
Call Stack:
c:\users\jean\documents\visual studio 2012\projects\procenum\procenum\procenum.cpp (26): ProcEnum.exe!wmain + 0x7 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (533): ProcEnum.exe!__tmainCRTStartup + 0x19 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (377): ProcEnum.exe!wmainCRTStartup
0x760A33AA (File and line number not available): kernel32.dll!BaseThreadInitThunk + 0x12 bytes
0x76CF9EF2 (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x63 bytes
0x76CF9EC5 (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x36 bytes
Data:
48 21 5A 00 00 00 00 00 00 CD CD CD H!Z..... ........
Visual Leak Detector detected 1 memory leak (48 bytes).
Largest number used: 640 bytes.
Total allocations: 640 bytes.
Visual Leak Detector is now exiting.
The program '[10680] ProcEnum.exe' has exited with code 0 (0x0).
I'm freaking out guys I just don't see the leak ,Thanks in advance .
|
|
|
|
|
How many bytes allocated and pointed by m_filename?
|
|
|
|
|
it's not used ,its deallocating it anyway...
|
|
|
|
|
If the sizeof(PROCESSENTRY32) == 48, then I have found your leak.
|
|
|
|
|
not that either it's around 500~ bytes and I'm deallocating that too :/
|
|
|
|
|
I cant see any memory leak in the given code.
Please check memory leak without allocating memory Process.
|
|
|
|
|