|
Hi Everyone,
If anyone donot mind go to the MSWord Help and select office assistant,u will find office assistance image character
appear and then click and u will see form appear on the screen.(If do searching). I want like that form and button flushing in VC++.
Thanks
|
|
|
|
|
I am trying to use a struct as a parameter to a template. I am trying to use the struct as an abstract interface to a plugin architecture. The problem is that I can't seem to instantiate it correctly. Here is the code below. Any ideas what I am doing wrong. All the example for templates seems to exclusively use stack for there example.
// Here is how I am trying to instantiate it
CPlugin<I_Plugin>PLUGIN;
PLUGIN.Load("HTPCPlugin.dll", "GetPlugin"); // compiler pukes here
Compiling...
HTPCCOREDlg.cpp
d:\htpccore\htpccoredlg.cpp(117) : error C2143: syntax error : missing ';' before '.'
d:\htpccore\htpccoredlg.cpp(117) : error C2501: 'PLUGIN' : missing storage-class or type specifiers
d:\htpccore\htpccoredlg.cpp(117) : error C2371: 'PLUGIN' : redefinition; different basic types
d:\htpccore\htpccoredlg.cpp(115) : see declaration of 'PLUGIN'
d:\htpccore\htpccoredlg.cpp(117) : error C2143: syntax error : missing ';' before '.'
Error executing cl.exe.
Creating browse info file...
HTPCCORE.exe - 4 error(s), 0 warning(s)
// Below is the template and interface
struct I_Plugin
{
public:
virtual ~I_Plugin() { }
virtual void Initialize() = 0; // We'll use this to initialize the object
virtual void Destroy() = 0; // We'll use this to destroy the object
virtual void Config() = 0;
virtual void Release() = 0;
virtual void SendMessage( CString ModuleName , UINT Msg, WPARAM wParam, LPARAM lParam ) = 0;
};
template<typename T>
class CPlugin
{
public:
CPlugin():m_hLibrary(0), m_pPlugin(0){}
~CPlugin(){}
T* Load( const char* szDLLName, const char* szFunction )
{
LOADPLUGIN pfnLoad;
// Load our plugin
m_hLibrary = (HINSTANCE)::LoadLibrary( szDLLName );
// Handle errors
if( m_hLibrary == NULL )
return 0;
// Get Address of our plugin accessing function
pfnLoad = (LOADPLUGIN)::GetProcAddress( m_hLibrary, szFunction );
// Get our plugin
if( pfnLoad)
{
pfnLoad( &m_pPlugin );
}
return m_pPlugin;
}
void Release()
{
if( m_pPlugin == 0 )
return;
m_pPlugin->Release();
::FreeLibrary( m_hLibrary );
}
private:
T* m_pPlugin;
typedef void (*LOADPLUGIN)(T**);
HINSTANCE m_hLibrary;
};
|
|
|
|
|
Hi smesser,
Brackets do not show properly in your post. Please use the "Do not treat <'s as HTML tags" checkbox below the editbox. Also, what is the error messahe the compiler is emitting?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Sorry about that. I did as you sugguested and I also added the compilers errors.
Thanks
Steve
PS: Oh your the guy who answered my questions about FFT.
|
|
|
|
|
In which context are you issuing the PLUGIN.Load() call? Inside a function or outside?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
At the moment I was using it outside all functions (globally) just to see if I could get it to complile.
|
|
|
|
|
Then don't You cannot write code outside a function just like that. It is like if you dropped a printf("hello") outside a function, you get this is not legal, right? Put your code inside some function and things will probably work (or at least your error chasing will move one step further.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Your my hero.
Thanks, you are always so helpful.
Steve
|
|
|
|
|
You can have the plugin loaded without any "inside" code if you define the ctor as
CPlugin(const char* szDLLName, const char* szFunction){} and provide some GetPlugin accesor for later use. IMHO this is probably better than the Load scheme, since the only purpose of CPlugin is to make the loading anyway. Following this approach, you might want to move the unloading code to the dtor of the class and supress the explicit loading functions altogether. This fits nicely with a C++ idiom called RAII (Resource Acquisition is Initialization), which you can google for for further info.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks for the sugguestion. I will look into it.
Steve
|
|
|
|
|
Ok, I just put:
PLUGIN.Load("HTPCPlugin.dll", "GetPlugin");
inside of a function and it compiled beautifully.
I am new to templates so what is going on here?
Steve
|
|
|
|
|
There is surely something I do not understand here. I would very much appreciate if someone could explain to me how I screwed this up.
Thank you.
--------------------Configuration: TCPIPwatch - Win32 Debug--------------------
Compiling...
TCPIPwatchDlg.cpp
C:\DOCUMENTS AND SETTINGS\ADMIN\DESKTOP\SSPROJECT\TCPIPwatch\TCPIPwatchDlg.cpp(235) : error C2664: 'bind' : cannot convert parameter 2 from 'struct CTCPIPwatchDlg::TCPIPWConnectSock::SOCKADDR_IN *' to 'const struct sockaddr *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
TCPIPwatch.exe - 1 error(s), 0 warning(s)
void CTCPIPwatchDlg::TCPIPWConnectSock(SOCKADDR_IN *dest, SOCKET &theTrgSock)
{
dest->sin_family = AF_INET;
dest->sin_port = 80;
if(dest->sin_port == INVALID_SOCKET)
AfxMessageBox("Port is invalid.",MB_OK);
theTrgSock = socket(AF_INET, SOCK_RAW, IPPROTO_IP);
const char RCVTIMEO[50] = "5000";
setsockopt(theTrgSock, SOL_SOCKET, SO_RCVTIMEO, (RCVTIMEO), 4);
bind(theTrgSock, (struct SOCKADDR_IN*) dest, sizeof(dest));
}
|
|
|
|
|
Hi,
typecast with (const ::SOCKADDR*) to 2nd parameter for function bind().
Cheers
The chosen One
|
|
|
|
|
Well, I am comming along more and more with this program, but I could still obviously use some help. I am going to put the specifications in full out here.
Define a class for triagnles. A triangle is defined by three sides. Class should have following capabilities:
A constructor that will allow definining a triangle. (float side1, float side2, float side3). The constructor is to call Order to place the sides in order from smallest to largest.
A constructo with no arguments: initialize the three sides to zero.
Public member functions needed.
void SetTriangle(float side1, float side2, float side3);
bool IsEquilateral();
bool IsIsosceles();
bool IsScalene();
bool IsRight();
bool IsAcute();
bool IsObtuse();
friend Triangle Copy(Triangle triangle1);
friend bool operator ==(const Triangle& triangle1, const Triangle& triangle2);
friend ostream& operator <<(ostream& outs, Triangle& the_triangle);
Private member functions needed.
void Order;
void Swap;
I need to write a program that will define triangle1, triangle2, triangle3, triangle4
am to define a class for triangles, and once I have defined it I need to do tese procedurse:
The constructor (with sides) is to call order to order the sides from smallest to largest.
and
The SetTriangle function is to call order to order the sides from smallest to largest
and then display the sides and the type it is... scalene and right, isosceles and acute, ....
I think I may need to give more detail. Triangle1 will not have any values defined. Triangle2 has sides 6.0, 6.0, 6.0. Triangle3: 5.0, 4.0, 3.0. Triangle4: 6.0, 4.0, 4.0
And then for Triangles 2, 4, and 4... I
1) Use friend operator function << to display the three sides of each
2) Test to see if the triangle is Equilateral, Isosceles, or Scalene. When one of the functions returns true, display message. Message should not be displayed within function.
3) Test to see if Right, Acute, Obtuse
For the copy test
1) Use the friend copy function to copy triangle 4 to triangle 1
2) Use friend operator function << to display the three sides of triangle 4 and triangle 1.
3)Use friend operator function == to see if triangle 1 is equal to triangle 4. If the two are, display " are equal", otherwise " are not equal.
For another == test, do the following
1)Use friend operator function << to display three sides of triangle2 and triangle3.
2)Use friend operator function ++ to see if triangle2 is equal to triangle3 and display appropriate message
For the SetTriangle test, do the following:
1)set Triangle3's sides to (5, 4, 3 (in that order))
2)use friend operator function << to disply the three sides of triangle3.
There are all the specifications and what not. It has been like a week... and I have only gotten as far as this Could I please get some help all around on this one. I would so much appreciate it. Please, could I get some help. I have done this much on my own, and now I have just gotten stuck and don't really have a clue as what to do.
My code is
#include <iostream.h><br />
#include <stdlib.h><br />
<br />
class Triangle<br />
{<br />
public:<br />
friend Triangle Copy(Triangle triangle1);<br />
friend bool operator ==(const Triangle& triangle1, const Triangle& triangle2);<br />
friend ostream& operator <<(ostream& outs, Triangle& the_triangle);<br />
<br />
Triangle(float side1, float side2, float side3);<br />
Triangle();<br />
<br />
void SetTriangle(float side1, float side2, float side3);<br />
<br />
bool IsEquilateral();<br />
bool IsIsosceles();<br />
bool IsObtuse();<br />
<br />
float get_side1();<br />
float get_side2();<br />
float get_side3();<br />
<br />
private:<br />
void order(float side_1, float side_2, float side_3);<br />
void swap(float side_1, float side_2);<br />
<br />
float side_1, side_2, side_3;<br />
};<br />
<br />
void main()<br />
{<br />
Triangle triangle1, triangle2(5.0, 4.0, 3.0), triangle3(6.0, 4.0, 4.0);<br />
cout << "Display triangle 1:\n";<br />
cout << "Side 1 = " << triangle1.get_side1() << endl;<br />
cout << "Side 2 = " << triangle1.get_side2() << endl;<br />
cout << "Side 3 = " << triangle1.get_side3() << endl;<br />
<br />
cout << "Display triangle 2:\n";<br />
cout << "Side 1 = " << triangle2.get_side1() << endl;<br />
cout << "Side 2 = " << triangle2.get_side2() << endl;<br />
cout << "Side 3 = " << triangle2.get_side3() << endl;<br />
<br />
cout << "Display triangle 3:\n";<br />
cout << "Side 1 = " << triangle3.get_side1() << endl;<br />
cout << "Side 2 = " << triangle3.get_side2() << endl;<br />
cout << "Side 3 = " << triangle3.get_side3() << endl;<br />
<br />
}<br />
<br />
<br />
Triangle Copy(Triangle triangle1)<br />
{<br />
Triangle copy;<br />
<br />
copy.order = triangle1;<br />
return copy;<br />
}<br />
Triangle::Triangle(float side1, float side2, float side3)<br />
{<br />
side_1 = side1;<br />
side_2 = side2;<br />
side_3 = side3;<br />
} <br />
<br />
void swap(float side_1, float side_2)<br />
{<br />
float temp;<br />
temp = side_1;<br />
side_1 = side_2;<br />
side_2 = temp;<br />
}<br />
<br />
void order(float side_1, float side_2, float side_3)<br />
{<br />
if (side_1 > side_2)<br />
swap (side_1, side_2);<br />
if (side_1 > side_3)<br />
swap (side_1, side_3);<br />
if (side_2 > side_3)<br />
swap (side_2, side_3);<br />
}<br />
<br />
<br />
<br />
Triangle::Triangle() : side_1(0), side_2(0), side_3(0)<br />
{<br />
}<br />
float Triangle::get_side1()<br />
{<br />
return side_1;<br />
}<br />
float Triangle::get_side2()<br />
{<br />
return side_2;<br />
}<br />
float Triangle::get_side3()<br />
{<br />
return side_3;<br />
}
|
|
|
|
|
OK, let me see, if i understood you correctly.
You want to use an overloaded operator << . But what you have done, is only using the normal output of an float.
The overloading would look like this:
ostream& operator<< (ostream& ostr, CTriangle& triangle)
{
ostr << "Side1 = " << triangle.side1 << endl
<< "Side2 = " << triangle.side2 << endl
<< "Side3 = " << triangle.side3 << endl;
return ostr;
}
The overloaded operator== looks like this:
bool operator ==(const CTriangle& tri1, const CTriangle& tri2)
{
if (tri1.side1 == tri2.side1
&& tri1.side2 == tri2.side2
&& tri1.side3 == tri2.side3)
return true;
else
return false;
}
My personal advice:
You should divide your program into three files.
-----------------------
First file -
a file containing the declaration of the triangle class. Name this file triangle.h
!! Remember that triangle is a class, so name the class CTriangle. !!
-----------------------
Second file -
Name this file triangle.cpp
include your triangle.h by using
#include "triangle.h"
Now put all the definitions of your CTriangle class in here (for instance yout get-functions etc. and the overloaded operators). Don't forget neccessary inclusions like iostream.h
-----------------------
Third file -
name this file main.cpp
include your triangle.h by using
#include "triangle.h"
#include <iostream.h>
void main()
{
CTriangle triangle1, triangle2(5.0, 4.0, 3.0), triangle3(6.0, 4.0, 4.0);
cout << "Display triangle 1:\n";
cout << triangle1 ;
cout << "Display triangle 2:\n";
cout << triangle2 ;
cout << "Display triangle 3:\n";
cout << triangle3;
if (triangle2 == triangle3)
cout << "identical" << endl;
else
cout << "not identical" << endl;
<
}
I havent compiled it, but this should work. Test it by changing the values of the triangle2 and triangle3.
Hope this helps
sledge
|
|
|
|
|
ÓÃÖÐÎĶàºÃ£¬Ó¢ÎÄ¿´²»¶®£¡;P
|
|
|
|
|
Yeah....that's probably not going to compile.
When I can talk about 64 bit processors and attract girls with my computer not my car, I'll come out of the closet. Until that time...I'm like "What's the ENTER key?"
-Hockey on being a geek
|
|
|
|
|
heres my problem
float r=10.3;
int x=10;
int z=ceil(r*x) gives me 104 . I need 103
I need output to be converted as
if product = 103.1 o/p = 104
if product = 103.0 o/p=104
if product = 103.5 o/p = 104
Basically i dont want it to take the upper no if the product can be equivalently represented by an integer
what i mean is 103.0 is actually 103
but 103.1 isnt 103
|
|
|
|
|
Hi
double r=10.3;
int x=10;
int z= ::ceil(r*x);
will give 103
Chill
The chosen One
|
|
|
|
|
<code>float x = 3.01; x = ((int)x< ceil (x) )?(int)x:(int)x+1; </code>
a rough try
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
It's most likely round off error.
internally it figures that it is 103.0000000000001 and so it rounds up to 104. Look into the IEEE format used to store floats to figure out why.
J.
----------------------------
|
|
|
|
|
hi all,
i have an XML file..where i have some data as
<keywords>
<keyword>.net
<keyword>0% credit card
<keyword>0% interest credit card
<keyword>1 800 contacts
<keyword>1 800 flower
<keyword>1-800 flower
<keyword>1-800-flowers
I want to perform a search over this XML file as if i have "1-800-flowers". I dont want it to go thru each element and then reach there..it is a slow process as it goes in loop for each keyword tag..is there any way where i can perform a fast search for the data i have..so that it is fast..i am using VC++ with MSXML..Please help me out..
Thanks a lot in advance..
regards,
Himanshu
|
|
|
|
|
net
0% credit card
0% interest credit card
1 800 contacts
1 800 flower
1-800 flower
1-800-flowers
all this is the data embedded between tags that have the same name
like
<MYTAG>1 800 blah 1 </MYTAG>
<MYTAG>1 800 blah 2 </MYTAG>
<MYTAG>1 800 blah 3 </MYTAG>
<MYTAG>1 800 blah 4</MYTAG>
Then I am afraid u ll have to go thru each node and find out . if the tags are unique u can do a "getElementsByTagName" defined by DOM .
Engineering is the effort !
|
|
|
|
|
hi,
post proper XML u r using to get soln or or look into XPath query language on MSDN.
The chosen One
|
|
|
|
|
You could use XPath (Xalan). Not sure how compatible it is with MSXML. I use Xerces to parse XML.
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|