|
nooo, don't use GetBuffer() when only a Cast operator does the job. read my previous answer[^].
use GetBuffer() if you need to modify the CString buffer internally
|
|
|
|
|
strcpy(pchar, (LPCTSTR)str);
strcpy(pchar, (const char*)str);
strcpy_s(pchar, str.GetLength()+1, (LPCTSTR)str);
strcpy_s(pchar, str.GetLength()+1, (const char*)str);
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
If you want to use GetBuffer then you need to call ReleaseBuffer
|
|
|
|
|
WhiteSky wrote: If you want to use GetBuffer then you need to call ReleaseBuffer
Only if you change the contents, right?
|
|
|
|
|
a CString in unicode builds is a wchar_t array, not a char.
If you want to store chars in a CString in a unicode build then use the specific CStringA type.
If you want to use the generic CString, you'll need to convert the unicode CString to a char
type (using the WideCharToMultiByte() or similar).
Mark
|
|
|
|
|
Now, I code a program that manage PCs by using TCP with CSocket class.
However when I check on console by shell command,
"netstat -na"
I can see the server and client is connected like as,
163.152.216.228:9000 163.152.216.70:1234 ESTABLISHED
163.152.216.70:1234 163.152.216.228:9000 ESTABLISHED
But, when I send a message on the server or the client,
the two do not get a message. Also, don't occure the OnReceive() events.
So, I tried it on debugging mode and checked that
the "Send" Function had the correct values and run exactly.
What is the problem ?
How can I solve it ?
Please, help me~
Always beside you,
Focused on Focus KWON
|
|
|
|
|
Hi
You mean to say you have written your server and client from derived class of CSOcket rgt ?
If so can you give me more details ?
Is your server dialog based or console application ?
If its a dialog based one then OnReceive() will run - no problem
If its a console aplication then OnReceive() will not receive from client because you need to TranslateMessage() and PeekMessage() which you can do by using a hidden CFrameWnd class .This is a known problem because in a console app the message handlers are not active by default .
So usually , most servers are written with Win32 socket APIs . Its not advisable to use CSocket for a server - but client is ok
redindian
|
|
|
|
|
Focus KWON wrote: How can I solve it ?
This library makes sending recieving a breaze. Network Development Kit 2.0[^]
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
|
|
|
|
|
Hi
All
I want to use LoadStringResource() function in DLL. When i used this function in DLL code there is error as undeclare indentifier. Is there need to include any .H file to use it.plz send me info abt how to use LoadStringResource function.
Thnaks
Atool
M.Atul
|
|
|
|
|
The API is called LoadString()
|
|
|
|
|
Can any one guide me how do I monitor / check the health of a hard disk ?
I have gone through the msdn but I could not find in MSDN. My program is targettd to run on windows XP pro/2000 pro.
I found VDS interfaces for this functionality but they are only supported by Windows Vista.
can you please help me on this?
haribabu
|
|
|
|
|
kasturi_haribabu wrote: I have gone through the msdn but I could not find in MSDN. My program is targettd to run on windows XP pro/2000 pro.
look for WMI classes.. they have treasure hidden under them for this type of stuff
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
See here[^] if its helpfuls?
|
|
|
|
|
Hi everyone,
There is a need of embedding an application in an application, is there anyway? I mean I write an application and then I call CreateProcess to start a new application, all that I need is the new application will run in the window of my application.
Thanks in advance.
|
|
|
|
|
TPN wrote: There is a need of embedding an application in an application, is there anyway? I mean I write an application and then I call CreateProcess to start a new application, all that I need is the new application will run in the window of my application.
look some thing like containers.. read more about COM servers and DLLS
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
Thanks for your reply.
I would like to clarify that the first application is mine and I write it but the second application that I need to call is not mine, it is any other existing application...
|
|
|
|
|
Can anyone help me in finding out the speed (kbps ) of the connection .
I need to calculate the time required for an upload depending on file size and the network speed . I am unable to find any documentation on it .
Is anyone aware of how to get this speed programmatically in VC++ ?
Thanks In Advance
--Vijayeta
|
|
|
|
|
vijayeta wrote: Is anyone aware of how to get this speed programmatically in VC++ ?
try IPhelper Apis
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
vijayeta wrote: Is anyone aware of how to get this speed programmatically in VC++ ?
look here for more http://www.codeproject.com/internet/IPHelper.asp
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
Try to download a sample file using connection. File size/ time taken will give you the bandwidth. This is not accurate. Consider network latency & other factors
|
|
|
|
|
|
I want to customize the rebar's appearance(gripper, background...).I catch the NM_CUSTOMDRAW notification to do some processing, For example:
BOOL CMyReBar::OnNotify( WPARAM wParam, LPARAM lParam, LRESULT* pResult )
{
.........
NMHDR* pNMHDR = ( NMHDR* )lParam;
switch ( pNMHDR->code )
{
case NM_CUSTOMDRAW:
{
//DWORD dwStyle = GetDrawStyle();
//if (dwStyle>DRAW_ORIGINAL)
*pResult=DoCustomDrawXP(pNMHDR);
break;
}
...........
}
........
}
LRESULT CMyReBar::DoCustomDrawXP( NMHDR* pNMHDR)
{
LPNMCUSTOMDRAW lpNMCustomDraw = ( LPNMCUSTOMDRAW )pNMHDR;
LRESULT pResult = CDRF_DODEFAULT;
switch ( lpNMCustomDraw->dwDrawStage )
{
case CDDS_PREPAINT:
pResult = CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
//here I try to owner-draw the rebar control's appearance
DrawItem(lpNMCustomDraw);
pResult = CDRF_SKIPDEFAULT;
break;
}
return pResult;
}
But I find in this way I can only custom-draw the gripper. If there is a chevron button on the rebar, it is disappeared. How could I get the similar notification to draw the chevron button by myself?
Thanks
Benben
|
|
|
|
|
I am trying to develop a C++ socket object. This object will be initialized as client or server. After the client is initialized with server ip address and port number I want to create a thread and have the thread maintain the socket connection and report the sockets client state.
I am having difficult try to find out if the client socket status. Whether the client socket is connected after i call connect() and whether the client socket has been disconnected after a connection has been made. What is the best way to check the status of the client socket.
*********************************************************************************************
Function Name:
Purpose:
**********************************************************************************************/
void SocketLib5::RunClient(void)
{
int eResults;
int state = INIT_CLIENT;
//int iOptVal;
int iOptLen = sizeof(int);
bool bOptVal;
int bOptLen = sizeof(bool);
int iMode;
hostent* localHost;
char* localIP;
/*do something*/
while( isRunning )
{
// Checks to see in system in initialized
switch( state )
{
case INIT_CLIENT:
// Starts up the socket interfaces, library, and dlls
eResults = WSAStartup( MAKEWORD(2,2), &wsaData );
if ( eResults != NO_ERROR ){
WSACleanup();
break;
}
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = inet_addr( server_ip );
server_address.sin_port = server_port;
localHost = gethostbyname("");// Get the local host information
localIP = inet_ntoa (*(struct in_addr *)*localHost->h_addr_list);
client_address.sin_family = AF_INET;
client_ip = localIP;
state = CREATE_CLIENT;
break;
case CREATE_CLIENT: // Creates a socket
client_socket = socket(client_address.sin_family, SOCK_STREAM, PPROTO_TCP );
if ( client_socket == INVALID_SOCKET ){
closesocket(client_socket);
state = INIT_CLIENT;
break;
}
// Disable Blocking Mode function calls
//iMode = 0;
//ioctlsocket( client_socket, FIONBIO, (u_long FAR*) &iMode);
state = INIT_EVENT_CLIENT;
break;
case INIT_EVENT_CLIENT: // Configures Status Events
bOptVal = true;
//bOptLen = sizeof(bool);
// eResults = setsockopt(client_socket, SOL_SOCKET, SO_KEEPALIVE, (char*)&bOptVal, bOptLen);
// Create new event
g_hClientEvent = WSACreateEvent();
if (WSA_INVALID_EVENT == g_hClientEvent)
{
closesocket( client_socket );
state = INIT_CLIENT;
break;
}
eResults = WSAEventSelect(client_socket, g_hClientEvent, FD_READ | FD_WRITE | FD_ACCEPT | FD_CONNECT | FD_CLOSE);
if ( eResults == SOCKET_ERROR)
{
WSACloseEvent(g_hClientEvent);
closesocket(client_socket);
state = INIT_CLIENT;
break;
}
state = CONNECT_CLIENT;
break;
case CONNECT_CLIENT: // Accepts Server Socket
eResults = connect( client_socket, (SOCKADDR*) &server_address, sizeof(server_address) );
if( eResults == SOCKET_ERROR ){
state = INIT_CLIENT;
eResults = WSAGetLastError();
switch( eResults )
{
case WSAEWOULDBLOCK:
state = LOOP_CLIENT;
break;
case WSAEISCONN:
state = LOOP_CLIENT;
break;
default:
state = INIT_CLIENT;
cout << " connect error " << eResults <<endl;
closesocket(client_socket);
="" break;
="" }
="" }else{
="" state="LOOP_CLIENT;
" }
="" break;
="" case="" loop_client:=""
=""
="" eresults="WSAGetLastError();
" switch(="" )
="" {
="" wsaewouldblock:
="" wsaeisconn:
="" break;
="" default:
="" cout="" <<="" "="" connect="" error="" <<endl;
="" wsaenumnetworkevents(client_socket,="" g_hclientevent,="" &networkclientevents);
="" switch="" (="" networkclientevents.lnetworkevents="" fd_write:
="" printf("write="" message:="" \n\r");
="" fd_read:="" printf("client="" read="" fd_accept:
="" printf("accept="" fd_connect:
="" connected="" fd_close:="" connection="" lost:="" }="" switch
="" isrunning="" while="" loop
="" wsacloseevent(g_hclientevent);
="" closesocket(client_socket);="" wsacleanup();
="" return;
}
=""
<div="" class="ForumSig">Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
From the time you get a FD_CONNECT to the time you get a FD_CLOSE or a recv() call returns 0
the socket is connected.
I don't see in your code where you are waiting for an event. Using a wait function is much more
efficient than polling and WSAEnumNetworkEvents() should be used only when an event occurs.
Which part are you having a problem with?
Mark
|
|
|
|
|
In my code within switch case LOOP_CLIENT, I poll for events. I am getting a FD_CONNECT event but I know the clientsocket is not connected. In fact the server socket application is not even running yet. I was hoping that I would only get a FD_CONNECT event after the client socket connected with server socket, and a FD_CLOSE after a connection has been broken.
Right now, i can not garantee that which socket will be running first. So, i need some way to find the status of the client socket and possibly cancel/restart the connetion attempt.
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|