|
If it compiles without any errors or warnings, and does what it is supposed to do then yes it is ok. If not then it is not ok.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
ya , It's given the errors.
"Success lies not in the result , But in the efforts !!!!!"
Amit Mistry - petlad -Gujarat-India
|
|
|
|
|
Ok, I will repeat myself:
Every line in your macro, except the last one, must end in a slash. That includes blank lines.
Now take this advice and look carefully at your macro code. See any lines without a slash? I see two.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
This is so messy. Why don't you just make it into a function?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi all,
Is it possible to read the object ID of the file in the NTFS, and from the file's object ID, I can query the filename and path from NTFS so that I can locate the file ? (coz even the user change the filename and path of the file, the object ID will remain unchanged, so I just need to record the object ID for retrieving the file later)
Any reference on how to program this ?
Thanks
|
|
|
|
|
|
Hello Everyone!
I have seen article(of Jason ) :"WallpaperQ :A Wallpaper Management Tool " .I wrote a program by Win32(in VC++6).My simple program include: a button "OK" and a button "Exit"(in dialog "Test Wallpaper").In button "OK",i wrote code as follows :
//at WM_INITDIALOG event
pIActiveDesktop = NULL;
HRESULT hr = CoCreateInstance(CLSID_ActiveDesktop,
NULL, CLSCTX_INPROC_SERVER, IID_IActiveDesktop,
(void**) &pIActiveDesktop);
if (FAILED(hr)) pIActiveDesktop = NULL;
//in button "OK"
if(pIActiveDesktop == NULL)
{.......
SystemParametersInfo(...,"image.bmp",..);
.......
}
else
{..............
pIActiveDesktop->SetDesktopItemOptions
(&compOptions, 0);
............
pIActiveDesktop->SetWallpaperOptions
(&wpOptions, 0);
// Set the wallpaper image.
pIActiveDesktop->SetWallpaper(T2CW
("image.jpg") , 0);
// Apply all changes.
pIActiveDesktop->ApplyChanges(AD_APPLY_ALL);
}
My program only run the first case(pIActiveDesktop=NULL)(i.e it only set to Desktop Wallpapers ".bmp").I (very)want to try the second case but not succeed (i hide the first case,when i click "OK", a error occur"memory can't read ").
Please help me how to "IActiveDesktop is available"
Thanks !
|
|
|
|
|
Hi Guys,
I am having a problem creating a pointer to a CArray structure;
CArray<CBackground*, CBackground*>* m_paryBackground;<br />
<br />
int nNewSize = 2;<br />
m_paryBackground = (CArray<CBackground*, CBackground*>*)malloc(nNewSize * sizeof(CArray<CBackground*, CBackground*>*));<br />
<br />
m_paryBackground[0] = new CArray<CBackground*, CBackground*>;<br />
m_paryBackground[1] = new CArray<CBackground*, CBackground*>;
This does not work for some reason. I get a compile time error saying it cannot cast to the m_paryBackground variable. Does anyone know how I can do this properly? I'm using MFC 7 visual studio 2005
Cheers,
Greg
|
|
|
|
|
Have you read the documentation for how to use a CArray? The CArray class is an array management class, not a simply C array. Read the docs and use the class' member functions such as SetSize() and SetAt().
|
|
|
|
|
Yep I have,
I am not merely trying to use a CArray
I am trying to create a pointer to an array of CArray's. It won't let me do it using malloc for some reason.
|
|
|
|
|
malloc is a C function, not a C++ function. It simply allocates a block of memory, nothing more. You need to use new which allocates a block of memory and then calls the class' c'tor.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
ok, but I need to dynamically allocate memory so I wanted to be able to use realloc. Is there a realloc equivilent for new?
Thanks
|
|
|
|
|
Why? CArray takes care of all the memory allocations itself. There is no need for you to worry about it.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
You should never use malloc in C++. You should also prefer to use std::vector over CArray, as it is standard and it is more flexible/powerful.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Something like this?
size_t nNewSize = 2;
CArray<CBackground*, CBackground*>* m_paryBackground = new CArray<CBackground*, CBackground*>[nNewSize]; In the future, you should include the compiler error you are getting so we don't have to guess.
|
|
|
|
|
Hi guys,
Michael Dunn was kind enough to answer a question I had last night, but now I seem to have hit another nearby snag.
I'm trying to implement a copy constructor as follows:
<br />
Node somenode = new Node();<br />
Node masterArray[40];<br />
.<br />
. <br />
.<br />
<br />
for (int i = 0; i < 40; i++)<br />
{<br />
.
masterArray[i] = new Node(someNode);<br />
and this is my copy constructor (all values are ints, char arrays, etc)
<br />
Node::Node(const Node& n)<br />
{<br />
name = n.name;<br />
lChild = n.lChild;<br />
rChild = n.rChild;<br />
placed = n.placed;<br />
arraySpot = n.arraySpot;<br />
dRPtr = n.dRPtr;<br />
}<br />
When I try to compile, I get errors on all the lines similar to:
<br />
masterArray[i] = new Node(someNode);<br />
that read:
.\BST.cpp(52) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'Node *' (or there is no acceptable conversion)
c:\path 3 files\bst\bst\Node.h(14): could be 'Node &Node::operator =(const Node &)'
while trying to match the argument list '(Node, Node *)'
(verbose, isn't it? )
I'll keep digging around for an answer (yes, I did a cursory check of google first), but in the mean time, does anyone have any ideas?
Thanks, as always,
-Sean
|
|
|
|
|
You do not have an assigment operator defined for your Node class. You are getting the error because the default operator= simply does a bitwise copy of the bits from the right to the left, but it does not know how to copy from a Node* pointer to a Node object. Your Node class has to define it's own assignment operator.- Node& Node::operator =(const Node& n)
- {
- Name = n.Name;
- ...
- return *this;
- }
Node& Node::operator =(const Node& n)
{
Name = n.Name;
...
return *this;
}
[Edit]
It is always a good idea to declare both a copy c'tor and an assignment operator at the same time when you feel the need for either one.
[/Edit]
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
I see...
I stuck this code in the Node.h file:
Node& Node::operator =(const Node& n);
and this in the Node.cpp file:
Node& Node::operator =(const Node& n)
{
name = n.name;
lChild = n.lChild;
rChild = n.rChild;
placed = n.placed;
arraySpot = n.arraySpot;
dRPtr = n.dRPtr;
return *this;
}
But I seem to get the same thing. When I do masterArray[0] = new Node(someNode);
I get the same error. If I omit the "new" I get shallow copies.
Could someone please clarify which step I'm missing here? I guess I'm still a little confused.
Thanks for your patience.
|
|
|
|
|
Have you tried stepping through your code in the debugger? Does operator= get called? You may have to declare another operator= that takes a Node* pointer
Node & Node::operator =(const Node *n)
{
...
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
The operator= is not called, even when I add the function you mentioned above. My copy constructor is called:
Node::Node(const Node& n)
{
name = n.name;
lChild = n.lChild;
rChild = n.rChild;
placed = n.placed;
arraySpot = n.arraySpot;
dRPtr = n.dRPtr;
}
but I still seem to be getting shallow copies. If I put that "new" keyword back, I don't get compile time errors, but I get a run time error which reads "there is no source code available for this location", or something to that effect. Thanks again for the help. You seem to be pretty busy helping people on these boards today. I really appreciate all your hard work, and I'm sure they do too .
-Sean
|
|
|
|
|
Are you coming from a C# background perhaps? You're mixing up objects and pointers to objects. When you write Node masterArray[40] you get 40 objects, there's no need to call new Node later and put the result in the array.
Also - I didn't mention this in my earlier post - Node should have an operator= as well. When a class has either a copy constructor or an operator= , it usually needs the other as well.
|
|
|
|
|
Yeah, I took a few C++ classes, then about three semesters of C# (very astute). So then (referring to my above posts), how do I get that deep assignment that I need from where I am?
masterArray[i] = Node(someNode);
doesn't do the trick. Like I said, I get a shallow assignment after that line calls
Node::Node(const Node& n)
{
name = n.name;
lChild = n.lChild;
rChild = n.rChild;
placed = n.placed;
arraySpot = n.arraySpot;
dRPtr = n.dRPtr;
}
in node.h.
oddly, I get precisely the same thing happening if I give it
masterArray[i] = someNode;
still shallow assignment!
however, this time the overloaded operator is called:
Node& Node::operator =(const Node& n)
{
name = n.name;
lChild = n.lChild;
rChild = n.rChild;
placed = n.placed;
arraySpot = n.arraySpot;
dRPtr = n.dRPtr;
return *this;
}
why won't that give me my deep assignment?
Thanks again guys
-Sean
|
|
|
|
|
How are you determining "shallow" vs "deep" assignments?
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
Shallow changes when the object it is derived from changes, whereas a deep assignment is independent of its parent object.
|
|
|
|
|
All I want to do is change the font color in a button on themed XP/Vista...
MSDN claims that to change "text colors for all controls that support custom draw except for the list view and tree view, simply set the desired text and background colors in the device context supplied in the custom draw notification structure with the SetTextColor and SetBkColor functions"
I do this in the CDDS_PREPAINT phase and return CDRF_DODEFAULT. This has no effect. Anyone got any clues?
There was an MSDN sample but it has vanished from the Microsoft site.
Thx++
|
|
|
|