|
I have, now. It doesn`t work, although I include stdio.h. It accepts the header (I mean, it finds it to include it), but when encountering sprintf_s() in sais "undeclared identifier".
I have also tried _itoa_s()
Link provided: http://msdn2.microsoft.com/en-us/library/0we9x30h(VS.80).aspx
When compiling, it seems ok, but when the application comes to using that part of the code, I get an application error code, and Windows asking me to send the info to microsoft.
I think that perhaps because I try to convert an unsigned int (DWORD - 64-bit unsigned integer.), using an int-converting function, might result in some buffer overflows. Can anyone suggest an alternative to _itoa_s (for using with unsigned int vars)? I can`t figure it out which is the one...
I think I should mention that I`m writing code for a Smart Device (pocket pc) using WM5.
|
|
|
|
|
sprintf_s will do the trick, I use it all the time... you are doing something wrong in the code?
can you try sprintf, maybe the api i provided earlier is not supported for smart device development?
---
Yours Truly, The One and Only!
devmentor.org
Design, Code, Test, Debug
|
|
|
|
|
Routine Required header
sprintf_s, <stdio.h>
_sprintf_s_l
Compatibility
Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003
It seems that it doesn`t support Windows Mobile. Similar results for sprintf
back to _ui64toa_s, I get an error, stating that radix outside of 2;36.
The code is here:
char* buffer;
int Radiux;
_ui64toa_s(GPSData.dwSatellitesInView,buffer,65,Radiux);
GPSLog.Write("Sats View:",15); GPSLog.Write(buffer,3);
_ui64toa_s(GPSData.dwSatelliteCount,buffer,65,Radiux);
GPSLog.Write("Sats Count:",15); GPSLog.Write(buffer,3);
where the 2 vars to be converted are DWORD.
Ideas ?
|
|
|
|
|
update to this:
I have initialised Radiux with 5 (just... picked it) and it won`t get out with error.
But I get strange data, when logging i get squares instead of some characters, yet some numbers are displayed, too. Who can tell me what does Radiux do ? I don`t understand from the function's description, found here: http://msdn2.microsoft.com/en-us/library/0we9x30h(VS.80).aspx
|
|
|
|
|
you have to set the radix value, which would be 10 for decimal.
try int Radiux = 10;
also try not to hard-code values...how is buffer defined? if it's defined like an array, and not alloacted on the heap you might want to change your ocde to something like this.
char buffer[100] = {0};
const int Radiux = 10;
...
_ui64toa_s( GPSData.dwSatellitesInView,
buffer,
sizeof(buffer),
Radiux );
(*)The "={0}" is a quick way to zero out the array
(*) if you use const int, the compiler is smart enough to replace put in the value (in this case 10) everwhere the variable show up, so no actual storage is required for the Radiux
I hope this helps!!!
---
Yours Truly, The One and Only!
devmentor.org
Design, Code, Test, Debug
|
|
|
|
|
Thanks a lot, for the code sample and especially for tips about hardcoding (though I've copy-pasted code provided on msdn2.microsoft.com !
Now... how about double to string and more important systemtime to double ?
|
|
|
|
|
I am glad to hear you got something working!
But if you're using a fixed declared array like I showed you then it's better to use sizeof().
Also you can't use strlen on a zeroed out buffer, right? you will get a size of zero!!!
Moreover, you are reading data into the buffer, strlen is the wrong function to use, your code has a bug in it.
If you're using the buffer again, just make sure to zero it out before the call to _ui64toa_s( )
memset( buffer, 0 ,sizeof(buffer) );
---
Yours Truly, The One and Only!
devmentor.org
Design, Code, Test, Debug
|
|
|
|
|
Well, I now did write sizeof(buffer) instead of fix size, and I understand the benefits, thanks to you.
I wonder how you found out about me using strlen, was just a trial (it wasn`t that obvious for me that was wrong before trying it), and I've modified the post when I`ve discovered that it doesn`t work. Indeed,learned on the hard way, strlen on a buffer is a No-No.
Thank's for the tip about zeroing the buffer before calling _ui64toa_s(). It does ring a bell, now., though in my application this part of the code comes to execution only when data exists in all fields I convert, so it's not posibile to have to convert an old value. Anyway, for future practice...
Concerning double to string, I used var-(int)var (where var was of type: double) to get the integer part (which was... int) and used _itoa_s to convert it into a string, and the rest I started multiplying by 10 (I only needed 4 digits after .) .
SYSTEMTIME is a structure type, in which all components are of type WORD. So perhaps _itoa_s() - or someone in it`s family - will do the trick.
Thanks again for all your help!
Best wishes!
---
One chance in a million is still a chance!
|
|
|
|
|
hey all!
is RichText Box supports the emoticons like we ve got in Msn or Yahoo? if Yes thn wats the procedure to include them using codes? and wat about the source of that images?
|
|
|
|
|
ddspliting wrote: is RichText Box supports the emoticons like we ve got in Msn or Yahoo? if Yes thn wats the procedure to include them using codes? and wat about the source of that images?
The only support I've heard about is that you can insert images in rich text. I've never done it myself, but I know you'll have to provide your own images.
Nathan
|
|
|
|
|
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
|
|
|
|
|