|
Hello,
I was wondering if anyone had a good idea on how to convert the following...
CString strN;
strN.Format("%d", nNum); // where nNum is something like 1123456
I would like to see the output of strN equal "1,123,456"
Is there a easy way to do this?
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
Someone mentioned the API GetNumberFormat a few days ago. It's the fancy way of doing it. I'm sure you can whip up a quick for loop that will do it just as well.
Regards,
Alvaro
Hey! It compiles! Ship it.
|
|
|
|
|
Why don t u just put a comma after the third, the sixth... char?
Just make a loop which every 3 char inserts
a comma with CString::Insert for instance.
Something like this:
for(i,from begining to the end of the cstring)
{
if(i==3or6or9)
urstring.insert(",") //not the good syntax but u get the idea across
}
Is it what u meant?
hope it s of any help 2 u.
syl
sysy
|
|
|
|
|
Hi,
In the tree control at the time of inserting an item I put an application specific CString data with it as following:
m_TreeCtrl.SetItemData (hItem, (DWORD) ("Hello"));
But, if I try to use GetItemData the following way, the conversion gives error. Please let me know how I can convert a DWORD into a CString:
DWORD selelection = m_TreeCtrl.GetItemData (hItem);
CString str = (CString) selelection ;
|
|
|
|
|
Binayak wrote:
m_TreeCtrl.SetItemData (hItem, (DWORD) ("Hello"));
First off you will have to understand the a string, is not a number, so it cannot be converted to a DWORD!
Now, SetItemData associates the tree node with a DWORD (unsigned long, methinks); it does not an object class, or a string array.
Now as it happens, you can use the DWORD value as a pointer to an object, which in your case would probably be a string resource (or dynamically created array, if the string is unknown at the time).
-----
TCHAR* czStringArray[]={"Hello","Old","Boy"};
..
m_TreeCtrl.SetItemData(hItem, (DWORD)0);
..
..
DWORD nIndex = m_TreeCtrl.GetItemData(hItem);
CString strAssociatedString = czStringArray[nIndex];
cout<<(LPCTSTR)strAssociatedString<<endl;
you could also do the same with pointers to string values as well.
I Dream of Absolute Zero
|
|
|
|
|
Hi!
Using the winsock functions I am trying to make a chat program...
I have a server program and a client program but my server can only handle one client at a time! (I have blocking mode connection)
How can I handle multiple clients?
Thank you very much for your future answers!
Well... I am a beginner ...
|
|
|
|
|
There are several solutions. In theory and in practice, supporting multiple sockets using blocking I/O is quite unusual. In general, one solution is to keep track of all clients using a map.
I recommend an OVERLAPPED I/O model or IOCP.
Kuphryn
|
|
|
|
|
Hi, all:
I have a weird problem and need your help. I have a main app and DLL. In the main app I have my object pointer (CMyObj* pObj) that has method like:
HRESULT TranslateIDToName( long lID, LPSTR cBuff, UNIT dwBuffSize );
this TranslateIDToName then calls some methods in DLL.
In main, I have something like this:
const DWORD dwBuffSize = 128;
TCHAR cBuff[dwBuffSize];
pObj->TranslateIDToName( lID, cBuff, dwBuffSize );
When I compile both main app and DLL in RELEASE, (both uses Multithreaded DLL as Runtime DLL ). It works fine! However, if I compile both in Debug ( both uses Debug Multithreaded DLL ), I step through the code, The TranslateIDToName() fills up the cBuff correctly and then return from the function.
The problem comes when the function returns to the caller:
pObj->TranslateIDToName( lID, cBuff, dwBuffSize );
The pObj is trashed with either garbage in the pObj or pObj = NULL. In either case, the pObj address changes before calling the method and right after return from the method ( the Stack really messed up!!). Of course, the app crashes!
I tried all the stuff I can think of, and no more ideas about what could be wrong.
Any suggestion and help will be highly appreciated. Thanks in advance.
Dion
|
|
|
|
|
What goes on inside of TranslateIDToName()?
Kuphryn
|
|
|
|
|
I got the problem fixed. the problem is the array index out of range inside the function. thanks anyway.
|
|
|
|
|
Recently I've spotted the download manager "Hidownload" (www.hidownload.com),
and I'm wondering how they're analyzing the web-traffic.
They're catching url's to streamed RealMedia files, WMV files etc.
Now I know how to get download URL's from IE etc.,
but they seem to be doing it on a very low level.
(You have to specify which network-card you want to monitor.)
Does anyone have a clue how to do this ?
|
|
|
|
|
Some of the packet sniffer programs do the same thing....
First thing they do, is put your NIC into a "promiscuous" mode. This mode allows your computer to see all packets that pass by it, not just the ones that are destined for that machine.
This also assumes that the "watching" computer is on the same segment of LAN (same part of the network switch) that the "watched" machines are on.
I don't know how to accomplish this, but I do know that this is NOT SUPPORTED ON ALL ethernet adapters.
-p
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.santacruznetworks.com">Santa Cruz Networks</A>
|
|
|
|
|
Uhh... ok
I don't think it's needed to see all packets that pass by though,
after all all you want is to know what files are accessed by what protocol.
No need to spy on other datatraffic, right..?
|
|
|
|
|
Uhhh...
how are you gonna figure out what higher-level-protocols are in use? except to watch all packets that go by, and analyze those....
Your ethernet card knows nothing about actual protocols. It only knows how to accept or deny ethernet packets.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.santacruznetworks.com">Santa Cruz Networks</A>
|
|
|
|
|
I should add that I misread a bit.
They are sitting on the network card, and analyzing all data that comes to it. They don't need promiscuous mode, unless you want to see traffic generated on other machines too.
But the premise is the same, they are just watching the traffic coming over the card, and it's pretty easy to catch all of that that stuff at that point.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.santacruznetworks.com">Santa Cruz Networks</A>
|
|
|
|
|
Would you know of any source / info that could show me how to do this ?
(Get the lowlevel-packet-data ?)
|
|
|
|
|
Hi,
Try Winpcap for windows (Packet Capture Library) or pcap with unix machines.
WinPCap is a free download.
Satya
|
|
|
|
|
I am converting a dos app to a windows app. The application changes passwords for given a given user. The dos application accepts servername, username, and password as cmd line arg's. They are defined as char username[50], password[128], etc.
My dialog takes the username and password as CString's.
How can I convert the CString to make it compatible with the char [50], etc above?
Thanks!
"Keyboard Error - Press F1 to Continue"
|
|
|
|
|
To make a CString from char[]:
char username[50];
CString str;
str = username;
To make a char[] from CString:
CString str;
char username[50];
memset(username, 0, 50);
strncpy(username, str.LockBuffer(), 50-1);
str.UnlockBuffer();
Hope that helps
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
The calls to LockBuffer() and UnlockBuffer() are not necessary as the second parameter to strncpy() is expecting a LPCSTR , which CString provides. The same is true for GetBuffer() and ReleaseBuffer() .
|
|
|
|
|
Thanks! That worked great.
Frank
"Keyboard Error - Press F1 to Continue"
|
|
|
|
|
i'm writting an application using c# that needs to communicate with the parallel port efficiently.
since win32 API are not fast enough, i wrote a win32 dll in c++ which uses assembly instructions to communicate with the port.
to read values from the port, i have a dll export which just returns the current value read from the port.
doing these read operation many times through dllImport is not efficient. so i need a way to return multiple values from the dll export.
i'm not sure whether it is possible to communicate with parallel port directly from c#.
please help me.
thanks.
|
|
|
|
|
I would ask this question in the CodeProject C# forum.
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
Hi,
Can someone tell me how to implement a UDP client. I already did a TCP client (it works fine), and read some of the MSDN on some differences. Is the only difference that I use SOCK_DGRAM instead of SOCK_STREAM ? Where can I find a list of the protocols address family (af) for the function socket?
Can some tell me where to find a detailed article or some sample code.
Thanks.
Jimmy
Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)
|
|
|
|
|
Well, during the creation you just pass the SOCKET_DGRAM instead of SOCKET_STREAM .
Then you might 'bind ' it to the local port (selecting the client side port number - unusual in tcp). If you don't do it it will choose the port automatically as in tcp, but most udp protocol expects also known client port, so usually you have to do it.
Then the usage is slightly different - on write side whatever you write it will send a packet immediatelly (no nagle alg. as in tcp) therefore if you write every byte separately, there will be separate packet for every byte (thus big overhead). You also have to specify the destination address - this is in tcp taken from the 'connect ', but there's no connect, because it's connectionless socket .
Reading part - here you can use the recvfrom or WSARecvFrom functions which returns also the address from where the datagram was sent and you can process it.
That's the difference between udp and tcp - in udp you can communicate with several computers using one socket. Therefore you have to specify the address in write and receive it in read.
Another issue with udp is that it's not reliable - it's only best effort service, so during design of the protocol you have to think about the fact, that the packets (data) can be lost - this is normally controlled by tcp and in that case the data are resend, but it's not valid in udp, here it's up to you.
That's just brief description of udp-tcp differences. I hope it's not too much confusing
|
|
|
|