|
[Perplexed!]
I already tried to do the following:
<br />
{<br />
...<br />
CString strx;<br />
CDialog *pDialog;<br />
<br />
pDialog -> GetDlgItemText(IDC_WELLRAD,strx); <br />
x = atof((LPCTSTR)strx);<br />
...<br />
}
and toxcct's code as well. The first gave an ASSERT error while the other gave an unhandled exception in mfc42d.dll, in wincore.cpp ->C:\...\MFC\SRC\WINCORE.CPP at the line *** below:
<br />
HWND hWnd = ::GetDlgItem(m_hWnd, nID);<br />
if (hWnd != NULL)<br />
{<br />
int nLen = ::GetWindowTextLength(hWnd);<br />
::GetWindowText(hWnd, rString.GetBufferSetLength(nLen), nLen+1);
rString.ReleaseBuffer();<br />
}<br />
I'm trying to get the value of an edit box for use in a function outside CDialog, which would carry out computations on the value entered by a user. I don't understand why i get these errors.
|
|
|
|
|
aaadetos wrote:
I'm trying to get the value of an edit box for use in a function outside CDialog, which would carry out computations on the value entered by a user.
The function in which you are getting the Text is outside CDialog??
|
|
|
|
|
Yes, it is. The text: numerical data of type double, is to be used as a variable in a math computation in a function outside of CDialog.
|
|
|
|
|
If what i understood is correct ...
you are doing like this....
void CXDialog::Function1()
{
SomeOtherClassObj.YourMathFunction();
}
void CSomeOtherClass::YourMathFunction()
{
GetTheText();
//TODO
}
Think you have to pass the dialog pointer to your function outside the dialog class...
like...
void CXDialog::Function1()
{
SomeOtherClassObj.YourMathFunction(this);
}
void CSomeOtherClass::YourMathFunction(CDialog *pDialog)
{
pDialog -> GetDlgItemText(IDC_WELLRAD,strx);
x = atof((LPCTSTR)strx);
//TODO
}
Or get the Edit control text inside the Dialog class which contains the control and pass the text to your math function...
Hope this will help you ....
|
|
|
|
|
Thanks a lot Dreamz...
I actually decided to add a member function to my dialog's class, viz:
<br />
double CKuchukDlg::getrw(double x)<br />
{<br />
CString strx;<br />
<br />
GetDlgItemText(IDC_WELLRAD,strx);<br />
x = atof(strx);<br />
<br />
return x;<br />
}
i then used the function in my math function, to get the value of the edit box:
<br />
void bessk0(double *x,double *k0,int nSize);<br />
void bessk1(double *x,double *k1, int nSize);<br />
void ei(double *x, double *expi, int nSize);<br />
<br />
void unbound(double *unbd, int nSize)<br />
{<br />
enum{nSize = 100};<br />
double A[nSize],B[nSize],k0[nSize],k1[nSize],s[nSize],expi[nSize],a[nSize],b[nSize];<br />
<br />
<br />
double x=0;<br />
s[0] = 1;<br />
a[0] = x*sqrt(s[0]);<br />
b[0] = 2*sqrt(s[0]);<br />
<br />
bessk0(a,k0,nSize);<br />
bessk1(a,k1,nSize);<br />
ei(b,expi,nSize);<br />
<br />
A[0] = k0[0]/(x*sqrt(s[0])*k1[0]);<br />
B[0] = (1-exp(-2*sqrt(s[0])))/(2*sqrt(s[0]));<br />
<br />
unbd[0]=0.5*(A[0]-B[0]-expi[0]);<br />
<br />
<br />
CKuchukDlg MyClass;<br />
MyClass.getrw(x);<br />
x = MyClass.getrw(x);<br />
<br />
for (int t=1;t<nSize;t++)<br />
{<br />
<br />
s[t] = 2*t*PI;<br />
a[t] = x*sqrt(s[t]);<br />
b[t] = 2*sqrt(s[t]);<br />
<br />
bessk0(a,k0,nSize);<br />
bessk1(a,k1,nSize);<br />
ei(b,expi,nSize);<br />
<br />
A[t] = k0[t]/(x*sqrt(s[t])*k1[t]);<br />
B[t] = (1-exp(-2*sqrt(s[t])))/(2*sqrt(s[t]));<br />
<br />
unbd[t]=0.5*(A[t]-B[t]-expi[t]);<br />
}<br />
}
While the code compiles without error, i still obtain a debug assertion failure in wincore.cpp!!
Is there a better way of calling my getrw(double x) in my math fxn without having this problem?
Thank you.
|
|
|
|
|
aaadetos wrote:
CKuchukDlg MyClass;
MyClass.getrw(x);
x = MyClass.getrw(x);
You have got a dialog displayed already from where you get the Edit control' text.That is an existing instance of the class CKuchukDlg.You have to use the same instance for further operations.
Here what you do is,you have created an instance of CKuchukDlg.But no Dialog window is there for the paticular instance.And you are trying to get the Text from the Edit control.There is no such window to get the Text from.So you are getting the assertion failure.
This why i asked to use "this" poiter.
If you are calling "unbound(double *unbd, int nSize)" from your dialog class
pass the pointer of your "Current Dialog Window" to the function.
void unbound(double *unbd, int nSize,CDialog *pDialog)
{
........
//x = MyClass.getrw(x);
x = pDialog->getrw(x);
........
}
You can call the function like this...
SomeObj.unbound(x,y,this);
Better you can pass the Text from the edit control itself to the function.
void unbound(double *unbd, int nSize,double DataFrom_getrw)
{
........
//x = MyClass.getrw(x);
x = DataFrom_getrw;
........
}
|
|
|
|
|
In your code
CDialog *pDialog;<br />
<br />
pDialog -> GetDlgItemText(IDC_WELLRAD,strx);
you have not assigned a value to pDialog after declaring it and before using it.
pDialog must be assigned as a pointer to your dialog.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
Antony M Kancidrowski wrote:
You do not need to cast to CEdit as CWnd will do
i know, but i prefer a most "understandable" code than one that works, but which you cannot debug...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I would like to generate human friendly product keys similar to what Microsoft and many others do. The keys should have the property of being 25 or 30 characters.
I need to be able to generate many individual keys, on the order of 10000 or so probably.
They should be generated in such a way that it is easy to verify that a particular key is one which I generated, but hard for someone else to generate the identical list of keys. I am aware of commerical products that do this, but it seems like something that wouldn't be that hard to reinvent.
It appears to me that this requirement calls for use of an asymmetric crypto algorithm.
Like all locks, this one is intended to help honest people stay honest. I'm not too worried about the hacker with a disassembler, but it ought to be at least challenging for him to generate a valid product key.
Any suggestions, especially pointers to sample code, will be greatly appreciated.
Jim
|
|
|
|
|
this might work:
assuming you're using RSA (or something similar):
1. come up with a public/private key pair.
2. put one of your keys in your app, and one in your license creator.
3. generate a series of short plaintext strings like this: "SomeText_######" , where ###### is an incrementing counter, or a time stamp, or some other unique value (just to ensure that no two codes are the same). the actual content doesn't matter to the algorithm, only that the form of the string can be verified when decoded.
4. encrypt each of those strings with your license creator key. then output them as hex strings: a0b4-d3ee-091c-etc. the code length will depend on how big the input data was.
5. distribute those keys to your users.
6. when your app gets a license code, decrypt it using the key from #2.
7. if the decrypted code matches the form from #3, it's a valid license code.
take a look at crypto++[^].
Software | Cleek
|
|
|
|
|
That's a good idea, but I have a question about step #5, "distribute those keys to your users".
I would like to have a fixed length key of no more than 30 characters, similar to what microsoft does. I'm not sure that's feasable if the key is just hex strings. I guess I don't grock the relationship between the lenght of the plantext and the lenght of the cyphertext.
Perhaps I should encode the key with a base 26 system.
I already incorporate parts of crypto++ in my app for symmetric encryption, it is an excellent product.
|
|
|
|
|
Jim Howard wrote:
I guess I don't grock the relationship between the lenght of the plantext and the lenght of the cyphertext.
i believe RSA requires the block size to be the same as the key length. so, a 32 byte code string, based on 16 hex numbers, gives you a 128-bit key - not very big.
Jim Howard wrote:
Perhaps I should encode the key with a base 26 system
or base32. it gives you an extra byte of data for every 8 code charaters vs base16. (8 chars b32 = 40 bits. 8 chars b16=32 bits)
Software | Cleek
|
|
|
|
|
I search to know (in C++ & MFC) when a windows is finished to be move or resizing. To repaint it only at the end, not durin event.
Can you help me
Thank
Thierry
|
|
|
|
|
Only the user knows.
(The user is the warm thing attached to the mouse.)
The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).
|
|
|
|
|
you can make a heavy overload of WM_LBUTTONDOWN , WM_LBUTTONUP and WM_DRAGANDDROP (or something like that) with a set of flags to try to know if, when the mouse button is getting up, it is the end of your resizing/moving action.
have a good (head)-day (headache... muwahahahh )
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
If your client calls your child window properly, and you implement your child window properly, you might find this one useful: WM_SETREDRAW
However, if you are a top level window, then maybe you can watch for WM_WINDOWPOSCHANGING, block your drawing, and then perform all your drawing when you get the WM_WINDOWPOSCHANGED.
The WM_WINDOWPOSCHANGING message is sent to a window whose size, position, or place in the Z order is about to change as a result of a call to the SetWindowPos function or another window-management function. The WM_WINDOWPOSCHANGED message is sent to a window whose size, position, or place in the Z order has changed as a result of a call to the SetWindowPos function or another window-management function.
Also read these two : WM_ENTERSIZEMOVE and WM_EXITSIZEMOVE
|
|
|
|
|
Fine, Thank you I try that.
|
|
|
|
|
How can I make this message box work?
<br />
CString * s = (CString *)lParam;<br />
AfxMessageBox(s);<br />
delete s;<br />
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
AfxMessageBox does not take a CString * parameter.
Assuming lParam really is is CString * try:
...
AfxMessageBox(*s);
...
The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).
|
|
|
|
|
Sorry, I guess I needed more detail
Here is the whole function:
<br />
LRESULT CLAMsgSwDlg::OnMyConnect(WPARAM, LPARAM lParam)<br />
{<br />
CString * s = (CString *)lParam;<br />
AfxMessageBox(s);<br />
delete s;<br />
return 0;<br />
}<br />
I've tried it that way and I still get an error. But after stepping thru it I found that I was getting an error on the "delete s;". So thanks for that help...now another question. Am I not supposed to delete this pointer so that it does not hold memory and become a leak?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
s ( via lParam ) is not allocated by you, so you don't have to delete it yourself; should be done by the one who initiate the message.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
I'm trying to send back a pointer to a CString from a thread that I am creating.
After my thread connects to socket sever and a call is made to the OnConnect event then I send message to the main app and pass a pointer to some data.
<br />
void CMyThread::OnConnect()<br />
{<br />
MessageBox(NULL, "OnConnect", "CMyThread", MB_OK);<br />
CString threadID = "TESTER";<br />
if (!PostMessage(myHandle->m_hWnd, UWM_CONNECTED, 0, (LPARAM)&threadID))<br />
MessageBox(NULL, "Error Posting Connection Message", "Error on PostMessage", MB_OK | MB_ICONEXCLAMATION);<br />
}<br />
then in my main app I want to do something with the data, (for testing purposes, I just pop up a message box with the data sent) when it's received by my main app. But all i get is, I assuming the pointer handle to the CString of the pointer from my thread....and it's garbage when I show it thru afxmessagebox.
<br />
LRESULT CLAMsgSwDlg::OnMyConnect(WPARAM, LPARAM lParam)<br />
{<br />
CString * s = (CString *)lParam;<br />
AfxMessageBox("Here in my main app");<br />
AfxMessageBox(*s);<br />
return 0;<br />
}<br />
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
You are running into scope problems. The CString threadID is going out of scope, and being destroyed, at the end of your OnConnect() method. As a result, the pointer that is recieved by the OnMyConnect() method is no longer valid.
"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!
|
|
|
|
|
OHHH!! I see what you are saying. That threadId is getting destroyed as soon as I leave the onConnect function.
Okay so how can I keep it in scope until my main app receives the data?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Tom Wright wrote:
I'm trying to send back a pointer to a CString
is CString::Format() function help ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|