|
s_k wrote:
__REBARBANDINFO rb;
__rb.cbSize=sizeof(REBARBANDINFO);
__// THIS IS PROBLEM FUNCTION
__RCtrl.GetBandInfo(0,&rb);
try
_REBARBANDINFO rb;
::ZeroMemory(&rb, sizeof(REBARBANDINFO));
__rb.cbSize=sizeof(REBARBANDINFO);
|
|
|
|
|
IT WORKS!!
I thank you so much!
Anyway, if you answered me this question, I would be even more happy: How is it possible that neither in debug version nor in release version without debug info no access violation appeared? Maybe I would understand difference between debug and clean release version, but what the heck is difference between, we can say, two DEBUG versions?
Thank you again, AlexO, I really appreciate your help!
|
|
|
|
|
It is very common error in debug vs. release. The problem is debug memory allocation it usually initializes memory to 0 or 0xcdcdcdcd.
Release memory is not initialized so values are random. Example:
DWORD dwSize; //not that is not initialized
SomeFunction(&dwSize);//note dwSize is in/out parameter
the example above might work in debug but will blow up in release.
|
|
|
|
|
I don't understand.
dwSize is just local variable. Its address (as passed to SomeFunction()) will be always valid, won't be? Of course SomeFunction() mustn't do something like this:
TCHAR* s = new TCHAR[dwSize];
because dwSize was not initialized, but the code you posted itself is valid as long as I don't know SomeFunction() code...
|
|
|
|
|
no, I did not mean address. Imagine that inside that function you have soemthing like
int SomeFunction(DWORD* dwSize, char* actualBuffer)
{
if(*dwSize > 0)
{
char* pCopy = new char[*dwSize];
::memcpy(pCopy, actualBuffer, *dwSize);//this is where error will manifest itself if you forgot to initialize dwSize, in release dwSize could be anything, in debug it would probably be zero so we never come here
...
}
...
}
P.S. Real scenario is usually more complex but idea is the same
|
|
|
|
|
Yes, I understand now, that's what I thought could really cause problems...
|
|
|
|
|
A few things I'd try:
1) Always test functions succeed. In particular CreateEx(), Create() etc.
2) In CMainFrame::ChangeDlgBar() add:
ASSERT_VALID( this );
ASSERT( ::IsWindow( m_hWnd );
ASSERT( ::IsWindow( m_wndDoubleDiscBar.m_hWnd ) );
__CReBarCtrl& RCtrl = m_wndDoubleDiscBar.GetReBarCtrl();
ASSERT_VALID( &RCtrl );
ASSERT( ::IsWindow( RCtrl.m_hWnd );
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Thanks Neville! Fortunately, AlexO has already found the cause of the problem - I have to call ::ZeroMemory to zero REBARBANDINFO structure. Never thought this may be reason for CWnd::FromHandlePermanent() to return NULL...
|
|
|
|
|
Yes I saw Alex's post just after I sent mine. Initialization issues like this can be hard to track down and the outcome can vary depend on what crap happens to be being set. Bottom line is your back in business.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
In debug mode build, the linker assigns bogus size storage for each block. When you accidentally forgotten to delete or deinitialize some component. The extra size storage in each other block can still cater as it had not touched the actual content. But once the linker had swicthed to release mode. All the storage blocks were optimise to it supposing size. When you have crossing action in your code, straight up a access violation will pop up.
I read this in one of codeproject article. Can't remember the title already but hope this helps.
|
|
|
|
|
I know I probably forgot to call a default class member when building some message handler or another but this is really aggravating.
I have a dialog based app and the app exits if you hit the enter key.
I really wish it didn't do this.
Could anyone help?
|
|
|
|
|
The enter key activates the default button of the dialog which is usually the Ok button..
John
|
|
|
|
|
John M. Drescher wrote:
The enter key activates the default button of the dialog which is usually the Ok button..
Thanks - I'm an idiot. That's the first thing I thought of, and I know it is true from so many other apps and is just a Windows basic user-level thing but I totally forgot about that and was mixing it up with the space bar ala the currently active control.
I guess I will change the control ID for the button. :sheepish grin:
|
|
|
|
|
tnolley wrote:
I guess I will change the control ID for the button.
Changing the control ID won't solve your problem. The most simple way is to override CDialog::OnOK(). You might want to override CDialog::OnCancel() as well, in case you don't want the dialog to get closed when you hit the escape key.
CMyDialog::OnOK(){ return; }
// Afterall, I realized that even my comment lines have bugs
When one cannot invent, one must at least improve (in bed).-My latest fortune cookie
|
|
|
|
|
|
What's the quickest way (in terms of programming time) to display an image (jpg, tif, bmp or gif) ? I thought about simply using a WebBrowser2 control, but wanted to ask here as imaging is something I've never got into so there might be a more accepted method of doing this.
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
Unless you want to study the JPEG file format and write a decoder by hand, you are better off using an image library.
I have had great results using the Victor Image Library. It is free for 30 days while you evaluate it.
It is available at:
http://www.catenary.com
The demo version of VIC32.DLL is available free for download. The commercial version of VIC32.DLL costs $499 and is included with any application that uses the VIC library. Although I would certainly pay for it if you planned on releasing software developed with it. If for whatever reason you didn't get the chance to fully evaluate it during the 30 days, (sday you got hit by a car and spent 29 days in the hospital) you could either change your system clock or do a web search for VIC32.DLL
|
|
|
|
|
No can do. This is for a chapter demo on reading BLOB data with ADO.NET. Therefore, I don't want to force the reader to have to download or install 3rd party products.
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
I forgot where I found this snippet.
You can use it in a subclassed CStatic you draw on the CDialog
in Sub Classed CStatic header
public:
void LoadPictureFile(LPCTSTR szFile);
virtual ~CSubClassStatic();
protected:
LPPICTURE gpPicture;
protected:
//{{AFX_MSG(CSubClassStatic)
afx_msg void OnPaint();
//}}AFX_MSG
in Sub Classed CStatic implementation File
#define MAX_LOADSTRING 100
#define HIMETRIC_INCH 2540
#define MAP_LOGHIM_TO_PIX(x,ppli) ( ((ppli)*(x) + HIMETRIC_INCH/2) / HIMETRIC_INCH )
void CSubClassStatic::OnPaint()
{
if (gpPicture)
{
CPaintDC dc(this); // device context for painting
// get width and height of picture
long hmWidth;
long hmHeight;
gpPicture->get_Width(&hmWidth);
gpPicture->get_Height(&hmHeight);
// convert himetric to pixels
int nWidth = MulDiv(hmWidth, GetDeviceCaps(dc.m_hDC, LOGPIXELSX), HIMETRIC_INCH);
int nHeight = MulDiv(hmHeight, GetDeviceCaps(dc.m_hDC, LOGPIXELSY), HIMETRIC_INCH);
RECT rc;
GetClientRect(&rc);
// display picture using IPicture::Render
gpPicture->Render(dc.m_hDC, 0, 0, nWidth, nHeight, 0, hmHeight, hmWidth, -hmHeight, &rc);
}
// TODO: Add your message handler code here
}
void CSubClassStatic::LoadPictureFile(LPCTSTR szFile)
{
// open file
HANDLE hFile = CreateFile(szFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE) return;
// get file size
DWORD dwFileSize = GetFileSize(hFile, NULL);
if (-1 == dwFileSize) return;
LPVOID pvData = NULL;
// alloc memory based on file size
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
_ASSERTE(NULL != hGlobal);
pvData = GlobalLock(hGlobal);
_ASSERTE(NULL != pvData);
DWORD dwBytesRead = 0;
// read file and store in global memory
BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL);
_ASSERTE(FALSE != bRead);
GlobalUnlock(hGlobal);
CloseHandle(hFile);
LPSTREAM pstm = NULL;
// create IStream* from global memory
HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pstm);
_ASSERTE(SUCCEEDED(hr) && pstm);
// Create IPicture from image file
if (gpPicture)
gpPicture->Release();
hr = ::OleLoadPicture(pstm, dwFileSize, FALSE, IID_IPicture, (LPVOID *)&gpPicture);
_ASSERTE(SUCCEEDED(hr) && gpPicture);
pstm->Release();
if (gpPicture)
{
CPaintDC dc(this);
// get width and height of picture
long hmWidth;
long hmHeight;
gpPicture->get_Width(&hmWidth);
gpPicture->get_Height(&hmHeight);
// convert himetric to pixels
int nWidth = MulDiv(hmWidth, GetDeviceCaps(dc.m_hDC, LOGPIXELSX), HIMETRIC_INCH);
int nHeight = MulDiv(hmHeight, GetDeviceCaps(dc.m_hDC, LOGPIXELSY), HIMETRIC_INCH);
}
InvalidateRect(NULL, TRUE);
}
|
|
|
|
|
I kind of forgot what this actually was, it's using the (OLE I believe?), IPicture interface to load the file/type automatically
|
|
|
|
|
|
Use OleLoadPicturePath() to get an IPicture interface, then IPicture::Render() to draw it. You could also use the shell's IExtractImage interface to generate a thumbnail, but doing so takes about 30 lines of code.
--Mike--
"Big handwavy generalizations made from a position of deep ignorance is one of the biggest wastes of time on the net today.
-- Joel Spolsky
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
|
|
|
|
|
|
Either Michael's way, or using GDI+
Graphics g(hdc);
Image img(imageFileName);
g.DrawImage(x, y, &img);
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I am developping application like photoshop
and have problem with making the title bar of dialog
boxes blue(just like when you activate dialog box,
but this time I want to make 2 or 3 dialog boxes
activated status). Any comments could be helpfull
Thank you in advance.
Shinya
|
|
|
|