|
Actually, I copied the property into my code and it compiles fine sans the content. It's the content of the property that's the problem. I don't know if James has solved it or not.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Tom Archer wrote:
I don't know if James has solved it or not.
He hasnt. Not yet. I think he's going to post the code snippets now.
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
Thanks, Nish. I saw that he had posted responses to other posts after I answered you.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Here is the offending code
#pragma once
#pragma unmanaged
#include <windows.h>
#pragma managed
#using <System.dll>
using namespace System;
using namespace System::Drawing;
namespace ScreenSaverUtils
{
public __gc class OptimizedBitmap : public IDisposable
{
private:
OptimizedBitmap(void)
{
}
public:
OptimizedBitmap(Graphics *g, Bitmap *bmpToCopy ) : _disposed(false)
{
}
~OptimizedBitmap(void)
{
Dispose();
}
void Dispose()
{
}
__property Graphics* get_Graphics()
{
System::Diagnostics::Debug::Assert(!_disposed);
return Graphics::FromImage(bitmap);
}
__property Bitmap* get_Bitmap()
{
System::Diagnostics::Debug::Assert(!_disposed);
return dynamic_cast<Bitmap*>(bitmap->Clone());
}
private:
bool _disposed;
HDC hdc;
HBITMAP hbitmap;
Graphics *graphics;
Bitmap *bitmap;
};
} Thanks for everyone's help
[Edit: I'm no longer interested in using those two as properties because the original intent has changed; but I still want to know why its failing to compile ]
James
Simplicity Rules!
|
|
|
|
|
Actually, depending on how you arrange this code, it comes back with varying results.
If you move the variable declarations to the top of the class, most of the problems disappear. This doesn’t give me a whole lot of faith in MC++. There seems to be a conflict here though, but nothing is jumping out at me as anything being wrong with the class structure.
Note: Variable names should not start with an underscore in C/C++; those are reserved for compiler vendors.
The following compiles.
public __gc class OptimizedBitmap : public IDisposable
{
private:
bool disposed;
HDC hdc;
HBITMAP hbitmap;
Graphics *graphics;
Bitmap *bitmap;
OptimizedBitmap()
{
}
public:
OptimizedBitmap(Graphics *g, Bitmap *bmpToCopy ) :
disposed(false)
{
}
~OptimizedBitmap(void)
{
Dispose();
}
void Dispose() {
}
__property Graphics* get_Graphics()
{
return Graphics::FromImage(bitmap);
}
__property Bitmap* get_Bitmap()
{
#if 0
return dynamic_cast<System::Drawing::Bitmap*>(bitmap->Clone());
#else // or
return new System::Drawing::Bitmap(bitmap);
#endif
}
};
|
|
|
|
|
Thanks Neil, i'll put this through its run later, but now I have some anime to watch
James
Simplicity Rules!
|
|
|
|
|
This is interesting, I just created a new project and found this...
This compiles...
namespace VNK {
using namespace System;
using namespace System::Drawing;
public __gc class Foo
{
private:
Graphics *m_pGraphics;
Bitmap *m_pBitmap;
public:
Foo();
~Foo();
__property Graphics* get_Graphics()
{
return m_pGraphics;
}
__property Bitmap* get_Bitmap()
{
return m_pBitmap;
}
};
This does not...
namespace VNK {
using namespace System;
using namespace System::Drawing;
public __gc class Foo
{
public:
Foo();
~Foo();
__property Graphics* get_Graphics()
{
return m_pGraphics;
}
__property Bitmap* get_Bitmap()
{
return m_pBitmap;
}
private:
Graphics *m_pGraphics;
Bitmap *m_pBitmap;
};
I would bet there is a bug report on this, or I am missing something very fundamental that came in on the heals of MC++.
|
|
|
|
|
That would explain why it worked on my machine then. Very strange...
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Tom Archer wrote:
Very strange...
It is indeed, before Christian tore me away from my research, I didn't see anything that would indicate variable declarations need to go at the top of the file.
Unfortunately all the __property examples I've seen use the same one slightly modified:
__property int get_Size() { return 0; }<br />
__property void set_Size() { }
Once I get my mind back in shape I'll take a further look
James
Simplicity Rules!
|
|
|
|
|
I don't think it's a bug. To me it is looks quite obvious that the scope resolution should fail in the second case as it tries to resolve the token Graphics in the local scope and it turns out to be a property name where property name is not expected. Solve this using
using namespace System;
using namespace System::Drawing;
public __gc class Foo
{
public:
Foo();
~Foo();
__property Graphics* get_Graphics()
{
return m_pGraphics;
}
__property Bitmap* get_Bitmap()
{
return m_pBitmap;
}
private:
System::Drawing::Graphics *m_pGraphics;
System::Drawing::Bitmap *m_pBitmap;
};
And for all the C# haters, C# compiler is much smarter in this regard.
|
|
|
|
|
Rama Krishna wrote:
private:
System::Drawing::Graphics *m_pGraphics;
System::Drawing::Bitmap *m_pBitmap;
Thats it, I quit!
James
Simplicity Rules!
|
|
|
|
|
Actually, I think you may be correct, that’s what I get for looking at these things at 3:30 in the morning...
|
|
|
|
|
Just wondering if anybody could point me in the direction of a good book or a good website about MC++ [except the MSDN].
(-_-)
|
|
|
|
|
Tom Archer recomended me a awesome book:
Visual C++ .Net Step By Step by Julian Templeman & Andy Olsen
Al
|
|
|
|
|
Albert Pascual wrote:
awesome book
Good for MC++ then, yea?
(-_-)
|
|
|
|
|
In my modest opinion I think is a very good book about MC++! But that's just my opinion
Al
|
|
|
|
|
Albert Pascual wrote:
In my modest opinion I think is a very good book about MC++! But that's just my opinion
Right. I think I'll go by that. I'll see if I can get the college library to buy it... will save me about €50
(-_-)
|
|
|
|
|
$39.99, save $10 dollars at Amazon and please use the Amazon link in CodeProject so Chris and team get some money
|
|
|
|
|
Albert Pascual wrote:
Amazon and please use the Amazon link in CodeProject so Chris and team get some money
Oh I will use the amazon link at CP if I'm buying it.
(-_-)
|
|
|
|
|
I bought the book on Tom Archer's recommendation. It is a great book for a C++ programmer wanting to move over to managed C++. Highly recommended.
Michael
Communication is the first step towards enlightenment.
|
|
|
|
|
Michael P Butler wrote:
It is a great book for a C++ programmer wanting to move over to managed C++. Highly recommended.
I'll see if they have it at my local book store.. I'll give it a bit of a glance and if I like it I'll buy it through the Amazon link here.
(-_-)
|
|
|
|
|
I didn't realize you bought it then? Great to hear that you're enjoying it!
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
Yeah its actually really good! Thanks and keep suggestions coming
Al
|
|
|
|
|
Here are some of my own MC++ articles :-
http://www.codeproject.com/useritems/mcppintro01.asp
http://www.codeproject.com/useritems/mcppthreads01.asp
http://www.codeproject.com/useritems/mcppsingleinst.asp
http://www.codeproject.com/useritems/mcppwinforms02.asp
http://www.codeproject.com/useritems/mcppwinforms01.asp
http://www.codeproject.com/useritems/mcppoutlookgui.asp
http://www.codeproject.com/useritems/mcppthreadsync01.asp
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|