|
Dear Chris,
Sorry, I thought I have emailed you back.
Unfortunately, the equation that I typed with MS Word editor is still not showing despite the fact that I checked the ignore the html text editor box.
Could you please, answer this question for me
Is it necessary to create a constructor when you are dealing with things like mathematical formulae that involves using classes?
Thanks for your prompt response.
Regards,
SKG!
skg
|
|
|
|
|
Check "ignore HTML tags" to preserve angle brackets, please.
A cynic is a man who, when he smells flowers, looks around for a coffin. -H.L. Mencken
|
|
|
|
|
I'm developing a MFC application using ADO to connect to a local SQL Server database.
And I have troubles catching the exceptions.
Here is my connection code:
const LPCSTR STRING_CONNECTION = "Provider=SQLOLEDB;User ID=sa;Initial Catalog=Northwind;Data Source= (local); Integrated Security=SSPI;";
<br />
BOOL Connect(_ConnectionPtr& pCone)<br />
{<br />
_bstr_t bstrCone(STRING_CONNECTION); <br />
<br />
try<br />
{<br />
<br />
pCone.CreateInstance (__uuidof(Connection));<br />
<br />
pCone->Open (bstrCone ,_bstr_t (""), _bstr_t (""), adModeUnknown );<br />
<br />
return TRUE;<br />
}<br />
catch (_com_error* ce)
{<br />
watch_com_error(ce); <br />
return FALSE;<br />
}<br />
<br />
<br />
}<br />
<br />
<br />
void watch_com_error(_com_error *e)<br />
{<br />
CString msgErr; <br />
_bstr_t bstrSource= e->Source(); <br />
_bstr_t bstrDescri=e->Description(); <br />
<br />
msgErr.Format (_T("ADO - COM Error\n\tCode = %08lx\n\tSource = %s\n\tDescription = %s\n"),<br />
e->Error(),(LPCSTR)bstrSource, (LPCSTR)bstrDescri);<br />
<br />
msgErr.Format (_T("ADO - COM Error\n\tCode = %08lx\n\tSource = %s\n\tDescription = %s\n"),<br />
e->Error(),(LPCSTR)bstrSource, (LPCSTR)bstrDescri);<br />
<br />
AfxMessageBox( msgErr, MB_OK | MB_ICONERROR );<br />
<br />
}<br />
<br />
<br />
The connection works. The problem is handling exceptions.
If I change the string connection to force a COM ERROR, it throw an unhandled exception instead of reach the _com_error handle.
And if I change the _com_error catch by a CException object to intercept generics exceptions, it still throwing an unhandled exception.
What is wrong here?
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
Add another catch block with ... parameters (unless you can find out exactly what type of exception is being thrown):
try
{
pCone.CreateInstance (__uuidof(Connection));
pCone->Open (bstrCone ,_bstr_t (""), _bstr_t (""), adModeUnknown );
return TRUE;
}
catch (_com_error* ce)
{
watch_com_error(ce);
return FALSE;
}
catch (...)
{
return FALSE;
}
Also, check to make sure that ADO is throwing a pointer and not a _com_error& reference (I can't remember which it does off hand).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Yes Zac, you are right!.
Wrong type, it's a reference instead a pointer.
Thank you very much.
Kind regards.
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
The codes that I have written so far is below:
// Simulation of the Dynamics of a 2-Link Pan-Tilt Robotic Manipulator
/* This programme calculates the Velocity, Acceleration and the angles of inclination
of the two links of the Spherical Pointing Motor, which is essentially a Two-Link Robotic
Manipulator*/
//#include
//#include
//#include
//#include
//#include
//#include
// Precompiler Directives
#include
#include
// Constants Declaration
#define n (int) 2
#define m1 (float) 0.05
#define m2 (float) 0.03
#define r1 (float) 0.04
#define r2 (float) 0.06
#define ra (float) 0.04
#define rb (float) 0.06
#define l (float) 0.05
#define d (float) 0.02
#define acc_due_gravity (float) 9.81
class AngVel1
{
public:
};
class AngAccln1
{
public:
};
class AngVel2
{
public:
};
class AngAccln2
{
public:
}
/*
n = Number of Links = 2
m1 = Mass of the First Link (The Annulus)
m2 = Mass of the Second Link
r1 = Inner Radius of Link 1 (The Annulus)
r2 = Outer Radius of Link 1 (The Annulus)
ra = Outer Radius of the Annulus
rb = Inner Radius of the Annulus
l = Half the Lenght of Link 1
d = Displacement from the Centre of Mass
g = Acceleration due to gravity = 9.81
t = time in seconds
*/
// Declaration of variables (Robot Parameters)
float t;
// Prototypes
float TorqueVal(float t);
double Runge_Kutta ();
double AngVel1 (double om1){
return om1;
}
double AngAccln1 (double t, double om1, double tetha1, double tetha2){
t = 0.1;
return (tau1 - 2*m2(r2*r2/4 -h2*h2/3 -d*d) * om1*om2*sintetha2*costetha2 - m2*g*d*costetha1*costetha2)/
om1*(m1(ra*ra + rb*rb)/4 + m1(h1*h1)/3 + m2((r2*r2)(1+sinsqtetha2)/4 + m2*h2*h2*cossqtetha2/3 + m2*d*d*cossqtetha2);
}
double AngVel2 (double om2){
return om2;
}
double AngAccln2 (double t, double om1, double om2, double tetha1, double tetha2){
t=0.4;
return (tau2 + (m2(r2*r2/4 -h2*h2/3 -d*d)*om1*om1*sintetha2*costetha2) - m2*g*d*sintetha1*sintetha2)/
om2*m2(r2*r2/4 + h2*h2/3 + d*d;
double RK(double y){
double k1,k2,k3,k4;
k1=h*fn(y);
k2=h*fn(y+(k1/2.0));
k3=h*fn(y+(k2/2.0));
k4=h*fn(y+k3);
return y+(k1/6.0)+(k2/3.0)+(k3/3.0)+(k4/6.0);
}
// The Main Routine
int main()
{
// Torque Function
float TorqueVal1(float t)
{
t = 0.1;
return t;
}
// Runge-Kutta Function
double RK(double y){
double k1,k2,k3,k4;
k1=h*fn(y);
k2=h*fn(y+(k1/2.0));
k3=h*fn(y+(k2/2.0));
k4=h*fn(y+k3);
return y+(k1/6.0)+(k2/3.0)+(k3/3.0)+(k4/6.0);
}
double RK(double l){
double v1,v2,v3,v4;
v1=h*fn(l);
v2=h*fn(l+(k1/2.0));
v3=h*fn(l+(k2/2.0));
v4=h*fn(l+k3);
return l+(v1/6.0)+(v2/3.0)+(v3/3.0)+(v4/6.0);
}
}
i am attempting to simulate the dynamics of a 2-link pan-tilt robot. Two second order ODE were generated. As a requirement of the Runge-Kutta, each of the two second-order ODE was converted to 2 first order ODE thereby making four equations in all.
I was not using a class before and I just started packing the four equation into classes.
For further explanation or clarification, please, mail me to olaskg@yahoo.ie.
Thank you.
skg
skg
|
|
|
|
|
Damn...and I WAS feeling all smart and stuff this morning.
I knew I should have taken a computer science class in college.
Mark
|
|
|
|
|
sahoong wrote: For further explanation or clarification, please, mail me to olaskg@yahoo.ie.
Are you nuts? This is a forum for you to ask/answer questions. We don't go looking for you! Post your question. Be as exact as possible. Include only relevant code snippets.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
We have too feeble minds to comprehend him. I bet he's laughing at us right now.
--
Verletzen zerfetzen zersetzen zerstören
Doch es darf nicht mir gehören
Ich muss zerstören
|
|
|
|
|
For a client application, after sending a string to the server,
I want to receive 2 strings from the server separately.
But the second recv() call quite often receive NULL.
How can I solve this problem?
(give a delay for it is sometimes better, but NOT always work)
Thanks!
|
|
|
|
|
Receive NULL returned from recv or NULL for number of bytes received?
1) Make sure both strings get sent.
2) Make sure you wait for both strings to get to the client.
You'll need to poll or wait for an FD_READ event/notification from the socket
and REPEAT until you've received the number of bytes you are expecting.
TCP knows nothing about "strings". It only knows a stream of bytes.
It is up to you to know how many bytes to send and receive and to reassemble them into "strings",
"packets", etc. on the receiving end.
Mark
|
|
|
|
|
After receiving the first string, the buffer is cleared (set '\0' to all indices).
After the second recv(), the buffer is still all '\0'.
I am sure that the server has sent 2 strings to the application (client).
The condition is that the second recv() sometimes can receive the correct string, but often receives NULL.
recv() holds the application progress.
Once it finished, the application can go on.
It returned BOOL TRUE so it succeeded but actually nothing is received......
Please help.
Thanks.
|
|
|
|
|
can you post the code you use to send and the code you use to receive?
What is the return value from recv()? Is it the number of bytes sent? Less than that?
Is it 0?
Mark
|
|
|
|
|
Mark,
I do NOT have the code now.
I post it ~8 hr later.
Thanks for your help!
|
|
|
|
|
<br />
Remote PC Socket -----------> Local PC Socket<br />
|<br />
|<br />
Between them Read Data by my Local Prog<br />
<br />
<br />
Remote PC Socket <----------- Local PC Socket<br />
|<br />
|<br />
Between them Read Data by my Local Prog<br />
This is like a send/receive data reader on local machine read all TCP/UDP/...etc data on any Port. i.e. Network Protocol Analyzer
How I can Implement this? Which Protocol should be used for this?
|
|
|
|
|
|
I created a tab ctrl derived from CTabCtrl.
I want to change the border style,so I paint it myself.
But I find that if xp theme enabled,
my tabctrl doesn't have a yellow header on the top of the item.
Infact ,I like the yellow header.
Is there any way that I can onwer draw a tab ctrl,and there is a yellow header if xp theme enabled?
Thank you
|
|
|
|
|
Tricky.. To get the "XP feel" you'd have to use the theme API to draw the tab, but then you'd have to paint your borders after you have drawn the tab with the theme API. Make sure to test your UI with several themes though, to make sure that your additions are general enough, so that it doesn't look bad when using other themes (or no themes for that matter).
There are a bunch of theme API articles on Codeproject if you need specific help on how to program it. Also make sure to lookup the Theme Explorer article here, as it'll help you ALOT to find out what state/part combination draws what.
Good luck!
--
Verletzen zerfetzen zersetzen zerstören
Doch es darf nicht mir gehören
Ich muss zerstören
|
|
|
|
|
I am going to develop a automatic windows service which continuously moniters for devices connected to USB drive.. and i need to get type of device connected to usb port(ex:keyboard or mem stick etc...). What are the functions in windows API to do above things?
Thanks in advance..
|
|
|
|
|
Take a look at the SetupDiEnumDeviceInterfaces() function
#include
InterfaceClassGuid = GUID_DEVCLASS_USB
Mark
|
|
|
|
|
I am going to develop a automatic windows service which continuously moniters for devices connected to USB .. and i need to get type of device connected to usb port(ex:keyboard or mem stick etc...). What are the functions in windows API to do above things?
Thanks in advance..
|
|
|
|
|
Have you looked at HKLM\SYSTEM\CurrentControlSet\Enum\USB and HKLM\SYSTEM\CurrentControlSet\Enum\USBSTOR keys? The LocationInformation value is indicative of what the device is.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Take a look at the SetupDiEnumDeviceInterfaces() function
#include <devguid.h>
InterfaceClassGuid = GUID_DEVCLASS_USB
Mark
|
|
|
|
|
Is this[^] helpful for you
|
|
|
|