|
Hi,
I need to start and stop one exe from an application. I seeing the status of start and stop of the exe. The problem is out side of this application, if I try to start this exe, I get the message box saying that the exe is already running. I am unable to see the exe in the Task Manager, How can this be possible??
Regards,
Satya Prasad
|
|
|
|
|
See I dont know the exact reason, But for finding the exe, it must be having some process area, there are some APIs exists to enumerate the Process and threads.
EnumProcesses
EnumProcessModules
Then this link
http://support.microsoft.com/default.aspx?scid=KB;en-us;q178893
might help you to kill application safely.
VikramS
|
|
|
|
|
server is using MFC socket class on win2K
client using sockets on solaris 2.3
I cant seem to receive anything at Server side coz I put breakpoints in OnReceive() & Receive() of the sock function.
connection is ok coz server side shows connected IP address n port on the application window, just that no data received.
This is the CLIENT side
connectServer(&clientAddr,&sock); //see below
//fread data from a file to a buffer
send(sock,buffer,size0f(buffer),0); //
connectServer(struct sockaddr_in *clientAddr, int *sock)
{
arr[1] = "serverPC";
hp = gethostbyname(arr[1]);
*sock = socket(AF_INET,SOCK_STREAM,0)
servAddr.sin_family = AF_INET;
bcopy(hp->h_addr,&servAddr.sin_addr, hp->h_length);
servAddr.sin_port = htons(9000);
result = connect(*sock,&servAddr,sizeof(servAddr) );
}
server side goes like tis
Server.Create(9000,SOCK_STREAM,myIP);
Server.Listen();
CSock::OnAccept(int nErrorCode)
{
Accept(socket,0,0)
.......
}
void CSock::OnReceive(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
long dataLength;
Receive(&dataLength, 4);
if (dataLength > 0&& dataLength < 100000) //Just to make sure the client doesn't crash the server)
{
byte* message = new byte[dataLength+1];
int nRec = Receive(message,dataLength);
message[nRec] = '\0';
// ::SendMessage(hParent,WM_RECEIVE_MESSAGE,(WPARAM)m
essage,(LPARAM)nSocket);
}
CSocket::OnReceive(nErrorCode);
}
omitted the err checking codes
any idea where went wrong?
server n client code is found at
http://www.codeguru.com/forum/attachment.php?s=&postid=916238
|
|
|
|
|
I just need to implement a listening socket that can accept and receive data.
Anyone?
|
|
|
|
|
I have made my header file, and then when I want to use its functions .Net gives me the error:
.....................
error LNK2005
.....................
error LNK2005: "public: char __thiscall WsaP::Show(int)" (?Show@WsaP@@QAEDH@Z) already defined in Test.obj
It's a long time that I don't work with my programs since of it. If you can help me.
Thanks.
|
|
|
|
|
Because you have multiple invoke of this function by header or cpp files (first invoke is in test.cpp or by header files). Make diferent calling include files with invokes only one.
|
|
|
|
|
Add something similar to the following to the the .h file:
#if !defined(some_unique_identifier_here)
#define some_unique_identifier_here
#pragma once
#endif // !defined(some_unique_identifier_here)
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Hi,
How do i format text in a DHTML edit control..
There are lots of clases generated with this active x control... so i'm not sure how to use it??
Need some advice...a litle hint maybe..
|
|
|
|
|
I want to write a program which, while running, would intercept keyboard input and modify it if desired. For example, if the key '\' is pressed, my program would intercept the keystroke and then instead make the computer believe the user had typed 'hi'. Unfortunately, I don't know where to begin, any help would be appreciated.
|
|
|
|
|
On the first page of CP, Most Popular->• Three Ways to Inject Your Code into... , In that he explained how to Change the WinProc....(This is only the place where you can fool the application , by hacing WinProc)i.e when u press keyboard, you can change the stuff, ...I guess you will run that code.
regards
Balkrishna Talele
|
|
|
|
|
Look http://www.codeguru.com/Cpp/W-P/system/keyboard/article.php/c5699/
|
|
|
|
|
hi
i have an STL string object, which has a NULL char in the MIDDLE. For ex:
#include<string>
using namespace std;
....
string str = "abcdefghijklmnopqrstuvwxyz";
str[11] = 0; // str.size() still equals 26
Now i want to convert this string to _bstr_t object, retaining the NULL char and the chars after that. I tried this:
_bstr_t bstr = str.c_str();
But only first 11 chars are being copied(till NULL char). Pls help
TIA
|
|
|
|
|
A string containig a \0 in the middle is not a string in any c-derived language. You are probably better off in not trying to pretend that it is one.
Make your string a vector of bytes, and it can happily contain as many \0 as you need.
What are you trying to achieve? Maybe stepping back and taking the time to describe your problem in words will help you to find a new approach to its solution.
Sandeep Kulkarni wrote:
str[11] = 0; _bstr_t bstr = str.c_str();
But only first 11 chars are being copied(till NULL char).
Any other behaviour would be a clear violation of guarantees given by the std::string. \0 is a string terminator.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
Actually the scenario is a bit different. I have a string, which needs to be encrypted first, then be supplied to another component. While encrypting a "valid" string, there is every possibility(perhaps there is!) that some of the chars be substituted by NULL char. THIS IS VERY MUCH ALLOWED HERE!!!
Now such an encrypted string needs to be passed to a method of a COM component which accepts nothing other than _bstr_t !!! Hence the problem!!
Thanx anyway,More help will be appreciated.
|
|
|
|
|
So you can't change the code of the COMponent?
And the way of encryption you need to use is also fixed?
Too bad.
bstr_t is holding strings in UNICODE encoding, and constructors and operators that take char* are converting the strings to Unicode.
Unicode strings sould be resistant to a single \0, as they are only terminated by \0\0.
Maybe you can assemble the bstr_t from your string by adding the part until the first \0, then subsequently +=ing the \0, the part until the next \0, the next \0 and so on?
Try it out.
Sorry that I am of no help here.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
I am curious if anyone know of a good tutorial to learn how to make a SIMPLE client server program. All I wish to do is make a server listen on a port on my local network and a client be on all the computers of the network. What i wish to do hopefully is allow the clients to send a message to the server with various messages like "Computer user needs help" or whatever. I have seen some examples on the net but the code is simply just given and not explained and unfortunately for me I don't have enough knowledge with the winapi yet to fully understand what alot of the functions mean. I tutorial using mfc would be great. Or code that is portable to a mfc program. Your help is gratefully appreciated.I know there are programs like WinChat and Netsend and so on but thats beside the point.
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
use the following smaple code...Create WIn32 console and paste the server.c in one project and client.c in another win32 copnsole project
// Module Name: Server.c
//
// Description:
// This example illustrates a simple TCP server that accepts
// incoming client connections. Once a client connection is
// established, a thread is spawned to read data from the
// client and echo it back (if the echo option is not
// disabled).
//
// Compile:
// cl -o Server Server.c ws2_32.lib
//
// Command line options:
// server [-p:x] [-i:IP] [-o]
// -p:x Port number to listen on
// -i:str Interface to listen on
// -o Receive only; don't echo the data back
//
#include <winsock2.h>
#include <stdio.h>
#include <stdlib.h>
#define DEFAULT_PORT 5150
#define DEFAULT_BUFFER 4096
int iPort = DEFAULT_PORT; // Port to listen for clients on
BOOL bInterface = FALSE, // Listen on the specified interface
bRecvOnly = FALSE; // Receive data only; don't echo back
char szAddress[128]; // Interface to listen for clients on
//
// Function: usage
//
// Description:
// Print usage information and exit
//
void usage()
{
printf("usage: server [-p:x] [-i:IP] [-o]\n\n");
printf(" -p:x Port number to listen on\n");
printf(" -i:str Interface to listen on\n");
printf(" -o Don't echo the data back\n\n");
ExitProcess(1);
}
//
// Function: ValidateArgs
//
// Description:
// Parse the command line arguments, and set some global flags
// to indicate what actions to perform
//
void ValidateArgs(int argc, char **argv)
{
int i;
for(i = 1; i < argc; i++)
{
if ((argv[i][0] == '-') || (argv[i][0] == '/'))
{
switch (tolower(argv[i][1]))
{
case 'p':
iPort = atoi(&argv[i][3]);
break;
case 'i':
bInterface = TRUE;
if (strlen(argv[i]) > 3)
strcpy(szAddress, &argv[i][3]);
break;
case 'o':
bRecvOnly = TRUE;
break;
default:
usage();
break;
}
}
}
}
//
// Function: ClientThread
//
// Description:
// This function is called as a thread, and it handles a given
// client connection. The parameter passed in is the socket
// handle returned from an accept() call. This function reads
// data from the client and writes it back.
//
DWORD WINAPI ClientThread(LPVOID lpParam)
{
SOCKET sock=(SOCKET)lpParam;
char szBuff[DEFAULT_BUFFER];
int ret,
nLeft,
idx;
while(1)
{
// Perform a blocking recv() call
//
ret = recv(sock, szBuff, DEFAULT_BUFFER, 0);
if (ret == 0) // Graceful close
break;
else if (ret == SOCKET_ERROR)
{
printf("recv() failed: %d\n", WSAGetLastError());
break;
}
szBuff[ret] = '\0';
printf("RECV: '%s'\n", szBuff);
//
// If we selected to echo the data back, do it
//
if (!bRecvOnly)
{
nLeft = ret;
idx = 0;
//
// Make sure we write all the data
//
while(nLeft > 0)
{
ret = send(sock, &szBuff[idx], nLeft, 0);
if (ret == 0)
break;
else if (ret == SOCKET_ERROR)
{
printf("send() failed: %d\n",
WSAGetLastError());
break;
}
nLeft -= ret;
idx += ret;
}
}
}
return 0;
}
//
// Function: main
//
// Description:
// Main thread of execution. Initialize Winsock, parse the
// command line arguments, create the listening socket, bind
// to the local address, and wait for client connections.
//
int main(int argc, char **argv)
{
WSADATA wsd;
SOCKET sListen,
sClient;
int iAddrSize;
HANDLE hThread;
DWORD dwThreadId;
struct sockaddr_in local,
client;
ValidateArgs(argc, argv);
if (WSAStartup(MAKEWORD(2,2), &wsd) != 0)
{
printf("Failed to load Winsock!\n");
return 1;
}
// Create our listening socket
//
sListen = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
if (sListen == SOCKET_ERROR)
{
printf("socket() failed: %d\n", WSAGetLastError());
return 1;
}
// Select the local interface, and bind to it
//
if (bInterface)
{
local.sin_addr.s_addr = inet_addr(szAddress);
if (local.sin_addr.s_addr == INADDR_NONE)
usage();
}
else
local.sin_addr.s_addr = htonl(INADDR_ANY);
local.sin_family = AF_INET;
local.sin_port = htons(iPort);
if (bind(sListen, (struct sockaddr *)&local,
sizeof(local)) == SOCKET_ERROR)
{
printf("bind() failed: %d\n", WSAGetLastError());
return 1;
}
listen(sListen, 8);
//
// In a continuous loop, wait for incoming clients. Once one
// is detected, create a thread and pass the handle off to it.
//
while (1)
{
iAddrSize = sizeof(client);
sClient = accept(sListen, (struct sockaddr *)&client,
&iAddrSize);
if (sClient == INVALID_SOCKET)
{
printf("accept() failed: %d\n", WSAGetLastError());
break;
}
printf("Accepted client: %s:%d\n",
inet_ntoa(client.sin_addr), ntohs(client.sin_port));
hThread = CreateThread(NULL, 0, ClientThread,
(LPVOID)sClient, 0, &dwThreadId);
if (hThread == NULL)
{
printf("CreateThread() failed: %d\n", GetLastError());
break;
}
CloseHandle(hThread);
}
closesocket(sListen);
WSACleanup();
return 0;
}
--------------------------------------------------------------------------
//Now paste Client.c in Another Project
// Module Name: Client.c
//
// Description:
// This sample is the echo client. It connects to the TCP server,
// sends data, and reads data back from the server.
//
// Compile:
// cl -o Client Client.c ws2_32.lib
//
// Command Line Options:
// client [-p:x] [-s:IP] [-n:x] [-o]
// -p:x Remote port to send to
// -s:IP Server's IP address or host name
// -n:x Number of times to send message
// -o Send messages only; don't receive
//
#include <winsock2.h>
#include <stdio.h>
#include <stdlib.h>
#define DEFAULT_COUNT 20
#define DEFAULT_PORT 5150
#define DEFAULT_BUFFER 2048
#define DEFAULT_MESSAGE "This is a test of the emergency \
broadcasting system"
char szServer[128], // Server to connect to
szMessage[1024]; // Message to send to sever
int iPort = DEFAULT_PORT; // Port on server to connect to
DWORD dwCount = DEFAULT_COUNT; // Number of times to send message
BOOL bSendOnly = FALSE; // Send data only; don't receive
//
// Function: usage:
//
// Description:
// Print usage information and exit
//
void usage()
{
printf("usage: client [-p:x] [-s:IP] [-n:x] [-o]\n\n");
printf(" -p:x Remote port to send to\n");
printf(" -s:IP Server's IP address or host name\n");
printf(" -n:x Number of times to send message\n");
printf(" -o Send messages only; don't receive\n");
ExitProcess(1);
}
//
// Function: ValidateArgs
//
// Description:
// Parse the command line arguments, and set some global flags
// to indicate what actions to perform
//
void ValidateArgs(int argc, char **argv)
{
int i;
for(i = 1; i < argc; i++)
{
if ((argv[i][0] == '-') || (argv[i][0] == '/'))
{
switch (tolower(argv[i][1]))
{
case 'p': // Remote port
if (strlen(argv[i]) > 3)
iPort = atoi(&argv[i][3]);
break;
case 's': // Server
if (strlen(argv[i]) > 3)
strcpy(szServer, &argv[i][3]);
break;
case 'n': // Number of times to send message
if (strlen(argv[i]) > 3)
dwCount = atol(&argv[i][3]);
break;
case 'o': // Only send message; don't receive
bSendOnly = TRUE;
break;
default:
usage();
break;
}
}
}
}
//
// Function: main
//
// Description:
// Main thread of execution. Initialize Winsock, parse the
// command line arguments, create a socket, connect to the
// server, and then send and receive data
//
int main(int argc, char **argv)
{
WSADATA wsd;
SOCKET sClient;
char szBuffer[DEFAULT_BUFFER];
int ret,
i;
struct sockaddr_in server;
struct hostent *host = NULL;
// Parse the command line, and load Winsock
//
ValidateArgs(argc, argv);
if (WSAStartup(MAKEWORD(2,2), &wsd) != 0)
{
printf("Failed to load Winsock library!\n");
return 1;
}
strcpy(szMessage, DEFAULT_MESSAGE);
//
// Create the socket, and attempt to connect to the server
//
sClient = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sClient == INVALID_SOCKET)
{
printf("socket() failed: %d\n", WSAGetLastError());
return 1;
}
server.sin_family = AF_INET;
server.sin_port = htons(iPort);
server.sin_addr.s_addr = inet_addr(szServer);
//
// If the supplied server address wasn't in the form
// "aaa.bbb.ccc.ddd," it's a host name, so try to resolve it
//
if (server.sin_addr.s_addr == INADDR_NONE)
{
host = gethostbyname(szServer);
if (host == NULL)
{
printf("Unable to resolve server: %s\n", szServer);
return 1;
}
CopyMemory(&server.sin_addr, host->h_addr_list[0],
host->h_length);
}
if (connect(sClient, (struct sockaddr *)&server,
sizeof(server)) == SOCKET_ERROR)
{
printf("connect() failed: %d\n", WSAGetLastError());
return 1;
}
// Send and receive data
//
for(i = 0; i < dwCount; i++)
{
ret = send(sClient, szMessage, strlen(szMessage), 0);
if (ret == 0)
break;
else if (ret == SOCKET_ERROR)
{
printf("send() failed: %d\n", WSAGetLastError());
break;
}
printf("Send %d bytes\n", ret);
if (!bSendOnly)
{
ret = recv(sClient, szBuffer, DEFAULT_BUFFER, 0);
if (ret == 0) // Graceful close
break;
else if (ret == SOCKET_ERROR)
{
printf("recv() failed: %d\n", WSAGetLastError());
break;
}
szBuffer[ret] = '\0';
printf("RECV [%d bytes]: '%s'\n", ret, szBuffer);
}
}
closesocket(sClient);
WSACleanup();
return 0;
}
--------------------------------------------------------------------------
How to Run them
for server usage is
server -p:5150 -o
and for client the usage is
client -p:5150 -s:IP -n:10 -o
|
|
|
|
|
thanks for the reply. One question what headers are needed for the includes? you didn't turn the <> function on in your post so it wiped out the includes.
Thanks again,
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
Can any body tell me how to completely automate the build of a vc++ project from command line.I want to export makefiles automatically and build it.It's urgent.
|
|
|
|
|
Can nobody answer me?Is it because it's a dumb question?I'm a fresher.I would be grate ful to you,if anybody helps me.
|
|
|
|
|
This article[^] in the MSDN describes the command line switches for VS.NET 2002/2003. You can use these to build projects or whole solutions from the command line or in a batch file.
If you are still using Visual C++ 6.0, there are similar command line options for it; you'll need to check the help text.
Software Zen: delete this;
|
|
|
|
|
Hi,
I am new in MFC window based application.
I have created a SDI project(based on document view architecture) using MFC wizard. I want to remove menu bar and title bar completely. How can I do that?
Advance thanks for support.
Shoma
|
|
|
|
|
In the dialog design view, right click on the dialog and select properties, there are checkbox where you can remove the titlebar.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
Hello,
That chap is asking about SDI Application and not Dialog based application...dont confuse him....
|
|
|
|
|
Sorry for the wrong answer before here what you need to do, in the mainframe window, add the virtual funtion for PreCreateWindow(..) if it is already there then in that method the paramter CREATESTRUCT has a member variable called dwExStyle. if you modify the style here you will get the corresponding style of your window.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|