|
Am trying to telnet a server on a particular port immediately after reboot of a 98 PC and obtained a failure in the connection.After repeating the telnet connection for 3 times,only at the fourth time am able to connect to the server on that port.This happens only in Windows 98 PC.Hope I would get help on this.
URagav
Everything can be sacrificed for truth, but truth cannot be sacrificed for anything .
|
|
|
|
|
Pliz help me to validate my input in my program below.I want to accept the integer input only but not characters, how do i do it because i used dafault in my case statement. If i enter characters the program crushes.
#include <stdio.h>
#define _WIN32_WINNT 0x0400
#define WINVER 0x0400
#include <windows.h>
#include <stdio.h>
#include <windef.h>
#include <winbase.h>
#include <imagehlp.h>
#include <stdlib.h>
typedef struct _iobuf FILE;
#include <assert.h>
#include <sys types.h="">
#include <sys stat.h="">
int menu(void)
{
int choice;
printf ("\n");
printf ("*****************************************\n");
printf ("*\t\t\t\t\t*\n*\tPROCESS CREATION \t\t*\n");
printf ("=========================================");
printf ("\n=\t 1: Create a process \t\t=");
printf ("\n=\t 2: Suspend the process\t\t=");
printf ("\n=\t 3: Resume process \t=");
printf ("\n=\t 4: Shutdown the process \t=");
printf ("\n=========================================\n");
printf ("\n");
printf("\nEnter choice (1-4): ");
scanf("%d", &choice);
return choice;
}
int main(int argc, char **argv)
{
PROCESS_INFORMATION pi; /* filled in by CreateProcess */
STARTUPINFO si; /* startup info for the new process*/
HANDLE hProcess;
DWORD lpAddr = 0;
TCHAR lpApplicationName[_MAX_PATH]="";
int result;
char ans [4]="";
int choice;
while((choice = menu())!=5)
{
switch (choice)
{
case 1:
GetStartupInfo(&si);
lpAddr = 0;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
printf("Enter process you want to execute: ",lpApplicationName);
scanf ("%s",lpApplicationName);
printf("Process %d reporting for creation\n",GetCurrentProcessId());//print out our process ID
CreateProcess(NULL, /* lpApplicationName */
lpApplicationName, /* lpCommandLine assumes to use curent process directory*/
NULL, /* lpsaProcess */
NULL, /* lpsaThread */
FALSE, /* bInheritHandles */
CREATE_NEW_CONSOLE, /* dwCreationFlags */
NULL, /* lpEnvironment */
NULL, /* lpCurDir */
&si, /* lpStartupInfo */
&pi /* lpProcInfo */
);
hProcess = pi.hProcess;
printf("New Process ID: %d ",pi.dwProcessId);
printf("has started \n");
break;
case 2:
SuspendThread(pi.hThread);// identifies thread to suspend
break;
case 3:
ResumeThread(pi.hProcess);
break;
case 4:
printf("\nYou are about to terminate a running process, do you want to continue ( y or n) ");
scanf ("%s",ans);
result = strcmp(ans,"y");
if (result==0)
{
TerminateProcess(pi.hProcess, 0);//identifies the process to terminate
GetLastError();
}
break;
default:
printf("\nInvalid choice: ");
}
}
return (0);
}
-oam-
|
|
|
|
|
You don't initialize choice in your menu function. If you enter character data when scanf is expecting an integer (the "%d " format), scanf will stop scanning the input, and not set the choice variable. This means that your menu function will return a random value if you enter character data. Note that this random value could include one of your valid menu values of 1 through 4.
Software Zen: delete this;
|
|
|
|
|
mpapeo wrote:
printf("\nEnter choice (1-4): ");
scanf("%d", &choice);
return choice;
How about some error checking:
int done = 0;
while (! done)
{
printf("\nEnter choice (1-4): ");
done = scanf("%d", &choice);
}
return choice; This is hardly foolproof, and may not even work, but it might give you a foundation to build upon. An alternative is to use getch() to get each character as it is typed. If it is a numeric character, proceed. Otherwise, indicate problem and ask for another character.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Well i tried your idea but it seems as if its difficult somehow as i am still get the program crashing
-oam-
|
|
|
|
|
I tried using something different but now i am getting these errors, how can i solve them
<br />
#include <stdio.h><br />
#define _WIN32_WINNT 0x0400<br />
#define WINVER 0x0400<br />
#include <windows.h><br />
#include <stdio.h><br />
#include <windef.h><br />
#include <winbase.h><br />
#include <imagehlp.h><br />
#include <stdlib.h><br />
#include <ctype.h><br />
typedef struct _iobuf FILE;<br />
#include <assert.h><br />
#include <sys/types.h><br />
#include <sys/stat.h><br />
int menu(void)<br />
{<br />
int choice;<br />
char iobuf[80];<br />
int i,len,valid;<br />
boolean isDigit();<br />
printf ("\n");<br />
printf ("*****************************************\n");<br />
printf ("*\t\t\t\t\t*\n*\tPROCESS CREATION \t\t*\n");<br />
printf ("=========================================");<br />
printf ("\n=\t 1: Create a process \t\t=");<br />
printf ("\n=\t 2: Suspend the process\t\t=");<br />
printf ("\n=\t 3: Resume process \t=");<br />
printf ("\n=\t 4: Shutdown the process \t=");<br />
printf ("\n=========================================\n");<br />
printf ("\n");<br />
<br />
printf("\nEnter choice (1-4): ");<br />
<br />
valid = 0;<br />
while( valid == 0)<br />
{<br />
fgets(iobuf,sizeof(iobuf),stdin);<br />
len = strlen(iobuf)-1;<br />
iobuf[len] = 0;<br />
valid = 1;
for(i = 0; i < len; i++)<br />
{<br />
if( !isdigit(iobuf))<br />
{<br />
printf("Plese enter numeric digits only\n");<br />
valid = 0;<br />
break;<br />
}<br />
}<br />
}<br />
choice = atoi(iobuf);<br />
<br />
<br />
scanf("%d", &choice);<br />
return choice; <br />
}<br />
int main(int argc, char **argv) <br />
{<br />
PROCESS_INFORMATION pi; <br />
STARTUPINFO si; <br />
HANDLE hProcess;<br />
DWORD lpAddr = 0;<br />
TCHAR lpApplicationName[_MAX_PATH]=""; <br />
int result;<br />
char ans [4]="";<br />
int choice;<br />
<br />
<br />
while((choice = menu())!=5)<br />
{<br />
switch (choice)<br />
{<br />
case 1: <br />
<br />
GetStartupInfo(&si);<br />
lpAddr = 0;<br />
ZeroMemory( &si, sizeof(si) );<br />
si.cb = sizeof(si);<br />
ZeroMemory( &pi, sizeof(pi) );<br />
printf("Enter process you want to execute: ",lpApplicationName);<br />
scanf ("%s",lpApplicationName);<br />
printf("Process %d reporting for creation\n",GetCurrentProcessId());
<br />
CreateProcess(NULL, <br />
lpApplicationName, <br />
NULL, <br />
NULL, <br />
FALSE, <br />
CREATE_NEW_CONSOLE, <br />
NULL, <br />
NULL, <br />
&si, <br />
&pi <br />
); <br />
hProcess = pi.hProcess;<br />
printf("New Process ID: %d ",pi.dwProcessId);<br />
printf("has started \n"); <br />
break;<br />
case 2:<br />
SuspendThread(pi.hThread);
break;<br />
case 3:<br />
ResumeThread(pi.hProcess); <br />
break;<br />
case 4:<br />
printf("\nYou are about to terminate a running process, do you want to continue ( y or n) ");<br />
scanf ("%s",ans);<br />
result = strcmp(ans,"y");<br />
if (result==0)<br />
{<br />
TerminateProcess(pi.hProcess, 0);
GetLastError();<br />
}<br />
break;<br />
default:<br />
printf("\nInvalid choice: ");<br />
}<br />
}<br />
return (0);<br />
}<br />
<br />
C:\Documents and Settings\9804626\Desktop\pro.c(46) : error C2107: illegal index, indirection not allowed<br />
C:\Documents and Settings\9804626\Desktop\pro.c(46) : error C2296: '&' : illegal, left operand has type 'unsigned short *'<br />
Error executing cl.exe.<br />
-oam-
|
|
|
|
|
What's wrong with:
int menu( void )
{
int choice;
do
{
printf("\nEnter choice (1-4): ");
choice = _getche();
} while (choice < '1' || choice > '5');
return choice;
}
void main( void )
{
int choice;
while ((choice = menu()) != '5')
{
switch (choice)
{
case '1':
...
}
}
}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Well its like it does not want to accept any input whether text nor digits
-oam-
there might be something missing because it does read input and i can't figure it out
|
|
|
|
|
Well i used the other method which i found it simpler even though longer that the one you suggested.
printf("\nEnter choice (1-4): ");<br />
valid = 0;<br />
while( valid == 0)<br />
{<br />
fgets(iobuf,sizeof(iobuf),stdin); <br />
len = strlen(iobuf)-1;<br />
iobuf[len] = 0;<br />
valid = 1;
for(i = 0; i < len; i++)
{<br />
if( !isdigit(iobuf[i]))<br />
{<br />
printf("\nPlese enter numeric digits only (1-8):");<br />
valid = 0; <br />
}<br />
}<br />
break;<br />
}<br />
choice = atoi(iobuf);<br />
<br />
scanf("%d", &choice);
return choice; <br />
}
Thanks anyway.
-oam-
|
|
|
|
|
This much code to get a simple number is a maintenance nightmare waiting to happen.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
The code snippet I provided does indeed work. Are you sure you typed it in correctly?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
in my keyboard hook dll i have used a global variable in all functions of that dll. I get value of that variable when control is in dll calling application. but if control is in another application (notepad or word) it won't get the global variable's value.
|
|
|
|
|
Global varible does NOT mean global concerning multiple processes!!
That global just means then you can access it from every function of ONE process.
If you want to access the variable from multiple processes then you have to share it!
To make it more clear:
The DLL file format (called PE file format) consists of sections. These section can have different settings. You code normally uses a section called .text, and the global variables use .data.
When a DLL is attached to a process, the sections are checked whether they contain data or code, and weather they sould be shared accross the whole system.
If sharing is not used, then the .text section is loaded and initialized by the code from the DLL file, but the .data section gets NEW memory, which is then initialized by the main function of the DLL file.
That would mean, that every process with the DLL attached to it, there is a completly new .data section which has different physical addresses in your RAM.
So when you want to share such a global variable over many processes, then you need to add a new shareable section or modify the whole .data section to make it shareable (which is not very reasonable).
To create a new section use this code:
#pragma data_seg( ".share" )
HANDLE hFileHandle = 0;
#pragma data_seg()
#pragma comment( linker, "/SECTION:.share,RWS" )
Don't try it, just do it!
|
|
|
|
|
Hi, all
I have an MFC application that uses CHtmlView to display the contents of an xml file (xml source).
I use the CHtmlView()->Navigate2(sFile,NULL,NULL); function, and it displays the xml source in internet explorer style (coloring, xml node explansion, etc), I use it also to display plain text files content, however, in some computers when using the Navigate2 method it launches a separate Notepad window and displays an IE error message: "Action canceled
Internet Explorer was unable to link to the Web page you requested. The page might be temporarily unavailable". In others it displays the file source. Any hint on how to force it programaticaly to display the text file contents?
thanks,
Oscar
|
|
|
|
|
Hello, All!
I have a some problem, may be smbd can help me.
So, I have a RichEdit window and have to use it like console window (so, use any functies for stdout and strdinm, for example, FillConsoleOutputCharacter, SetConsoleCursorPosition and so on). May be smbd know how to do it...
PS: I just trying to rewrite a console application of telnet-client with supporting vt100 and esc-sequenses and have a problem with a positional output.
Thanx for all answeres!
|
|
|
|
|
if you have a problem with '\n' , replace them with '\r\n'
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
No, not this problem. Problem with rewriting information which sending from telnet-server. For example, if we send the "top" command to telnet-server information in RichEdit have to redraw not all but in special position.
|
|
|
|
|
I'm not sure I understand, but does Invalidate() function work for you ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
|
Big thanx! Try to use it!
|
|
|
|
|
Now have a new problem - i'm using a VC 6 but this project on a C#, and i can't include this dll to my project
|
|
|
|
|
*Differences between VxDs and DLLs (Win9x)
*when to write a VxD or when to write a DLL (Win9x)
*how to write VxDs in C or C++.
Tell Me Please
|
|
|
|
|
A VxD is a Virtual Driver
A DLL is a Dynamic Link Library
A DLL is a library of functions, classes, etc that can be use by any program which wants to stay a bit modular.
A VxD don't have any relationship with this...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
VxDs only for kernel-mode drivers.
That means, if you don't need any functions only accessable from kernel-mode (e.g. direct device access), then you don't need a VxD.
Don't try it, just do it!
|
|
|
|
|
Hi all:
What "0L" stands for, "L" is the data type "Long" right?
But in the statement above, is "L" a operator or something else?
Thanks
|
|
|
|
|