|
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
|
|
|
|
|
I should have qualified that with "a successful" FD_CONNECT.
Check for an error:
WSAEnumNetworkEvents(client_socket, g_hClientEvent, &NetworkClientEvents);
switch ( NetworkClientEvents.lNetworkEvents )
{
...
case FD_CONNECT:
if (0 != NetworkClientEvents.iErrorCode[FD_CONNECT_BIT])
printf("Connect Failed Message: \n\r");
else
printf("Client Connected Message: \n\r");
break;
...
}
Out of curiosity, why would you poll if you are using an event? It just needlessly eats CPU time.
|
|
|
|
|
Thanks Mark, that seem to work! I found in the MSDN that a FD_CONNECT error can be used to extract more information but, i am have not had success getting that information. I am guessing that FD_CONNECT_BIT is the indexing for the 10 array element of iErrorCode. Where can i find the other meanings of the array elements.
Additional error codes can be set when an application window receives a message. This error code is extracted from the lParam in the reply message using the WSAGETSELECTERROR macro. Possible error codes for each network event are listed in the following table.
Event: FD_CONNECT
Error code Meaning
WSAEAFNOSUPPORT Addresses in the specified family cannot be used with this socket.
WSAECONNREFUSED The attempt to connect was rejected.
WSAENETUNREACH The network cannot be reached from this host at this time.
WSAEFAULT The namelen parameter is invalid.
WSAEINVAL The socket is already bound to an address.
WSAEISCONN The socket is already connected.
WSAEMFILE No more file descriptors are available.
WSAENOBUFS No buffer space is available. The socket cannot be connected.
WSAENOTCONN The socket is not connected.
WSAETIMEDOUT Attempt to connect timed out without establishing a connection.
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
ScotDolan wrote: I am guessing that FD_CONNECT_BIT is the indexing for the 10 array element of iErrorCode. Where can i find the other meanings of the array elements.
Correctemundo. In the platform SDK, Windows Sockets 2, under WSANETWORKEVENTS struct:
iErrorCode
Array that contains any associated error codes, with an array index that corresponds to the
position of event bits in lNetworkEvents. The identifiers FD_READ_BIT, FD_WRITE_BIT and others
can be used to index the iErrorCode array.
They were too lazy to list them
ScotDolan wrote: Additional error codes can be set when an application window receives a message. This error code is extracted from the lParam in the reply message using the WSAGETSELECTERROR macro.
That would be if you were using windows-based events (WSAAsyncSelect) I believe.
Since you are using WSAEventSelect, you get the error messages codes from the WSANETWORKEVENTS struct.
Mark
-- modified at 18:35 Monday 22nd January, 2007
|
|
|
|
|
In my post above I stated "Since you are using WSAEventSelect, you get the error messages from
the WSANETWORKEVENTS struct."
I forgot to mention that it only applies when WSAGetLastError() after a failed non-blocking
socket op returns WSAEWOULDBLOCK. Sometimes the error is reported immediately and you'll never
get the FD_xxx event.
Mark
|
|
|
|
|
For what i am learning, it seems like WSAAsyncSelect() with WSAGETSELECTERROR marco might be a better solution than WSAEnumNetworkEvents(client_socket, g_hClientEvent, &NetworkClientEvents);
It seems that WSAAsyncSelect() will provide me with more information and less chance of missing a event.
A FD_CLOSE event produce the below error codes, but from what I understand if want to use WSAEnumNetworkEvents( ) I will not be able to get access to the below error message without a call to WSAGetLastError() and even that might miss a error code.
WSAEAFNOSUPPORT, Addresses in the specified family cannot be used with this socket.
WSAECONNREFUSED, The attempt to connect was rejected.
WSAENETUNREACH, The network cannot be reached from this host at this time.
WSAEFAULT, The namelen parameter is invalid.
WSAEINVAL, The socket is already bound to an address.
WSAEISCONN, The socket is already connected.
WSAEMFILE, No more file descriptors are available.
WSAENOBUFS, No buffer space is available. The socket cannot be connected.
WSAENOTCONN, The socket is not connected.
WSAETIMEDOUT, Attempt to connect timed out without establishing a connection.
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
ScotDolan wrote: For what i am learning, it seems like WSAAsyncSelect() with WSAGETSELECTERROR marco might be a better solution than WSAEnumNetworkEvents(client_socket, g_hClientEvent, &NetworkClientEvents);
It seems that WSAAsyncSelect() will provide me with more information and less chance of missing a event.
Unless you're using a buggy socket implementation, you won't miss any events using either method.
The difference is, WSAAsyncSelect uses a window to notify you. WSAEventSelect uses an event.
The window method is only really useful if you want to do asynchronous socket ops in a single
threaded app. If you have a separate thread for socket communication then an event is easier
and more efficient (the thread can wait on the event).
I'm not sure what you're getting at with the FD_CLOSE errors. I wouldn't expect any error
(or even look for one). After receiving the FD_CLOSE notification there's nothing that can
be done on the socket except reading any remaining unread/buffered receive data.
Mark
|
|
|
|
|
Also, see Mike's post below
|
|
|
|
|
Don't use a switch statement to check the network event. More than one event can be signalled at a time. The events will be OR 'd together.
Mike
|
|
|
|
|
Thanks Mike!
I didn't even think about that....I just copy/pasted from the OP's code
Mark
|
|
|
|
|
I didn't realize it was the OP's code (which was so long and unformatted that I barely even glanced at it). Sorry.
Mike
|
|
|
|
|
No problem. I always appreciate a heads up when I'm wrong
|
|
|
|
|
Hi,
I am using the Windows API to write some code that uses the end user's already installed Adobe Acrobat Reader to open up a *.PDF file. My problem is locating the file. Everytime Adobe upgrades to another version of Adobe Acrobat the pathname changes, say for example from
C:\Program Files\Adobe\Acrobat 5.0\Reader\Acrord32.exe
to
C:\Program Files\Adobe\Acrobat 7.0\Reader\Acrord32.exe
which at the moment causes the routine to fail unless I have specified the correct directory.
I am guessing there must be a much better way to do this, could anybody point me in the right direction? I would assume that you can ask the operating system what *.exe it uses to open up *.pdf and tell it to use that, but I am unsure how I code that.
Could someone point me in the right direction?
Thanks,
Joe
|
|
|
|
|
You can call ShellExecute using as argument the path of the document to open (instead of that of the executable, see MSDN documentation for details...).
hope that helps.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
TheDelChop wrote: I am guessing there must be a much better way to do this, could anybody point me in the right direction? I would assume that you can ask the operating system what *.exe it uses to open up *.pdf and tell it to use that, but I am unsure how I code that.
http://visualcpp.org/template_permalink.asp?id=125[^]
"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
|
|
|
|