|
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!
|
|
|
|
|
Sergei Yevseyev wrote:
MFC Cdialog
You are going to need a MFC alternative for Linux. I don't know of any though
Sergei Yevseyev wrote:
Subclassed dialog amd buttons from BCGControlBar and other libs
Doesn't sound promising. Contact the makers and see if there is a Linux port. Although if they are subclassed from MFC it doesn't sound promising.
Sergei Yevseyev wrote:
DAO
I don't know anything about this but I would think there is a Linux alternative.
I would suggest you start over in terms of GUI.
- Matt Newman
- Matt Newman
-Sonork ID: 100.11179:BestSnowman
|
|
|
|
|
Well, I'm afraid you are in trouble. There is no MFC for Linux, and you'll have to rewrite your applications. I suggest you use some OS-independent library like wxWindows.
Anyway, why would you port your GUI application to Linux? Less then 5% of PC users run Linux on their desktop computers?
I vote pro drink
|
|
|
|
|
|
Sergei, we use Tcl/TK to build cross platform GUIs. All the non-GUI code is built as libraries (DLL/so) that are linked into Tcl.
/ravi
"There is always one more bug..."
ravib@ravib.com
http://www.ravib.com
|
|
|
|
|
What about wxWindows (http://www.wxwindows.org/)?
It works on both Windows, Linux, MacOS, and several others, I'm sure.
I've toyed around with it, and it works nicely.
"If ye love wealth better than liberty, the tranquility of servitude better than the animating contest of freedom, go home from us in peace. We ask not your counsels or your arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen."
--Samuel Adams
|
|
|
|
|
I have created an interface to a recordset within a dialog. i have now created another dialog for reporting. How can i access the recordset from that dialog. i have tried including the header, and defining the recordset external. i think i am just missing a step. thank you for any help on this.
|
|
|
|
|
You need to open the recordset from a extarnal class to your dialogs, for example in the app class.... In this way the recordset can be open from any dialog and readed from any dialog....
Best Regards....
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
i used the wizard to create my app. it placed the following in my view to init the recordset.
m_pSet = &GetDocument()->m_tDSMSet;
CRecordView::OnInitialUpdate();
in my view header i have
class CTDSMSet;
.....
CTDSMSet* m_pSet;
i have been able to move the class declaration to my app header but nothing else with out errors. do you know if there is any documentation on moveing everything to the app class from a view class? or am i just looking to hard at this configuration maybe?
|
|
|
|
|
Always I prefer no use CRecordView, I prefer to declare de Database class and recordset in a public class for all classes in my application.... You need to see how can get access to the view from any dialog or other classes....
Try to get access to the View using AfxGetMainWnd();
Best Regards....
Happy new year!!!
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
the MSDN said you can not DRAW in OnUpdate() function, which is called by OnInitialUpdate by default
one is the other who absorbs the thoughts of others
|
|
|
|
|
who knows the answer , please tell me
thanks
one is the other who absorbs the thoughts of others
|
|
|
|
|
You can draw, provided you can get a DC;
CClientDC dc(this);
However, there's a good chance that the window is not visible yet, so drawing into it will not be very useful. A better idea is to use the class as it was intended; initialize any data necessary for drawing in OnInitialUpdate() , updated it in OnUpdate() , and draw it in OnDraw() . OnDraw() will be called when the window is shown and first needs to be updated, so if you place your drawing code there, the view will act as desired.
i ain't happy, i'm feeling glad; i got sunshine in a bag; i'm useless, but not for long; the future is coming on...gorillaz, clint eastwood
|
|
|
|
|
i set a breakpoint in first line of the OnDraw
but can not trace into the code
one is the other who absorbs the thoughts of others
|
|
|
|
|
Not sure what you mean now... The break point isn't getting hit?
i ain't happy, i'm feeling glad; i got sunshine in a bag; i'm useless, but not for long; the future is coming on...gorillaz, clint eastwood
|
|
|
|
|
How to get the data of a csv file ??
regards
Sonu
|
|
|
|
|
the target platform c:...xyz.dll does not match the current target platform
i am getting a error when i am executing a dialog based program which uses a dll that was developed in BC45 environment what does this error mean can any one help me
sudha
sudha
|
|
|
|
|
BC 4.5 uses BWCC.dll (16-bit one). Use Target to switch to 32-bit one OR rebuild Your broject by C++ Builder.
|
|
|
|
|