|
Hi Moak,
I was about to write that function and ask and saw your message.
When I use, then i can safely give the vector's first element as reference to the function and vector's size.
std::vector<Point3D> points;
....
if(!points.empty())
calcPerimeter(&points[0], static_cast<int>(points.size());
Best Regards.
Bekir.
|
|
|
|
|
There's another option here which probably means changing your design...
From the small amount of code you've posted it looks to me like you're trying to handle 3D paths of some sort. Instead of exposing a set of functions which operate on vectors of points, how about defining an interface?
class path
{
public:
virtual ~path();
virtual double length() const = 0;
virtual double distance_from( const point &p ) const = 0;
};
Then you can write all your client code that deals with paths in terms of that interface. You can then impelement paths in your DLL or pass them into other DLLs and not have to worry about copying, assignment and all the other DLLy problems (such as exporting functions - THIS is the big plus for me...).
So say you implement a concrete path in your DLL:
class vector_path : public path
{
public:
vector_path( const std::vector<point *> &points_defining_path );
~vector_path();
virtual double length() const;
virtual double distance_from( const point &p ) const;
private:
std::vector<point *> points_defining_path_;
};
you can export a pair of creation/deletion functions:
PATH_EXPORT path *create_vector_path( const point **start_pts_in_path, const point **end_pts_in_path )
{
std::vector<point *> pts_in_path( start_pts_in_path, end_pts_in_path );
return new (no_throw) vector_path( pts_in_path );
}
PATH_EXPORT void cleanup_path( path *to_cleanup )
{
delete to_cleanup;
}
This gives you a nice interface you can use without worrying about lobbing vectors around as you're dealing with paths, a much higher level concept.
Cheers,
Ash
|
|
|
|
|
Dear Ash,
Thank you for such a detailed answer, at first i thought i can have data set and implement different operations on that data set (Area, Perimeter and some clipping operations)
Defining an interface and hide the data in concrete classes and use interface functions to operate on is another perhaps better way. I had already looked into below link. Mature Approach part is similar to yours except virtual destructor is replaced by a Release() method and Smart Pointer calls that function for clean-up.
HowTo: Export C++ classes from a DLL[^]
Again thank you for the answers.
Best Regards.
|
|
|
|
|
If you go for that style of solution there's plenty you could do to improve the safety of the solution I outlined - private destructor, cleanup function a friend of the interface so it can be deleted, quick typedef for shared_ptr and a helper to create them. If you need some more help with the details please ask another question and I can bore you further!
Cheers,
Ash
|
|
|
|
|
Which one takes more processing time a. contineous if condition or switch case in while loop .
e.g.
while(conditon)
{
switch(conditon)
{
case contion :
}
codition++
}
or
if(condition)
{
}
if(condition)
{}
if(codition)
{}....
and so ono...
Thanks
|
|
|
|
|
No idea and even if I could give you an idea it'd only be for the compiler (including settings) I tested it on and running the code on the particular configuration of computer/OS I ran it on. If you really want to know then about all you can do is test it on the computer the code's eventually going to run on.
Cheers,
Ash
|
|
|
|
|
|
Hi sir,
I have origin axis and x1,x2,y1,y2.
I want to draw a rectangle and rotate it with the given degree.I am trying with this code,but i am not getting.
Her is the code
double x1,x2,y1,y2;
sf=(1024/31);
A1 = 10.00;
A2 = 10.00;
B1 = 10.00;
B2 = 10.00;
x1 = (A1 * sf);
x2 = (A2 * sf);
y1 = (B1 * sf);
y2 = (B2 * sf);
float Angle = 45.0;
x1 = x1 * cos(Angle) + y1 * sin(Angle);
y1 = -x1 * sin(Angle) + y1 * cos(Angle);
x2 = x2 * cos(Angle) + y2 * sin(Angle);
y2 = -x2 * sin(Angle) + y2 * cos(Angle);
Origin(525,454);
MoveToEx(pCellInfo->hDC,center.x-x1,center.y-y2,NULL);
LineTo(pCellInfo->hDC,center.x-x1,center.y+y1);
LineTo(pCellInfo->hDC,center.x+x2,center.y+y1);
LineTo(pCellInfo->hDC,center.x+x2,center.y-y2);
LineTo(pCellInfo->hDC,center.x-x1,center.y-y2);
If i test with this hard code values,i am getting the rectangle rotated
MoveToEx(pCellInfo->hDC,525,289,NULL);
LineTo(pCellInfo->hDC,360,454);
LineTo(pCellInfo->hDC,525,619);
LineTo(pCellInfo->hDC,690,454);
LineTo(pCellInfo->hDC,525,289);
how can i get the same values
Thanks
Raj
Can some one help me
|
|
|
|
|
I can see a few problems straight up:
1. [Probably not important] If sf is an int, then that's probably not what you want.
2. Trig functions expect angles in radians not degrees, so an angle of 45.0 is probably not what you want.
3. Where is center being set? It could be some wild value so that all the drawing is offscreen. Look at the actual values you are passing to MoveToEx and LineTo.
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Peter_in_2780 wrote: Look at the actual values you are passing to MoveToEx and LineTo.
Peter_in_2780 wrote: If sf is an int
No its double.
Peter_in_2780 wrote: Trig functions expect angles in radians not degrees,
I have changed it to
int a = 45;
float Angle = ( 3.142 * a ) / 180;
Peter_in_2780 wrote: Where is center being set?
I am gettin g the center by calculating the bitmag as..
center.x=(((pCellInfo->rcBitmapRect.right-pCellInfo->rcBitmapRect.left)/2)+pCellInfo->rcBitmapRect.left);
center.y=(((pCellInfo->rcBitmapRect.bottom-pCellInfo->rcBitmapRect.top)/2)+pCellInfo->rcBitmapRect.top);
Thanks
Raj
|
|
|
|
|
#include <iostream>
#include <windows.h>
using std::cin;
using std::cout;
using std::endl;
void main()
{
WIN32_FIND_DATA FileDetails;
HANDLE ListDirectory;
ListDirectory = FindFirstFile(L"C:\\*", &FileDetails);
cout << FileDetails.cFileName << endl;
FindClose(ListDirectory);
}
I read on MSDN the code is deprecated on Windows 7! Any ideas why it is giving me junk text as a result.
Does anyone also know a 1 line fix for the 3 using declarations?
|
|
|
|
|
Your code seems unicode, thats why cout prints junk.
use unicode version as wcout<<FileDetails.cFileName<<endl;
|
|
|
|
|
The using keyword is used as follows -
#include <iostream>
using namespace std;
|
|
|
|
|
It's only used that way if you want to dump the whole of the std:: namespace into your code. You can also use it on individual identifiers (as the original poster did) and to change the visibility of class members.
Ash
|
|
|
|
|
Fareed Rizkalla wrote: Does anyone also know a 1 line fix for the 3 using declarations?
This made me think the OP wanted it so.
|
|
|
|
|
Good point! Next stop I'll be starring on the muppet show.
Ash
|
|
|
|
|
I'm trying to make a program that reads the temperature from the cpu and then sends it to my arduino duemilanove, where I have a 4 digit 7-segment display. I've been searching for a while but found nothing about reading the temperature from cpu's DTS (Digital Thermal Sensors). I don't want to use CoreTemp or any other related tool.
EDIT: By the way, I have a asus n61jq laptop with intel core i7 720QM
|
|
|
|
|
|
I'm trying to use __readmsr() intrinsic function to get the temperature, but it keeps giving this error:
"Unhandled exception at 0x000000013fd81009 in test.exe: 0xC0000096: Privileged instruction."
It seems that rdmsr instruction must be executed in privileged mode.
EDIT: Is there any way of switching from user-mode to kernel-mode instead of making a driver?
modified on Tuesday, August 17, 2010 8:29 AM
|
|
|
|
|
Is the Win32_TemperatureProbe class of any help?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
It could help but I never worked with WMI, so I will need a example of its use.
I've just downloaded the WDK and I will try to read the temperature by making a driver.
This could be fun!
|
|
|
|
|
Using WMI will be much simpler than doing a driver - search CP and you'll find lots of articles on WMI such as Making WMI Queries In C++[^]
Judy
Be wary of strong drink. It can make you shoot at tax collectors - and miss.
Lazarus Long, "Time Enough For Love" by Robert A. Heinlein
|
|
|
|
|
I've got an SDI MFC application.
The app has a ribbon. On the "home" group of the group is a clipboard panel with cut/copy etc buttons on it.
I want to show a popup dialog, well actually, CDockable pane.
I want the user to be able to use the clipboard buttons to invoke the cut/copy handlers in the dialog.
Is the possible?
|
|
|
|
|
I haven't properly understood the question, but if you want to invoke the cut/copy/paste handlers of one window from another, you could try sending the standard WM_CUT /WM_COPY /WM_PASTE messages to the target window.
|
|
|
|
|
hi..
i am trying to install htk 3.2
but it is giving an error
cl not recognized as an internal or external command
..
i hv installd microsoft visual studio 2003 .net 2003
|
|
|
|