|
The value in the text box is "50.56556", but the converted value is 5.
Also the value of the temp string is "5"
CString sz_DisplayStr;<br />
char *temp;<br />
<br />
m_cInitLat.GetWindowTextW(g_szDisplayStr);<br />
short length = g_szDisplayStr.GetLength();<br />
temp = (char*)(LPCTSTR)g_szDisplayStr.GetBuffer(length); <br />
m_dInitLat = atof(temp);
Also why has GetWindowText gone to GetWindowTextW?
Andy
|
|
|
|
|
atof doesn't like wide characters. try _wtof
|
|
|
|
|
Andy202 wrote: m_dInitLat
What's the type of that ?
|
|
|
|
|
Is this an MFC app, are you using DDX_Text function, because it will convert to an int or float for you.
Also CString is type char and you are using GetWindowTextW( ) which is a wide char API...try CStringW
-- modified at 14:16 Tuesday 18th September, 2007
---
Yours Truly, The One and Only!
devmentor.org
Design, Code, Test, Debug
|
|
|
|
|
If you are going to use CString (actually for any new development)
I highly recommend using generic character types instead of "char".
Generic-Text Mappings in Tchar.h[^]
All the CRT string functions have generic versions as well.
Routine Mappings[^]
There's also NO reason to use CString::GetBuffer() to read a CString.
I also recommend that any time you use a cast, make sure you really need
it and you're not just hiding improper usage of data types.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello.
When im binding my socket, i want to find out what local address that is connected to the internet, if there are any, and bind it to that address.
What is the best way to get this info? getaddrinfo() dosn't know if an address is connected to a lan that has no internet access, or if it is connected to a lan with an internet forwarding gateway, or if its directly connected to internet via PPPoE or something like that.
Maybe this info be found in the windows register?
(just using INADDR_ANY dosn't cut it in this case, i need a specific address to bind to)
To clearify what i want to use this for im writing an utility that moitors my internet traffic.
Thanks in advance for any input.
|
|
|
|
|
have you tried one of the following calls gethostbyaddr( ), gethostname( ) or getnameinfo( ) ?
---
Yours Truly, The One and Only!
devmentor.org
Design, Code, Test, Debug
|
|
|
|
|
Why won't using INADDR_ANY cut it? Not sure what you're trying to do, but if you're developing a server than the right thing to do is use INADDR_ANY when binding...in fact if you read any network book they all advise you to use INADDR_ANY when binding.
What about when you bind to a localhost that is multi-homed? It's better to use INADDR_ANY to let the TCP stack listen on ALL addresses and do the assignment for you.
---
Yours Truly, The One and Only!
devmentor.org
Design, Code, Test, Debug
|
|
|
|
|
Thanks for your replies!
Maybe im going about this the wrong way, what i want to do is to write an application that i can use to log my games network traffic. I am doing this by setting the SIO_RCVALL option with ioctl(), so that recvfrom() returns both sent and received packets. But using this option with ioctl() only works if i have bound my socket to a specific address, INADDR_ANY will cause it to fail.
I suppose i could just enumerate all addresses and listen to them all, but that feels like a waste, and could complicate things if this application is run on a gateway machine and not infact the machine that is running the game.
Since my game only supports multiplayer over internet via a matchmaking service, i need to know that im listening to the internet connected address.
Does anyone have any better suggestion on how to solve this?
|
|
|
|
|
I want to read string from regitsry and I wrote the code for it .Pls tell me what is wrong with it.
HKEY hKey;
DWORD MaxValue=0;
DWORD dwValue=0;
DWORD EADType=0;
CString szIdentityName;
CString szPath;
szPath=_T("Identities\\")+szIdentityID;//szIdentityID is name of identity
//Open Registry key
LONG lRetVal = RegOpenKeyEx(HKEY_CURRENT_USER,szPath,0,KEY_QUERY_VALUE,&hKey);
if( lRetVal == ERROR_SUCCESS)
{
char szString[255];
LONG lReturnCode = RegQueryValueEx( hKey,_T("Username"),0,&EADType,(BYTE *)szString,&MaxValue);
if( lReturnCode!= ERROR_SUCCESS)
::RegCloseKey(hKey);// Close key
else
::RegCloseKey(hKey);
szIdentityName.Format(_T("%x"),dwValue);
}
The string I am getting is NULL.
|
|
|
|
|
Look at the last parameter passed to RegQueryValueEx().
This variable needs to be initialized to the size of the return buffer, in BYTES (NOT characters).
On return, this variable will be set to the number of bytes copied to the buffer, including null terminators.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
What's wrong with you... stop reading the documentation! That's not what it's for.
|
|
|
|
|
LOL
Do people really just plug values into APIs until it compiles and then keep
changing the values until it runs? How do they find the APIs to begin with?
That's gotta be a frustrating way to write software.
To each his own, I guess
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: That's gotta be a frustrating way to write software a virus.
|
|
|
|
|
Mark Salsbery wrote: Do people really just plug values into APIs until it compiles and then keep
changing the values until it runs? How do they find the APIs to begin with?
Stop giving away my secrets, Mark. Good grief. Is nothing sacred anymore?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
pther wrote: Pls tell me what is wrong with it.
You are in a much better position to do this than us. What is the code (not) doing?
pther wrote: if( lReturnCode!= ERROR_SUCCESS)
::RegCloseKey(hKey);// Close key
else
::RegCloseKey(hKey);
Shouldn't you be calling RegCloseKey() regardless of what RegQueryValueEx() returns?
pther wrote: The string I am getting is NULL.
What string? Using the debugger, have you stepped through the code?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
question one:
CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
m_splitterWnd.CreateStatic(this,1,2);
m_splitterWnd.CreateView(0,0,RUNTIME_CLASS(CViewLeft),CSize (100,300),pContext);
m_splitterWnd.CreateView(0,1,RUNTIME_CLASS(CEditViewRight),CSize(100,100),pContext);
return TRUE;
}
the CViewLeft derived from CView, the CEditViewRight derived from CEditView, both them have OnDraw() function, but after debugging, only go into CViewLeft OnDraw(), not go into CEditViewRight OnDraw() , what's the matter?
question two:
I want to creat 2 rows 2 col views as following:
CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
m_splitterWnd.CreateStatic(this,2,2);
m_splitterWnd.CreateView(0,0,RUNTIME_CLASS(CFormViewUpLeft),CSize (100,300),pContext);
m_splitterWnd.CreateView(0,1,RUNTIME_CLASS(CFormViewUpRight),CSize(100,100),pContext);
m_splitterWnd.CreateView(1,0,RUNTIME_CLASS(CFormViewLowLeft),CSize (100,300),pContext);
m_splitterWnd.CreateView(1,1,RUNTIME_CLASS(CFormViewLowRight),CSize(100,100),pContext);
return TRUE;
}
but it is no function, any suggestion? thanks
|
|
|
|
|
Question one...
The edit view never has to draw anything, as its all covered up by an edit control - and *that* does it's own drawing.
Question two...
No idea. You'd best step into the CreateView functions and see why. I'd guess that one of the form view's dialogs aren't creating properly.
Try it with a very boring form view, with only a "hello world" static control, and build up from there.
Iain.
|
|
|
|
|
thanks Iain.
i will try as your suggestion.
|
|
|
|
|
hi can any body tell me how to add libraries in C++ using visual studio 2005
i downloaded JXTA-C and this requires APR ,OpenSSL ,zlib ,sqlite3 ,xml2 and expat but im not sure how to add them in Visual studio
|
|
|
|
|
On the Project-Explorer you choose the menu-item "Add an existing Element"
then you choose the .lib files.
It works also over the project properties, there is a special entry for extern libs.
Good luck
|
|
|
|
|
Anyone have any idea if Java is faster than C++ at run time?
This code was executed and it took java 2.5 secs to complete whereas it took c++ 11 secs.
Any input is appreciated.
thanks,
long start_time = System.currentTimeMillis();
System.out.println("Starting... ");
for (int i = 0; i < 1000000000; i++)
{
int j = 5;
j++;
j *= 2;
j /= 2;
j--;
double k = 5.0;
k++;
k *= 2;
k /= 2;
k--;
}
System.out.println("Ending. Time taken: " +
(System.currentTimeMillis() - start_time) + " milisec");
|
|
|
|
|
LCI wrote: This code was executed and it took java 2.5 secs to complete whereas it took c++ 11 secs.
There are way too many variables involved in order for this to be an accurate assessment. You are, in effect, comparing apples to oranges.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Not sure i understand why this is not an fair assessment. Can you elaborate when you say that i am comparing apples to oranges?
|
|
|
|
|