|
Dear All
It would be great if anyone could tell me how to print using cximage?
How do i go about incorporating it?
Thanks
|
|
|
|
|
Dear all
I am desperately trying to print a jpeg/bmp image in vc++.
It prints it on the top left corner of the page ina very small size.
I used the mm_loenglish mapping mode.
It would be great if you could help me to fix this.
Thankyou very much for your time.
|
|
|
|
|
I have an abstract base class CFoo that contains a pure virtual method void setDefault() as well as a public static method void doSomething() , like so:
class CFoo {
public:
CFoo()
{ setDefault(); }
virtual ~CFoo()
{}
virtual void setDefault() = 0;
static void doSomething() {
int x = 0;
x = 32;
}
}
One of CFoo 's clients does this:
CFoo::doSomething();
which causes VC6's linker to complain that CFoo::setDefault() is not implemented. It's as if the compiler wants to construct a CFoo object (which makes no sense since it's an abstract base class).
Is it me or VC6? (It's probably me, but I can't figure out what I'm doing wrong).
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
I think it is VC6. Both VC7.1 and Comeau compiled it just fine.
The results I get from Comeau,
MODE:strict errors C++
"ComeauTest.c", line 7: warning: call of pure virtual function
setDefault();
^
"ComeauTest.c", line 16: warning: variable "x" was set but never used
int x = 0;
^
In strict mode, with -tused, Compile succeeded (but remember, the Comeau online compiler does not link).
http://www.comeaucomputing.com/tryitout/[^]
|
|
|
|
|
Thanks.
What's weird is, I went ahead and implemented CFoo::setDefault() keeping the pure virtual specifier, and guess what - VC6 didn't complain! Eeek! (Nor did the problem go away.)
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
If no one actually attempts to instantiate a CFoo object, then it won't complain.
If you just do:
CFoo fred;
it will.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.santacruznetworks.com">Santa Cruz Networks</A>
|
|
|
|
|
Actually, you can never instantiate a CFoo , since it's an abstract class.
The problem has to do with the fact that CFoo's static (factory) method was constructing a derived class which caused the linker to want to resolve CFoo::setDefault() . This is sorta hokey, but what I was doing was wrong, since the derived class's vtable has not been initialized in the base class' constructor.
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
It's giving an error because you're calling CFoo::setDefault() directly, and that method is not implemented. Remember the virtual only kicks in if you call the method through a pointer. You need to call plain setDefault() to get the polymorphism that I think you are expecting.
--Mike--
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
CP SearchBar v2.0.2 released
|
|
|
|
|
Actually I'm calling CFoo::setDefault() indirectly - I neglected to mention that doSomething() is actually a factory method that serves up a specialization of a CFoo , which causes CFoo 's constructor to be called, which causes a call to a method in a derived class, which is just plain wrong!
But I still think the compiler should have caught the error.
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Ravi Bhavnani wrote:
which causes CFoo's constructor to be called, which causes a call to a method in a derived class
er, you aren't calling a virtual function in the CFoo ctor, are you? The vtbl isn't initialized yet so that will probably crash at runtime with a pure virtual function call.
--Mike--
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
CP SearchBar v2.0.2 released
|
|
|
|
|
Quite right, Mike. VC6 catches that link time, presumably because the vtable entry for setDefault() is NULL.
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Michael is right (almost) - you don't have "virtuality" in the constructor. Your doSomething should Create the object, and then call setDefault explicitely.
(almost: IIRC the VTable is initialized to the one ofthe base class, and you have a virtual call not only through a pointer but also in all member functions and the destructor)
"Vierteile den, der sie Hure schimpft mit einem türkischen Säbel."
sighist | Agile Programming | doxygen
|
|
|
|
|
peterchen wrote:
Your doSomething should Create the object, and then call setDefault explicitely.
Yes, that's exactly the tack I took. Thanks for your reply!
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
While writing some code for a class, wich also contains oveloads for the assignment operator ( = ), VC++ keeps giving C2801 errors. According to MSDN, C2801 means that assignment, class member access, subscripting or function call operators must be a non-static class member.
This is my code:
class Foo<br />
{<br />
private:<br />
CString m_String;<br />
public:<br />
Foo();<br />
Foo(CString);<br />
~Foo();<br />
friend Foo& operator= (const class Bar);<br />
}<br />
<br />
Foo::Foo (CString string)<br />
{<br />
m_String = string;<br />
}<br />
<br />
Foo& operator= (const class Bar BarInstance)<br />
{<br />
return Foo (BarInstance.m_String);<br />
}<br />
<br />
class Bar<br />
{<br />
private:<br />
CString m_String;<br />
public:<br />
Bar();<br />
~Bar();<br />
}
But that's not the whole story; the code
char* yourName = "DaFrawg";<br />
MessageBox("Hello there, %s", yourName);
will generate a messagebox with the prompt "Hello there, %s" and the caption "DaFrawg". What I want is, of course, to have the message "Hello there, DaFrawg" displayed.
Can somebody help me, please?
//Please don't mind my bad English
|
|
|
|
|
DaFrawg wrote:
But that's not the whole story; the code
char* yourName = "DaFrawg";
MessageBox("Hello there, %s", yourName);
will generate a messagebox with the prompt "Hello there, %s" and the caption "DaFrawg". What I want is, of course, to have the message "Hello there, DaFrawg" displayed.
Can somebody help me, please?
CString strMessage;<br />
<br />
strMessage.Format("Hello there, %s", yourName);<br />
MessageBox(strMessage);
Michael
'Logic, my dear Zoe, merely enables one to be wrong with authority.' - The Doctor: The Wheel in Space
|
|
|
|
|
Then why doesn't TRACE1("Hello %s", name) fail?
---QUOTE---
"ERROR: Keyboard not present - Press F1 to continue" - Most BOIS chips
|
|
|
|
|
|
Thanks, it works really good.
|
|
|
|
|
Try this:
class Bar
{
public:
Bar();
~Bar();
CString m_String;
};
class Foo
{
private:
CString m_String;
public:
Foo();
Foo(CString);
~Foo();
const Foo& operator=( const Bar& bar );
};
Foo::Foo (CString string)
{
m_String = string;
}
const Foo& Foo::operator=(const Bar& BarInstance)
{
m_String = BarInstance.m_String;
return (*this);
}
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
It still doesn't work. I now have the real code I use:
<br />
class Foo<br />
{<br />
public:<br />
Foo();<br />
virtual ~Foo();<br />
private:<br />
CString m_String;<br />
public:<br />
friend const Foo& operator= (const class Bar& BarInst);
};<br />
<br />
class Bar<br />
{<br />
public:<br />
Bar();<br />
virtual ~Bar();<br />
private:<br />
CString m_String;<br />
};<br />
<br />
const Foo& operator=(const class Bar& BarInst)
{<br />
m_String = Bar.m_String;
return (this*);
}<br />
The compiler is getting berzerk. Not only a C2801, but also two C2673 (Global functions do not have 'this' pointers), C2227 (left of m_String must point to class/struct/union), C2248 (but that's not a real problem) and C2059 (Syntax error: ';').
|
|
|
|
|
Please refer to M. Dimmick's reply. Friend functions are not considered class members; they are normal external functions that are given special access privileges. Also, friend s are not in the class’s scope, and they are not called using the member-selection operators (. and –>). The code snippet that I provided you is correct. If it is not the correct solution to your problem, however, then you must reconsider the design.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
It's not weird at all, it's standard: operator= must be implemented as a member function, according to the definition of the language.
The error message also tells you that any overloads of operator-> , operator[] or operator() must also be implemented as a member function. I believe it also applies to compound assignments, such as += , /= , etc.
operator= must be a function that modifies the object to which it's applied, i.e. the left-hand side of the assignment statement, which is pointed to by this inside the function body. It should return a reference to the object that was modified.
|
|
|
|
|
1) the operator function IS a member of the class
2) my (new) code IS using the this pointer and returns it
And still VC++ keeps saying "Operator '=' must be an <unknown> member.
|
|
|
|
|
Hello, everyone.
I am making a program with plug-ins. So I designed SDK (header files + lib file). This sdk is being used by the main program and plug-ins. I am working VC6. Now to the problem. I want to have a global object, which can be used and modified by the main program and all plug-ins (so it is a global object in the sdk). I am confused about how this object is used by main program and dll's. It looks like main program has its own version and each dll has its own version, while I want it to be shared. How do I do it?
And another concern: for right now my sdk is a static linked library, but can I make it to be a dll too? My confustion is that program must load dll and import its functions (like plug-ins), while I want a case, when implimentation of the sdk functions are in the shared dll. I would like to have more information about this topic, does anyone know a good reading material on the subject?
Thank you.
Regards,
Alexander.
|
|
|
|
|
For DLLs:
First, every class or independent function, or variable should be exported:
see __declspec(dllexport) and __declspec(dllimport)
Second, header for objects that are exported should be included into your exe. Look into using "interfaces". Interfaces help make it possible to upgrade the DLL without relinking the EXE.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.santacruznetworks.com">Santa Cruz Networks</A>
|
|
|
|