|
char *text = new (char) (100);
What are you trying to do here?
1. Allocate 100 characters?
2. Allocate 1 character initialized to 100?
The code does #2. If you want to do #1:
char *text = new char [100];
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
LOL, well ok.
Don't say I didn't try to help.
You might want to actually try to debug you code and see exactly what "char *array = new (char) (count)" actually does. Which is what I did. It equates to the code:
char *array = new char [1];
array [0] = count;
new operator
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
sorry tim, i didn't mean to sound or act rude, i very much appreciate your concern. i tried what you're suggesting, and i can't get it to work here.
thanx for your help, again.
imran.
|
|
|
|
|
well, what should i say, you're absolutely right. i'm awfully sorry for my stubborness, but i'll find an excuse, i've been awake all night...
imran.
|
|
|
|
|
Heh, no problem.
I just hope I didn't come across too bitchy.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Are you by any chance calling code in a non-MFC DLL from an MFC app? (Beware of heap issues).
/ravi
"There is always one more bug..."
ravib@ravib.com
http://www.ravib.com
|
|
|
|
|
hhh wrote:
hi to all the great developers out there!
what could be the reason for a program to crash at the last statement i=e, return 0?
the message is something like the instruction at location xxxx tried to reference memory at location xxxx. the memory could not be written.
please help, i'm stuck!
What is your problem ? Why are you deleting all your posts ?
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
i guess there were a lot of useless posts there by me! but my problem seems to have been solved, thanx to Tim, and to you all, really.
imran.
|
|
|
|
|
I apologize for not getting back to you. I'm glad Tim was able to help and you're up and running.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Hi all,
I'm using multiple languages in my Windows ...
For example: English US - French !
I wanna is any function or way for changing language ?
For example, i'm writing text in Notepad ...
Then i running my program, i wanna change my language from English to French, programitically !
Help me !
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Take a look at GetKeyboardLayout and ActivateKeyboardLayout APIs.
|
|
|
|
|
There's a following problem:
I use ADO to get some recordset from SQLServer2000.
the sql string is the following:
select * from Orders where EmployeeID='1' FOR XML AUTO
As You can see, I want the results to be in XMLform.
The problem is that sometimes (very often, when I want a
huge amount of data) the returned XML is not well formed !.
Of course I supply the single root element for entire
output (e.g wrapping everything in <some_element>).
The error is very subtle:
sometimes within document there are new-line characters in places
where they cant be .They are within attributes names.
For example:
ShipName="Bon app'" ShipAd
dress="12, rue des Bouchers" ShipCity="Marseille"
You can see that ShipAddress attribute is divided to
2 lines, whlist it must not.
The string I get is in this form immediately after having been
returned by the SQLSever (ADO method call) . Later, w hen I load
it using MSXML Parser
it seems to be not-well-formed. Also when saved the returned
string to file, and opened it with XML spy , it declares that
the file is wrong (not-well-formed), indicationg the very errors.
I use (I guess) the oldest version of SQLSrv2000 => this means
that it's without any patches or upgrades (if it matters anything)
What should I do to solve the problem ?
Please Help
Michal Januszczyk
|
|
|
|
|
I got some code contains a loop which execuates for about 20000 times.How can
I step into the 10000th execuation?
|
|
|
|
|
> How can I step into the 10000th execuation?
Conditional Breakpoints.
Open the Breakpoints dialog (Edit-Breakpoints or Alt+F9 in DevStudio 6.0), specify the location (or select a previously marked Breakpoint, which is easier), and then click on Condition... to specify a condition for the Breakpoint.
Peace!
-=- James.
|
|
|
|
|
Your condition should be something like
i == 10000
Todd Smith
|
|
|
|
|
if (i == 10000)
__asm int 3;
It is faster than conditional breakpoints.
I vote pro drink
|
|
|
|
|
Hi,
I´m trying to get the size of the paper when printing ( I just want to fit a metafile in the size of the paper), to get the size of the paper I tried this:
CSize himetricPrinter(pDC->GetDeviceCaps(HORZSIZE)*100, pDC->GetDeviceCaps(VERTSIZE)*100);
pDC->HIMETRICtoDP(&PaperSize); // Printer DC
The that value I use it to play the metafile.
And then I got wrong values ( For the Y axis). Can anybody help me ?, Thanks, Bye !
Braulio
|
|
|
|
|
I am having troubles loading a string from a binary file. My original problem was that it the string had wierd characters on the end when I was using this code (I am not using MFC):
HANDLE hFile = CreateFile(szFN, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
DWORD read = 0x00000000;
TCHAR szTest[9];
ReadFile(hFile, &szTest, 9, &read, NULL);
I realised that if I let 'szTest[9] = NULL', there would be no wierd characters at the end and it worked. However, when I do something like,
if (szTest == "BLABLABLA")
{
MessageBox(NULL, "It Worked", "", MB_OK); // Lets me know that it worked!
};
even though "BLABLABLA" is correct it doesn't recognise it. Is it because there is a NULL character now on the end (szTest[9])?
Any help would be greatly appreciated,
James Bird - birdjames@bigfoot.com
|
|
|
|
|
ReadFile reads binary data. If you don't put \0 in your file, it won't read it. You have two solutions:
1. When you write to the file, write a \0 at the and of your string, and when you read the string, read \0 with it.
2. Read the text, and then add the \0 at the end:
<br />
HANDLE hFile = CreateFile(szFN, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);<br />
<br />
DWORD read = 0x00000000;<br />
TCHAR szTest[10];<br />
ReadFile(hFile, &szTest, 9, &read, NULL);<br />
szTest[9] = '\0';<br />
And use strcmp for comparing two strings.
I vote pro drink
|
|
|
|
|
No, your problem is a different one. It't the difference between "equal" and "same" you are falling over. The Statement
if (szTest == "BLABLABLA")
compares two character pointer if they are equal. Or in other words: The statement returns true, iff both string references refer to the same object (same address in memory). However, what you want to know is if the two strings are equal, which means that boths string buffers contain the same value. For this you need the strcmp() CRT call:
if( strcmp( szTest, "BLABLABLA" ) == 0 )
Daniel
--
Daniel Lohmann
http://www.losoft.de
|
|
|
|
|
You problem is two-fold.
The first problem was already mentioned: your use of "==" will compare two pointers, not test for equality between two strings.
The second problem (garbage characters) stems from the fact that C-Style character strings are normally terminated with a NUL (not NULL) character. That NUL character tells whatever routine is manipulating the string where the end of the string is. You will see garbage characters after your read in your 9 characters because whatever is displaying the string is going to keep showing characters until it finds the terminating NUL.
While you do not need to write out the terminating NUL character when you write the string to a file (text or binary), you need to have that NUL there after you read it in (you can manually place it in the buffer) in order to have it treated as a C-Style string. That is basically what you did when you had
szTest[9] = NULL in your code.
(BTW: Your code writes the NULL/NUL off the end of the allocated array. Character arrays that are going to contain C-Style strings should always 1 be character larger than the maximum length of the string.)
Peace!
-=- James.
|
|
|
|
|
Hi,
I have a metafile, and I want to print it at full size of the page ( full size in A4, and A3 as well), what I thought is in the playMetafile method give the width and the height of the paper, but... it doesn´t work for me, I have tried:
CSize himetricPrinter(pDC->GetDeviceCaps(HORZSIZE)*100, pDC->GetDeviceCaps(VERTSIZE)*100);
CSize sizePrinterDP(HimetricPrinter.cx, HimetricPrinter.cy);
pDC->HIMETRICtoDP(&sizePrinterDP);
::PlayEnhMetaFile(hPrinterDC, hEnhMetaFile,
CRect(0, 0, (sizePrinterDP.cx), (sizePrinterDP.cy)));
Where is the error ?, Thanks Bye !
Braulio
|
|
|
|
|
Dear friends,
There is an MFC Sample called DRAWCLI provided in MSDN which is a drawing application with Visual Editing
container support. Basically you can draw rectangles, circles and polygons and these shapes are represented
as separate objects which can be moved, resized, filled with color etc. (CDrawObj is the base class
and individual classes have been derived from CDrawObj for each kind of shape)
Now I want to add a feature of rotating these objects. I do not want any fancy rotation using the mouse (like in Microsoft Word). The user will
simply enter the degrees to be rotated in a dialog and the object has to rotate after that.
I have tried this by changing the World transformation (using the SetWorldTransform function) specifying
appropriate XFORM values just before drawing the object ( say a rectangle) and set the transformation
back to normal after the rectangle is drawn and I am able to rotate the rectangle by the required degrees
although a part of the rectangle is hidden.
What I am unable to do is other operations like selecting, moving etc after rotating the rectangle since
the coordinates defining the rectangle (a CRect object) still are the same even after rotation. All
operations like invalidating, detecting mouse clicks (hit-testing) on the rectangle are based on its CRect object
which stores its position.
How can I update or store the coordinates of this rotated rectangle.
OR
If I am going in a totally wrong direction please tell me a better way to accomplish this
|
|
|
|
|
First I will try to solve the simple problem ("am able to rotate the rectangle by the required degrees
although a part of the rectangle is hidden"). I think every object should be rotated around it's top-left vertex. In this case I use two functions which prepare DC state to draw the object:
// Set device context to new state:
// every object drawn after call to this function will be rotated
// to nAngle degrees around (x, y) point.
// Rotation direction: positive - clockwise
//
void CWorldTransform2View::SetRotation(CDC* pDC,
int x,
int y,
int nAngle) // degrees
{
double dAngle = nAngle * PI_X_2 / 360.0; // PI_X_2 is pi*2
XFORM xForm;
xForm.eM11 = (FLOAT) cos(dAngle);
xForm.eM12 = (FLOAT) sin(dAngle);
xForm.eM21 = (FLOAT) (-sin(dAngle));
xForm.eM22 = (FLOAT) cos(dAngle);
xForm.eDx = (FLOAT) 0.0;
xForm.eDy = (FLOAT) 0.0;
int x1, y1;
x1 = (int) ( (x * cos(dAngle)) - (y * sin(dAngle)) );
y1 = (int) ( (x * sin(dAngle)) + (y * cos(dAngle)) );
GetViewportOrgEx(pDC->m_hDC, &m_PointOrigin);
SetViewportOrgEx(pDC->m_hDC, -x1 + x, -y1 + y, NULL);
m_nGraphicsMode = GetGraphicsMode(pDC->m_hDC);
SetGraphicsMode(pDC->m_hDC, GM_ADVANCED);
GetWorldTransform(pDC->m_hDC, &m_xForm);
SetWorldTransform(pDC->m_hDC, &xForm);
}
// Restore device context to the state is was before call to SetRotation
void CWorldTransform2View::RestoreDC(CDC* pDC)
{
SetWorldTransform(pDC->m_hDC, &m_xForm);
SetGraphicsMode(pDC->m_hDC, m_nGraphicsMode);
SetViewportOrgEx(pDC->m_hDC, m_PointOrigin.x, m_PointOrigin.y, NULL);
}
I hope this will help you to draw (if you have such problem).
To solve the second problem you need derive new class from drawing object you need to rotate (for example, CDrawRect) and add to it member m_nRotationAngle. After this rewrite all class functions using this angle. For example, function CDrawRect::GetHandle returns point. In your class you should rotate this point around rectangle's top-left vertex (some math...) and after this return it. Function Draw should draw the object with rotation angle (this is the problem you always solved, I beleive). Function MoveHandleTo should first rotate point (parameter) to -m_nRotationAngle degrees and after this work as usual (at least, such it seems to me now...). Function Intersects should work with region rather than rectangle etc.
So, you have some work for a couple of days or more, good luck.
|
|
|
|
|
Who knows, how to perform a migration from VC6 code to GNU C++ (from Slackware Linux 7.10 distribution) with minimum rewriting. Any ideas? My application is not a console one
. and uses:
1. MFC Cdialog
2. Subclassed dialog amd buttons from BCGControlBar and other libs
3. DAO
Thanks!
|
|
|
|
|