|
Alok, thats the first thing i tried.
char *stop;
UpdateData (TRUE);
input=strtod(m_display, &stop);
x=input;
m_display is the CString variable, input is double.
ERRORS:
error C2664: 'strtod' : cannot convert parameter 1 from 'class CString' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Help me!!!!!!!!!!!!!!!!!!!1
-hithesh
|
|
|
|
|
hithesh wrote:
input=strtod(m_display, &stop);
typecast that!-
input=strtod((LPCTSTR) m_display, &stop);
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Alok,
I typecasted it.
Error agian-
error C2664: 'strtod' : cannot convert parameter 1 from 'const unsigned short *' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Help me!!!!!!!!!!
-hithesh
|
|
|
|
|
hithesh wrote:
CString to char conversion
There are many ways to convert the CString to Char*.
Some of them I am going to mention here
Let for every case
CString strToConvert="123.34";
#1 by Copying
TCHAR *szNewString=new TCHAR[strToConvert.getLength()+1];
lstrcpy(szNewString,strToConvert);
#2 By Direct initialization
TCHAR *szNewString=strToConvert.GetBuffer(strToConvert.getLength());
......do What you want to do with string............
…after that…………………..
strToConvert.RelaseBuffer()
#3 directly to function! I.e. in your case strtod
strtod function is like this
double strtod( const char *nptr, char **endptr );
I believe you don't need convert it to anything, as it takes parameter of type const char *
anyways
char *strRet;
DOUBLE dVal=strtod(strToConvert,&strRet);
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
What happen to Forum today! every Body is looking for Conversion of string to Double.
Is everybody working on same project?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
ThatsAlok wrote:
Is everybody working on same project?
Did you not get the e-mail? It's due by day's end. Better get going!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
DavidCrow wrote:
Did you not get the e-mail? It's due by day's end. Better get going!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
dunno if its the same project.
I still haven't figured out a way.
Is it because, the cstring is defined in unicode and its storing in wide chars instead of chars?
Can I change the unicode option?
any solutions?
-hithesh
|
|
|
|
|
That is exactly your problem, the error you got before saying that it could not convert from 'const unsigned short *' to 'const char *' was your first hint. It sounds like you are building for Unicode.
You were given slightly incorrect direction by ThatsAlok; CString does have an overloaded operator for LPCTSTR , but strtod takes a LPCSTR . They are only same in ANSI builds; in Unicode builds, LPCTSTR becomes LPCWSTR .
CString is a TCHAR -based object, so you should be using TCHAR -based functions with it. Call ::_tcstod instead of strtod and that should work fine.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
James, can you give me an example. newbie here.
This is what i did -
input=_tcstod(m_display, &stop);
input is double, m_display is cstring, stop is char.
ERROR:
error C2664: 'wcstod' : cannot convert parameter 2 from 'char ** ' to 'unsigned short ** '
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
-hithesh
|
|
|
|
|
Once you start using TCHAR , you have to use it everywhere unless you are REALLY careful and know what you are doing:
<br />
TCHAR *pwcStop = NULL;<br />
<br />
input = ::_tcstod( m_display, &pwcStop );<br />
Also, if you do not need to know where parsing stopped at when converting the string to a double , you can just pass NULL as the second parameter.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
James, I cant thank you enough for this. I was up until 4 in the morning trying to find a solution.
Thanks again.
I need one more tiny help -
need to convert the float back to string to display it.
I am using - m_display.Format("%f", output);
which resulted in error -
error C2664: 'void __cdecl CString::Format(const unsigned short *,...)' : cannot convert parameter 1 from 'char [3]' to 'const unsigned short *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
-hithesh
|
|
|
|
|
[Remember to rate my posts if you found them helpful! ]
Remember what I said about "once you start using TCHAR "? All constant strings should be treated as TCHAR too, which means you wrap them in _TEXT() or _T() macros. (It is good practice to always use this macro, and use the corresponsing TCHAR -based versions of all string manipulation/processing functions. It takes a little while to get used to but quickly becomes second nature.)
That macro leaves the string unmodified in ANSI builds, or prepends the L modifier in Unicode builds, which converts it to a wide string, so...
<br />
m_display.Format( _T( "%f" ), output);<br />
-Becomes:
<br />
m_display.Format( L"%f", output);<br />
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
James, you just solved another problem.
Regarding the TCHAR, I am using it only once for pwsstop.
I guess I don't need to be worried.
Thanks again James. If I come across any more probs, I'll email you.
Hope u dont mind.
thanx thanx thanx!
-hithesh
|
|
|
|
|
I recommend NOT e-mailing him. That is what this forum is for.
|
|
|
|
|
I'll stick to the forum then.
-hithesh
|
|
|
|
|
you got your Answer!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hi folks,
here's the problem:
I have an internet-explorer-control in a dialog to retrieve a webpage. What I want is getting the webpage as a bitmap snapshot into the clipboard an then paste this into another document (in that case a MS Office Imaging file - tiff or mdi). Maybe, there are some other ideas to get the content of the webpage into the document (w/o usage of clipboard)?
With this document I do some OCR (with MS Modi-Component included in MS Office 2003).
Are there any ideas, code snippets etc. to do this job?
TIA
Mathefreak
|
|
|
|
|
|
Hi..
I have a problem with line that I draw using mouse click (LButtonDown). I use VC++ and MFC.
The problem is whenever I maximize or minimize the window the lines that I draw dissapear.
Below is my code for LButtonDown :
struct LINE
{
int xp[2];
int yp[2];
};
LINE L[100];
int Lnum = 0;
int icoord = 0;
int isline =0;
int psize = 1;
if(bLineFlag)
{
CPen penRed(PS_SOLID,1,RGB(250,0,0));
CPen *pOldPen = NULL;
pOldPen = pDC->SelectObject(&penRed);
CRect rcClient;
GetClientRect(&rcClient);
CPoint xpoint,ypoint;
L[Lnum].xp[icoord] = point.x / psize;
L[Lnum].yp[icoord] = point.y / psize;
if(icoord ==0)
{
icoord++;
isline = 0;
}
else
{
isline =1;
pDC->MoveTo(L[Lnum].xp[0],L[Lnum].yp[0]);
t.x = L[Lnum].xp[0];
t.y = L[Lnum].yp[0];
pDC->LineTo(L[Lnum].xp[1],L[Lnum].yp[1]);
p.x = L[Lnum].xp[1];
p.y = L[Lnum].yp[1];
icoord =0;
}
DrawCross(point,RGB(0,255,0),5,pDC->m_hDC);
}
Could anyone help me with the problem..
mafuza
|
|
|
|
|
You need to store your lines in memory (just the points coordinates) and then redraw everyting when the window is repainted. You will need to add the code for redrawing in OnDraw function
|
|
|
|
|
Hi cedric moonen..
thank you for your reply..so what's you saying is i have to transfer my coordinates from Lbuttondown to OnDraw?
I'm a newbie with MFC so the windows is repainted at the OnDraw function?
please reply thank you!!
|
|
|
|
|
What you can do is on the LButtonDown event, take the coordinates of the lines and store them somewhere (in your view or doc, I think document is better because it is designed for containing the data). Then invalidate the view (I think by calling Invalidate but not sure anymore), this will force your window to be redrawn (and will call OnDraw). Then in the OnDraw function, you draw all the lines that you have stored.
But there is an example of exactly the same case in the MSDN I think. This is called the scribble example (but I'm not sure)...
|
|
|
|
|
Hi all,
I want to add proxy support to my application. Now I know how to get the Automatic Proxy URL, but how do I get the right data from this file?
Thanks!
Geert
http://geert.yoki.org
|
|
|
|
|
Hello All!
Have a problem with changing font color in static. I do like this:
<br />
LRESULT CPage::OnHandleAll(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)<br />
{<br />
if ((uMsg == WM_CTLCOLORSTATIC) && (HWND)lParam == GetDlgItem (IDC_STATIC_TEXT_ABONENT_TYPE))<br />
{<br />
ModifyStyle( 0, SS_NOTIFY );<br />
HBRUSH hBr = NULL;<br />
HDC hDC = (HDC)wParam;<br />
SelectObject( hDC, GetFont() );
SetTextColor( hDC, RGB(255,255,0));<br />
SetBkMode( hDC, TRANSPARENT );<br />
hBr = (HBRUSH)GetStockObject( HOLLOW_BRUSH );<br />
return (LRESULT)hBr;<br />
}<br />
}<br />
But color not changing in IDC_STATIC_TEXT_ABONENT_TYPE =(
|
|
|
|