|
I don't know about third-party leak detectors.
I do use the CRT heap debugging features in my debug builds.
This goes on top (under the (#include lines) of all my source files:
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
For leaks that still don't give file/line number info...
In the debug output for the leaks, if the number in the curly braces is the same every time
you can add a breakpoint to break when those allocations occur.
See How to: Set Breakpoints on a Memory Allocation Number[^]
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thank you for the information, it is very interesting, but the problem again. All the time I'm getting problem on allocations 59 and 60.
{60} normal block at 0x02721790, 12 bytes long.<br />
Data: < r r > 90 17 72 02 90 17 72 02 CD CD CD CD <br />
{59} normal block at 0x027217D0, 44 bytes long.<br />
Data: <|hm am am r > 7C 68 6D 02 80 61 6D 02 88 61 6D 02 10 1B 72 02 <br />
Object dump complete.<br />
but _CrtSetBreakAlloc(60); results in no break. Why can it be? I'm using VC++ 6, but there are no reasons to assume that it doesn't support this function.
|
|
|
|
|
I want to download the latest platform SDK for visual c++ based development. If I use google to locate it, I am being taken to a page at Microsoft which says Windows 2003 server sdk. If I search MS for SDK, there are plenty of results and I am confused. Can someone give me a link where I could download the latest platform SDK? Thanks.
Sorry if it is posted twice. There was error, when I attempted previously. I will delete one, if it is posted twice.
|
|
|
|
|
Windows Server 2003 R2 sdk
that is to the best of my knowneldge is the latest sdk for vc++ developers
p.s its name is a bit miss leading but thats the one
|
|
|
|
|
If you're using VS05, the latest & greatest SDK is now called the Windows SDK[^].
|
|
|
|
|
looks like i need to upgrade my SDK
thanks
|
|
|
|
|
Ive looked around on getting inputs from the LPT port on windows xp, apparantly I need a dll called inpout32.dll. I have that, however I wonder how I should "include" the file? So that i can use the code described on http://www.ctv.es/pckits/tutorial.html#ppro and its functions
Ive looked around alot on codeproject, and google around 50 times, but not found how to get it to work...
any ideas?
Im open to other methods too, but nothing too advanced.
PS, im in win32console with mfc on winxp, i will only be using lpt inputs, two of them.
thanks!
//Johannes
|
|
|
|
|
I've developed a program that performs some mathematical operations and then exports the results into a csv file to be opened with Excel.
To export the results I used a while loop with incremental values and that's fine but now I'd like to save (and read) some results in (or from) very specific locations (e.g. 6th case of the 2nd row).
I am using C++ and the Win32 Console application in VS2005.
Does anybody know how to do that?
Many thanks for your help.
|
|
|
|
|
J_E_D_I wrote: ...I'd like to save (and read) some results in (or from) very specific locations (e.g. 6th case of the 2nd row).
Without also writing to the first row, and the other five cases of the second row?
"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
|
|
|
|
|
Correct!
Is it possible to read and write to and from very specific locations leving the rest unchanged?
I will be happy only when I will have FULL contol over this nasty language!
|
|
|
|
|
J_E_D_I wrote: Is it possible to read and write to and from very specific locations leving the rest unchanged?
Probably, but I would find it a lot easier to read the file into some sort of data structure, make the necessary changes, and write the data structure back to disk.
"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
|
|
|
|
|
Hi all,
I am transferring to .NET 2003 to .NET 2005 now. I have one application made in Visual C++.NET 2003. It is compiling fine in .NET 2005 but it gives one run time error at ShowDialog() function of OpenFileDialog Class object. Error is
"An unhandled exception of type 'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll
Additional information: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process."
Can I know what is wrong with this? And how can I solve this problem.
Thanks in advance,
Priyank
|
|
|
|
|
This should be posted on the Managed C++/CLI board.
I'm not sure what threads have to do with using the OpenFileDialog, but the error message is
pretty descriptive - it even states how to fix it.
Which version of ShowDialog() are you using?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
"Ensure that your Main function has STAThreadAttribute marked on it."
Have you tried this?
|
|
|
|
|
Are you switching to the "dark side of the force"?
Steve
|
|
|
|
|
I think Mike's onto something here; the error message is describing exactly what's wrong. See here[^] for more details.
Steve
|
|
|
|
|
I am using Visual Studio 2005, with Visual C++, and have generated a single docuemnt project with mainframe and childview for MFC.
I want to display parts of an image that the program loads from a bitmap file, on a grid pattern as produced by CGrid class in Grid.h and Grid.cpp.
When I use the StretchBlt function, the program asks for a HDC!!!!
I have not found litterature or samples for the use of that device context.
Would you know of a solution?
Thanks for any help....
Here is a possible code section for my function. With it, I can enter a string but not the image. It creates a CDC* but not a HDC. How should I code the HDC?????
void CGrid::FillCell(int r, int c, CString val, COLORREF brushColor, CImage m_Image)
{
CWnd* pWnd = AfxGetMainWnd();
CDC* pDC = pWnd->GetDC();
// pDC->BitBlt(0,0,20,20,pDC,0,0,SRCCOPY);
CBrush* pBrush;
pBrush = new CBrush (brushColor);
pDC->FillRect (mGrid[r][c],pBrush );
delete pBrush;
pDC->SetBkMode (TRANSPARENT);
pDC->SetTextColor (mStringColor);
pDC->DrawText(val,-1,mGrid[r][c],
DT_SINGLELINE |
DT_CENTER |
DT_VCENTER
);
// m_Image.StretchBlt(pDC,mGrid[r][c].TopLeft().x,mGrid[r][c].TopLeft().y,mGrid[r][c].Width(),mGrid[r][c].Height(),mGrid[r][c].TopLeft().x,mGrid[r][c].TopLeft().y,mGrid[r][c].Width(),mGrid[r][c].Height(),SRCCOPY);
// pDC->StretchBlt(mGrid[r][c].TopLeft().x,mGrid[r][c].TopLeft().y,mGrid[r][c].Width(),mGrid[r][c].Height(),m_Image,mGrid[r][c].TopLeft().x,mGrid[r][c].TopLeft().y,mGrid[r][c].Width(),mGrid[r][c].Height(),SRCCOPY);
pWnd->ReleaseDC(pDC);
}
guybour
|
|
|
|
|
Is the destination grid pattern on a window?
If so, then your code should work. Instead of trying to pass "pDC" as the destination DC,
pass "*pDC". This forces the compiler to use the CDC (HDC) cast operator to extract the HDC from
the CDC object. CDC is a C++ wrapper for an HDC.
You may need to get a DC for the window the grid is on, not the main frame window. The main
frame window is covered by a child view window. The view window is the one you want the DC for,
or whichever window you want to draw the image on.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
For starters, if you are trying to draw on on the view, you are getting a DC for the wrong window. Your getting a DC for the main frame window. From within you view class code, just use "this" since it is a pointer to the view/wnd
CDC* pDC=this->GetDC();
// or
CDC* pDC=GetDC();
Next, make sure the drawing code is in or called from the views OnDraw handler since anytime you drag another window over the view it will erase your drawing like an eraser. The OnDraw will get called and if your drawing code is not there to refresh the image, nothing will happen.
Next make sure you have the correct coordinate system for your drawing. The default mapping mode is MM_TEXT (y-axis positive as it goes down) all other mapping modes like MM_HIMETRIC, MM_HIENGLISH, etc... have the y-axis negative as it goes down. MM_ANISOTROPIC and MM_ISOTROPIC allow you to set the y-axis orientation. I've spent many an hour chasing my tail because my y-axis orientation was incorrect.
// The handle is a member of CDC. To access it use the arrow operator
pDC->m_hDC
// Something like
m_Image.StretchBlt(pDC->m_hDC, etc...
I hope that helps
|
|
|
|
|
Hi. I've been quite a while out of C++, wasn't expert before either. But right now, I got a really strange problem with strcpy. Maybe somebody can help? : )
<br />
char cBuffer[256];<br />
char cTemp[260];<br />
<br />
<br />
char ch = cBuffer[0];
strcpy(cTemp, "R");
strcpy(cTemp, &ch);
So what should I do to put ch in cTemp???
Thank you in advance...
|
|
|
|
|
If you just want to copy the first character from cBuffer to cTemp , then just do:
cTemp[0] = cBuffer[0]; If you want to copy the entire string, then:
strcpy(cTemp,cBuffer); From your example, remember that ch is only a single character. There is no space for a terminating '\0' , so the strcpy is terminating on whatever random garbage follows the ch variable in the stack.
Software Zen: delete this;
|
|
|
|
|
This is really weird. Watch this! I will give you the relevant pieces of code where cTemp and cBuffer are involved. This is really strange for me.
<br />
<br />
char cTemp[260];
char cTemp2[260];
char cBuffer[256];
<br />
GetModuleFileName(0, cTemp, 249);<br />
<br />
ReadFile(hFile, cBuffer, sizeof(char)*256, &dwNumRead, NULL);<br />
<br />
strcpy(cTemp2, cBuffer);
strcpy(cTemp, cBuffer);
<br />
HOWEVER!!! If I move the declaration for cTemp2 straight before the strcpy, it works!!! Like this:
<br />
char cTemp2[260];
strcpy(cTemp2, cBuffer);
sTemp = cTemp2;<br />
Why does it work !?!?!?!?!? What does anything have to do with where I declare the variable !??!!?
I'll give you the full code, maybe there's something there I missed. There are some things here which you won't understand, but try not to get stuck in my local program logic. ASDANSIString is a class I made to work easier with strings. It's a wrapper over a char*, quite similar to the String class in .Net, it has lots of parsing methods incorporated in it.
<br />
<br />
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)<br />
{<br />
ASDANSIString sTemp;
HANDLE hFile;
MSG msgPump;
DWORD dwNumRead;
long lCounter;<br />
char cTemp[260];
<br />
char cBuffer[256];
<br />
bReady = false;
lTimerID = SetTimer(0, 0, 1000, (TIMERPROC)TimerProc);
<br />
GetModuleFileName(0, cTemp, 249);
sTemp = cTemp;
sTemp = sTemp.SubStringA(0, sTemp.IndexOfRev("\\", 0));
sTemp += "\\Window Name.txt";
<br />
hFile = CreateFile(sTemp, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); <br />
ReadFile(hFile, cBuffer, sizeof(char)*256, &dwNumRead, NULL);<br />
CloseHandle(hFile);<br />
<br />
char cTemp2[260];
strcpy(cTemp2, cBuffer);<br />
sTemp = cTemp2;<br />
<br />
MessageBox(0, sTemp, "Test", 0);<br />
<br />
while (!bReady && GetMessage(&msgPump, NULL, 0, 0))
{<br />
TranslateMessage(&msgPump);<br />
DispatchMessage(&msgPump);<br />
}<br />
<br />
return 0;<br />
}<br />
<br />
|
|
|
|
|
Remember that ReadFile() is not a CRT function - it makes no guarantees about nul-terminating the data it reads. Try this, it will probably work:
char cBuffer[256] = { 0 };
|
|
|
|
|
Indeed you are right. This solved all the strange problems I've been seeing, even though I still can't explain why (in the above post) declaring a char just before the strcpy did not crash. Well, too much to do today to busy myself with finding that out : (... guess it'll remain to be checked out in the future : D. Thank you very much. You're in the "Thanks To..." list : D. You'll soon see where (in what software... but don't worry, it's free, you made a good deed).
EDIT:
I've been thinking about this and maybe it's perhaps when I declare the char[] before reading from that file, the char is initialized by C++ while when declaring it after reading from the file it is not? Hmmmmmm. Doesn't make much sense. Hrmph... whatever...
|
|
|
|
|
Axonn Echysttas wrote: ReadFile(hFile, cBuffer, sizeof(char)*256, &dwNumRead, NULL);
Try this:
ReadFile(hFile, cBuffer, sizeof(char)*256, &dwNumRead, NULL);
cBuffer[dwNumRead] = '\0';
strcpy(cTemp2,cBuffer); As mentioned elsewhere, ReadFile simply reads bytes from a file. It does not guarantee that a terminator is placed in the destination. The line I've added places a '\0' terminator after the data read, so that it's safe later on to perform the strcpy .
Software Zen: delete this;
|
|
|
|
|