|
Thanks for the valuable tips!
Since I'd rather not mess with pointers if I can help it, I called the array in my Bessel functions; viz:
void bessj0(double x[20],double j0[20])
{
double ax[20],z[20],xx[20],y[20],ans1[20],ans2[20];
for (int i=0;i<20;i++)
{
if ((ax[i]=fabs(x[i]))<8.0)
{
y[i]=x[i]*x[i];
ans1[i]=57568490574.0+y[i]*(-13362590354.0+y[i]*(651619640.7
+y[i]*(-11214424.18+y[i]*(77392.33017+y[i]*(-184.9052456)))));
ans2[i]=57568490411.0+y[i]*(1029532985.0+y[i]*(9494680.718
+y[i]*(59272.64853+y[i]*(267.8532712+y[i]*1.0))));
j0[i]=ans1[i]/ans2[i];
}
else
{
z[i]=8.0/ax[i];
y[i]=z[i]*z[i];
xx[i]=ax[i]-0.785398164;
ans1[i]=1.0+y[i]*(-0.1098628627e-2+y[i]*(0.2734510407e-4
+y[i]*(-0.2073370639e-5+y[i]*0.2093387211e-6)));
ans2[i]=-0.1562499995e-1+y[i]*(0.1430488765e-3
+y[i]*(-0.6911147651e-5+y[i]*(0.7621095161e-6
-y[i]*0.934945152e-7)));
j0[i]=sqrt(0.636619772/ax[i])*(cos(xx[i])*ans1[i]-z[i]*sin(xx[i])*ans2[i]);
}
}
}
I later called the function above with:
bessj0(p,j0);
But I'm not sure if a certain line in the implementing code, to return Ip[] would be valid, viz:
void Integrals(double Ip[20])
{
double alpha[20],beta[20];
for (int t=0;t<20;t++)
{
double j0[20],j1[20],H0[20],H1[20],p[20];
void bessj0(double x[20],double j0[20]);
void bessj1(double x[20],double j1[20]);
alpha[t] = beta[t] = 2*t*PI;
p[t] = 2*sqrt(pow(alpha[t],2.0)+pow(beta[t],2.0));
bessj0(p,j0);
bessj1(p,j1);
H0[t] = sum0(p[t]);
H1[t] = sum1(p[t]);
Ip[t] = ((PI*p[t])/2) * ((2*p[t]*j0[t]) + (((PI*p[t])/2) * ((H0[t]*j1[t])-(H1[t]*j0[t]))) - j1[t]);
}
}
Also, why didn't I get an error at line (***)? The function is defined thus:
double sum0(double x)
{
double H0;
H0 = x - (pow(x,3)/9) + (pow(x,5)/(9*25)) - (pow(x,7)/(9*25*49))
+ (pow(x,9)/(9*25*49*81)) - (pow(x,11)/(9*25*49*81*121));
return H0;
}
The code pasted compiles without any errors. But I'm concerned to make sure I'm doing the correct and logical thing in the 1st place.
I'd be greatful for constructive criticism and useful tips directly applicable to the pasted code. Thanks a lot!
|
|
|
|
|
If you are going to pass arrays then it is best to pass them as a pointer to array.
void Integrals(double Ip[20])
{
....
for( i=0; i<20; ++i )
Ip[i] = what ever;
}
void Integrals(double *Ip)
{
....
for( i=0; i<20; ++i )
Ip[i] = what ever;
}
void Integrals(double *Ip, int nSize)
{
....
for( i=0; i<nSize; ++i )
Ip[i] = what ever;
}
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Hi,
I've got a problem with the IShellFolder2 interface...
I want to use its GetDetailsEx funtion in a file tree application...
I add an interface pointer to my class and add a relese funtion for it in the destructor.
But when i compile the code VC++ gives me the following errors:
h:\Mydoc\C++\Visual Studio Projects\Lars\TreeNode.cpp(11) : error C2027: use of undefined type 'IShellFolder2'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\ShObjIdl.h(83) : see declaration of 'IShellFolder2'
h:\Mydoc\C++\Visual Studio Projects\Lars\TreeNode.cpp(11) : error C2227: left of '->Release' must point to class/struct/union
I've tried to move the code into a seperate file but still gets the same error..
I've no idea what can be wrong... Do I have to import something that implement the interface?
Thanks....
|
|
|
|
|
Try adding the following lines at the top of your stdafx.h file:
#define WINVER 0x0501
#define _WIN32_WINNT 0x0501
#define _WIN32_IE 0x0600 These ensure that when the Windows headers get compiled, the features that are only present in later versions of Windows (or provided by Internet Explorer) are available.
Gurra_Koo wrote:
Do I have to import something that implement the interface?
No. It sounds like in your application you're getting the interface from an API call (most likely SHGetDesktopFolder() ). The only time you would implement IShellFolder2 would be if you were writing a namespace extension for an object that would become part of the Windows shell.
Software Zen: delete this;
|
|
|
|
|
Thanks... That really helped!
|
|
|
|
|
From my MFC program how can i find out the drive letter from which the OS Booted
Also
how to convert "\Device\HarddiskVolume1\" to "c:\"
any help/suggestion
is most welcome
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
That's easy. Have a look at the WinObj tool from http://www.sysinternals.com/[^].
You will find the information in the Windows NT namespace (Path "??").
Enumerate the namespace using the native API and search for the Harddisk aliases.
Don't try it, just do it!
|
|
|
|
|
|
WM_GETMINMAXINFO
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Hi all,
In my application using eVC++ 4.0, I have to draw ellipses with different line styles such as dashed, dotted,
dashed-dotted..
I do it in VC++ 6.0, using Bezier Functions...
But some of the functions are not supported in eVC++ 4.0.
Is there any way to draw these ellipses?
Please help me...
Thanks in Advance,
Arun AC
|
|
|
|
|
As MSDN state,
The SendMessage function sends the specified message to a window or windows. It calls the window procedure for the specified window and does not return until the window procedure has processed the message.
I am facing Problem in this?i just want to transfer data back from the SendMessage,The way The ListView and etc work.
here is my code listing
on_click()<br />
{<br />
char nam1[255];<br />
nam1[0]=NULL;<br />
this->UpdateData(FALSE);<br />
::SendMessage((HWND)this->m_lHandle,WM_USER+90,0,(LPARAM)&nam1);<br />
<br />
MessageBox(nam1);<br />
}
and message Handlling
on_message()<br />
{<br />
char *nam1=(char*)lParam;<br />
<br />
char Text[100];<br />
sprintf(Text,"%u",nam1);<br />
::MessageBox(NULL,Text,"address of Nam1",MB_OK);<br />
strcpy(nam1,"codeproject");<br />
::MessageBox(NULL,Text,"kola",MB_OK);<br />
<br />
}
Both of Code working Fine, but name Variable contain some garbage value insist of codeproject
Any help is greatly apreciated
-----------------------------
"I Think this Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
You are getting your levels of indirection mixed up.
ThatsAlok wrote:
char nam1[255];
Ok, nam1 is an array of 255 chars, can be accessed as a char*
ThatsAlok wrote:
(LPARAM)&nam1
You are passing the address of nam1, or a char**. You should drop the &.
ThatsAlok wrote:
char *nam1=(char*)lParam;
you are casting a char** to a char*, here is your error
ThatsAlok wrote:
strcpy(nam1,"codeproject");
You end up copying "codeproject" to the address of your string pointer, not the string as you expected.
To see this happen, open up the memory window in VC while you debug your code. watch the memory at mem1 and at the address of mem1.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Really i am doing very big Pointer Mistake,i am still not able to sort out my problem.
something is missing that i need.
PJ Arends wrote:
ThatsAlok wrote:
char *nam1=(char*)lParam;
you are casting a char** to a char*, here is your error
Here i don't understand what to do??
really i am feeling weak at pointer
-----------------------------
"I Think this Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
|
i ma goin to lost my Mind if i don't complete this.
the Mentle Wagon is standing outside to send me remand home.if i am not able to transfer the String though send message and get it back.
please please help me . give me right pointer or line,two line of code please
-----------------------------
"I Think this Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
PJ Arends wrote:
ThatsAlok wrote:
char *nam1=(char*)lParam;
you are casting a char** to a char*, here is your error
actually i am facing problem in this step,i can successfully passing integer value by address but problem is when everi try to change the value of that interger, my MSStudio fails.
ie little code here
sending code
int *ji=new int;<br />
*ji=10;<br />
::SendMessage((HWND)this->m_lHandle,WM_USER+90,0,(LPARAM)*ji);<br />
CString s;<br />
s.Format("%d",*ji);<br />
MessageBox(s);
Receiving Code
int * i=(int*)lParam;<br />
char Text[100];<br />
sprintf(Text,"%d ",*i);<br />
::MessageBox(NULL,Text,Text,MB_OK);<br />
<br />
*i=40;
hope any body understand my problem.
-----------------------------
"I Think this Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
ThatsAlok wrote:
::SendMessage((HWND)this->m_lHandle,WM_USER+90,0,(LPARAM)*ji);
ThatsAlok wrote:
int * i=(int*)lParam;
You have to fix one of these two lines. In the SendMessage line you are passing 10 (*ji, the value that ji points to) as the lparam. Then in the recieving function you are casting the 10 to an int pointer. So basicly you are telling the program that the integer you want to work with is stored at memory address 10. This most likely gives you an access violation.
In the following code, you will notice that ji is already a pointer (int *ji), so when we send it via SendMessage we do not try to deference it ((LPARAM)*ji) which ends up passing the value 10, nor do we take the address of it ((LPARAM)&ji) which is actually passing a pointer to a pointer to an int (int **).
int *ji = new int;
*ji = 10;
::SendMessage((HWND)this->m_lHandle,WM_USER+90,(LPARAM)ji);
...
int *i = (int *)lParam If you have trouble with pointers read those two excellent articles I pointed you to earlier.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
I found my mistake, Actually I am transferring data between two application as my pointer to memory in not globally accesible it showing garbage value.thanks for helping me, Sir
-----------------------------
"I Think this Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
hi,
i'm developing a plug in for IE to enable image resize. my problem is, there is no interface for me to receive event notification from the browse regarding the image. Is it any possibility for me to create a custom one, without rebuild the whole browser?
list of event handling interface in DWebBrowserEvent2
http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reflist_cpp.asp
|
|
|
|
|
Hello !
I have created some classes for Huffman Tree but when I call CreateNode function it appears an error about CharArray string.
What is this error ?
Who can help me about this problem ?
Thank you.
class Node
{
friend class HuffmanTree;
private:
char *CharArray;
unsigned long Frequency;
Node *pLeft;
Node *pRight;
….
}
class HuffmanTree
{
private:
Node *pRoot;
public:
HuffmanTree();
~HuffmanTree();
Node *CreateNode(char *CharArray, unsigned long Frequency);
….
}
Node *HuffmanTree::CreateNode(char *CharArray, unsigned long Frequency)
{
Node *NewNode = new Node(CharArray, Frequency);
NewNode->pLeft = NULL;
NewNode->pRight = NULL;
return NewNode;
}
Node::Node(char *CharArray, unsigned long Frequency)
{
int CharArrayLen = strlen(CharArray)+1;
this->CharArray = NULL;
// delete this->CharArray;
this->CharArray = new char(sizeof(char)*CharArrayLen);
strcpy(this->CharArray,CharArray);
this->Frequency = Frequency;
pLeft = NULL;
pRight = NULL;
}
|
|
|
|
|
Hello,
Your code seems OK except that (IMHO):
- you removed trailling ';' at the end of class declarations
- you do not check for CharArray consistency (e.g. != NULL)
- you should use a more structured syntax (as m_ prefix for data members)
- I would recommand the use of new char[] instead of new char(). It would imply the use of delete [] when destroying the memory block.
You should be more specific about your error. Do you receive an exception ?
|
|
|
|
|
Hello,
Thanks for your response.
I have updated my code and they run well.
I will ask you when i have new errors.
I don't have any exception currently.
Special thanks to you.
Best regards,
Hai
|
|
|
|
|
I wanted to detect if a system (host) has high speed USB ports (ver 2.0). To my surprise CodeProject yielded nothing.
Does anyone has idea where to find that code. Basically user level program that enumerated the hubs, ports and may be attached devices and their information (serial no, manufactuer etc)
paracha3
|
|
|
|
|
Try looking here[^], especially on this page[^].
Software Zen: delete this;
|
|
|
|
|
In the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DocFolderPaths
lives the paths to all users.
How may I enum them?
How may I find current user?
"Naked we come and bruised we go."
- James Douglas Morrison
Best Wishes,
ez_way
|
|
|
|
|