|
|
gregdachs wrote: I would like now to make MATLAB able to modify these global variables or otherwise communicate with the control loop thread
I think MATLAB has a good COM interface.
|
|
|
|
|
I have a Linker problem in VCPP600.
after migrating the Source code to a new directory, the linker insits in linking with nafxcwd.lib, as well as mfc42d.lib, which of course leads to conflicts. The Manifest Constant _AFXDLL is set, and have an #ifndef _AFXDLL/n #error 'Gotcha' implicidly or expilcitly in each file associated with the project. None of these fire!
the DSP File does not mention 'nafxcwd.dll' anywhere. Where do I go from here.
LateNightsInNewry
|
|
|
|
|
Hi,
I know that a constructer is not suppoused to return value, however what if my object is dependent on certin data and the constructer which lets say takes a string
as paramter finds that the data is in error is there anyway to tell this to the user of the object and maybe not create the object
Thankx
|
|
|
|
|
I think u can throw a exception in your constructor
|
|
|
|
|
|
If you throw an exception in the constructor the object will not be constructed and thus will not be usable.
Steve
|
|
|
|
|
Constructors do not return values, but can throw exceptions. (If constructors could give an error return value, by logical extension you would have to test every constructor, which would include declarations like 'int i=0')
The YACC concept would be that the effective return value of a costructor is the object it constructs. The constructor cannot return a 'Non'object, and proceed from there, it can only succeed or fail.
So, if the string data is in error, throw an exception.
An easier method is, to separate the Construction and Initialisation process, and write a method such as Init() which CAN return Value!
LateNightsInNewry
|
|
|
|
|
|
"http://blog.csdn.net/xiaolongzhou1225/archive/2006/09/10/1204218.aspx" will be your help
|
|
|
|
|
|
Why dont you go for parameterized constructor instead..
Use call by ref concept. Is this useful. Just pass one more argument in constructor as out parameter. retrun thru out parameter.
class CMyCls
{
public:
CMyCls(){}
CMyCls(CString str,int &nRet)
{
if(some thing1)
nRet = your value;
else if(some thing2)
nRet = your value;
else if(some thing2)
nRet = your value;
else
nRet = your value;
}
};
void main()
{
<big>int result = 0;</big>
class CMyCls obj("hello",<big>result</big>);
}
I dont know what you expecting. But hope this is useful 2 u.
Nice talking to you. If you judge people, you have no time to love them. -- Mother Teresa
|
|
|
|
|
if the result is not what I want then I dont really need the objext created
some have suggested a Throw/exception might do the trick
|
|
|
|
|
i want to create a hook which prevents file creation in my system... i want to prevent exe files being copied to my system. i thought i can do that by using the WM_GETMESSAGE in setwindowshookex... it works for keypress and other messages and if i know the messages for file system i can do what i thought... is it a different concept of handling the file system? hope i can get an answer from forum... if more information is needed from me i can post this again...
|
|
|
|
|
you can use api hook to hook "CreateFile" win32 api which I've invoked and find it's not stable,in IFS(Installable File System),you will use filter driver to get the creation flag and "filemon" source code will be your help.If you're interesting in such,please contract me in eraccn@gmail.com and I've got the "filemon" source code and some document about these.
|
|
|
|
|
hi all. i am trying to accomplish a very simple task but am being bogged down with a linker error that i cant resolve!!
i am making a class with an ofstream object and initializing the object is the constructor...very straightforward.
here is the code:
simpleTask.h
--------------
static ofstream dg_video; // i need static for other reasons (that shouldn't be the reason)
simpleTask.cpp constructor
---------------------------
ofstream dg_video("replay.txt", ios::out);
linker error
---------------
error LNK2001: unresolved external symbol "public: static class std::basic_ofstream<char,struct std::char_traits<char=""> > dg_scenario::dg_video" (?dg_video@dg_scenario@@2V?$basic_ofstream@DU?$char_traits@D@std@@@std@@A)
1>.\spring___Win32_Debug\spring.exe : fatal error LNK1120: 1 unresolved externals
--
dg
|
|
|
|
|
Static members need to be defined outside the class declaration.
In simpleTask.cpp you could add (outside of any method):
ofstream CsimpleTask::dg_video("replay.txt", ios::out);
and remove the line from the constructor (which is actually creating another automatic ofstream
variable).
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the letter Z
|
|
|
|
|
OK. That's progress but doesn't quite fix the problem. I am getting no linking errors but now the text that I want to print into the file is not being printed..
here is the updated source code (only the changes I've made).
line outside of any methods or constructors in simpleTask.cpp
--------------------
ofstream CsimpleTask::dg_video("replay.txt", ios::out);
lines in the constructor
--------------------
CsimpleTask::dg_video << "-- INITIAL STATE --\n\n";
CsimpleTask::dg_video << "Object: dg_bead \n";
CsimpleTask::dg_video << "position: " << bead->getCenter().x << " " << bead->getCenter().y << " " << bead->getCenter().z << "\n";
CsimpleTask::dg_video << "dynamics: " << bead->getDynamics() << "\n";
CsimpleTask::dg_video << "being_grabbed: " << bead->isBeingGrabbed() << "\n\n";
CsimpleTask::dg_video << "-- SENSOR INFORMATION --\n\n";
the stuff that I'm printing in the constructor is not shown when I view the file after running the app..
any ideas why? solutions?
--
dg
|
|
|
|
|
Are you actually creating a CsimpleTask object so the constructor gets called?
(I'm assuming you're referring to the CsimpleTask class constructor)
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the letter Z
|
|
|
|
|
Yes I am creating the object. And yes, your assumption is correct.
--
dg
|
|
|
|
|
Since the static object won't be destructed until the process terminates, you may need to add
CsimpleTask::dg_video.flush();
after writing to the stream.
Otherwise, something else is going on - I'd need to see the code.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the letter Z
|
|
|
|
|
still doesnt work..
NOTE: the file name is simpleTask.cpp but the class name is dg_scenario...yes bad programming practice i know but i'm too lazy to change it right now
here is more code:
<br />
ofstream dg_scenario::dg_video("replay.txt", ios::out);<br />
<br />
dg_scenario::dg_scenario(springCore* springApp, char* params) : gameBase(springApp, params)<br />
{ <br />
if (wf) {<br />
dg_scenario::dg_workflow = new workflow("1. Pick up the ball", 0, 0);<br />
dg_scenario::dg_workflow->addNode("2. Move the ball to the other side", 2, 0, 1);<br />
dg_scenario::dg_workflow->addLeft("3. You dropped the ball", 3, 0, 0);<br />
dg_scenario::dg_workflow->addNode("4. Drop the ball on the other side", 4, 0, 0);<br />
}<br />
int i;<br />
if (debug) cerr << "dg_scenario::constructor()\n";<br />
<br />
{<br />
extern ObjectArray universe;<br />
extern SensorArray sensorarray;<br />
extern LightArray lightarray;<br />
this->universe = &universe;<br />
this->sensorarray = &sensorarray;<br />
this->lightarray = &lightarray;<br />
}<br />
<br />
<br />
<br />
<br />
bead = universe->addObject("dg_bead");
bead->CreateSphere(5,len,-1.0);
bead->setDiffuseColor(0.8, 0.4, 0.2, 1.0);<br />
bead->setDynamics(Object::rigid);
bead->setCollisionExtent(Object::external);
bead->Translate(-20+len,5.0,5.0);
grasper = universe->addObject("dg_grasper");<br />
grasper->CreateForcep(9.0, 4.0);<br />
grasper->setDiffuseColor(0.5, 0.5, 1.0, 1.0);
grasper->setCollisionExtent(Object::external);<br />
grasper->Translate(-20+len,10.0,5.0);<br />
left_plane = universe->addObject("dg_left_plane");<br />
left_plane->CreatePlane(2*len, 2*len, 1, 1, Point3D(-20.0,0.0,0.0),'y');<br />
left_plane->setCollisionExtent(Object::external);<br />
left_plane->setDiffuseColor(1.0,0.0,0.0,1.0);<br />
left_plane->setDynamics(Object::rigid);<br />
middle_plane = universe->addObject("dg_middle_plane");<br />
middle_plane->CreatePlane(2*len, len*8, 1, 1, Point3D(-20.0+2*len,0.0,0.0),'y');<br />
middle_plane->setCollisionExtent(Object::external);<br />
middle_plane->setDiffuseColor(0.0,0.0,1.0,1.0);<br />
middle_plane->setDynamics(Object::rigid);<br />
right_plane = universe->addObject("dg_right_plane");<br />
right_plane->CreatePlane(2*len, 2*len, 1, 1, Point3D(-20.0+len*10,0.0,0.0),'y');<br />
right_plane->setCollisionExtent(Object::external);<br />
right_plane->setDiffuseColor(1.0,0.0,0.0,1.0);<br />
right_plane->setDynamics(Object::rigid);<br />
<br />
extern muiObject* main_pulldown;<br />
<br />
extern int paused;<br />
paused = 0;<br />
<br />
extern int camera_relativ_to_univ_min_max;<br />
camera_relativ_to_univ_min_max = 0;<br />
<br />
springApp->setCollisionsOn(true);<br />
springApp->setCollisionAlgorithm(springCore::AABB_CD); <br />
<br />
extern int do_gravity;<br />
do_gravity = 1;<br />
extern double gravity_floor;<br />
gravity_floor = 0;<br />
extern void Gravity_CB(int glui_p);<br />
Gravity_CB(-1);
<br />
float* light_pos = lightarray->getLight(0)->getLightPos();<br />
light_pos[0] = 0;<br />
light_pos[1] = 1.0;<br />
light_pos[2] = 1.0;<br />
light_pos[3] = 0.0;<br />
<br />
lightarray->CreateLight();<br />
Light* light = lightarray->getLight(1);<br />
light->getLightPos()[3] = 1.0;
float* ambient_intensity = light->getAmbientIntensity();<br />
ambient_intensity[0] = 1.0;<br />
ambient_intensity[1] = 1.0;<br />
ambient_intensity[2] = 1.0;<br />
ambient_intensity[3] = 0.0;<br />
float* diffuse_intensity = light->getDiffuseIntensity();<br />
diffuse_intensity[0] = 1.0;<br />
diffuse_intensity[1] = 1.0;<br />
diffuse_intensity[2] = 1.0;<br />
diffuse_intensity[3] = 1.0;<br />
float* specular_intensity = light->getSpecularIntensity();<br />
specular_intensity[0] = 1.0;<br />
specular_intensity[1] = 1.0;<br />
specular_intensity[2] = 1.0;<br />
specular_intensity[3] = 0.0;<br />
light->setAttenuationConstant(0);<br />
light->setAttenuationLinear(0);<br />
light->setAttenuationQuadratic(0.01);<br />
light->setSpotExponent(128);<br />
light->setSpotCutoff(180);<br />
<br />
extern void windowsize_submenu_fn(int ItemNo);<br />
isDone = false; <br />
<br />
dg_scenario::dg_video << "-- INITIAL STATE --\n\n";<br />
dg_scenario::dg_video << "Object: dg_bead \n";<br />
dg_scenario::dg_video << "position: " << bead->getCenter().x << " " << bead->getCenter().y << " " << bead->getCenter().z << "\n";<br />
dg_scenario::dg_video << "dynamics: " << bead->getDynamics() << "\n";<br />
dg_scenario::dg_video << "being_grabbed: " << bead->isBeingGrabbed() << "\n\n";<br />
dg_scenario::dg_video << "-- SENSOR INFORMATION --\n\n";<br />
}<br />
<br />
dg_scenario::~dg_scenario() <br />
{ <br />
if (debug) cerr << "dg_scenario::destructor()\n";<br />
dg_scenario::dg_video.flush();<br />
dg_scenario::dg_video.close();<br />
}<br />
<br />
void dg_scenario::update_video_file(Point3D spt, int oc)<br />
{<br />
dg_scenario::dg_video << "position: " << spt.x << " " << spt.y << " " << spt.z << "\n";<br />
dg_scenario::dg_video << "state: " << oc << "\n\n";<br />
}
--
dg
|
|
|
|
|
I don't see anything...
Are you at least getting an empty replay.txt file when you exit the app or the dg_scenario
destructor is called (actually it should exist as soon as the
ofstream dg_scenario::dg_video<br />
("replay.txt", ios::out); line is executed at startup)?
If you put a breakpoint on
ofstream dg_scenario::dg_video("replay.txt", ios::out);
and run the app, is dg_scenario::dg_video constructed properly?
I'm not sure what's going on - I'm testing here with equivalent code and it works fine.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the letter Z
|
|
|
|
|
Also, if you add a flush call to the constructor after the last text is written
so it looks like this:
dg_scenario::dg_video << "-- SENSOR INFORMATION --\n\n";<br />
dg_scenario::dg_video.flush();
and put a breakpoint on the line calling flush(), the replay.txt file should have text in it
after flush is called.
If you're not seeing any "replay.txt" file at all, then you may want to specify a path with the
name so you can find it
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the letter Z
|
|
|
|
|
OK. I put a breakpoint on the line in the constructor which enters the first line of text and added the flush() at the end of the constructor. I stepped through all the lines and after passing flush(), opened the replay.txt file. The text had been entered successfully!!
HOWEVER, (after I remove that same flush() statement) if I run through the whole application, trigger the constructor and destructor, and then check the replay.txt file, I don't find anything..
any ideas why?
--
dg
|
|
|
|
|