|
hi, how do i execute a dos program in MFC Application?i try using ShellExecuteEx, the prompt is shown but not the dos program it self.i think the dos program has running at the background of dos prompt..who can help me ,please!!
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "C:\\GLAP1.EXE";
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOWNORMAL;
ShExecInfo.hInstApp = NULL;
if(ShellExecuteEx(&ShExecInfo)!= 0)
{
ShExecInfo.hProcess;
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
return 0;
}
else
return 1;
|
|
|
|
|
Hello,
I have a C++ dll that I just created and im having trouble converting the data inside a BYTE * to a C# version of byte[].
On my C# App I DllImported the dll, the return type i set to be an IntPtr (the return type of the C++ dll is BYTE *)
I then put the IntPtr I then Marshaled it and put the results inside a MemoryStream.
The output should have been an image (bitmap). but when trying to save to file it gives an error of not valid type.
My question is, on the C++ dll, what type is BYTE *? on my C# side should I go int, Uint32, IntPtr??
Any help would be greatly appreciated.
Steve
|
|
|
|
|
Did I create a tough question?
Does anyone know what to Marshal the BYTE * to on the C# side?
|
|
|
|
|
i've tried everything i can think of, but can't seem to capture a double-click in my CSliderCtrl-derived class.
i've tried ON_WM_LBUTTONDBLCLK, ON_WM_NCLBUTTONDBLCLK, PreTranslateMessage and even WindowProc , but none of them respond to double-clicks.
i've looked at the source for the control, but there's not much there (it's a common ctrl, so the bulk of the implementation is probably in COMCTRL32.DLL).
so, anyone else ever managed to capture dblclicks on a slider ?
Image Toolkits | Image Processing | Cleek
|
|
|
|
|
I want to create a submenu which uses the case statements. So my problem is the program crushes and i can't get the logic how i can arrange the case statements. Please help me, i am already under pressure because of time.
I want the program run such that if i enter option 1 it create a process and then produce which i can now suspend the process from there or shut it down in the submenu
Here is my code
<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 />
<br />
int menu(void)<br />
{<br />
char iobuf[80];<br />
int choice;<br />
int i,len,valid;<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: Quit the system\t\t=");<br />
printf ("\n=========================================\n");<br />
valid=0;<br />
printf("\nEnter choice (1-3): ");<br />
<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[i]))<br />
{<br />
printf("\nPlese enter numeric digits only (1-5)\n");<br />
valid = 0;<br />
}<br />
}<br />
}<br />
choice = atoi(iobuf);<br />
<br />
return choice; <br />
}<br />
<br />
int submenu(void)<br />
{<br />
char iobuf[80];<br />
int choice2;<br />
int i,len,valid;<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 />
<br />
printf ("\n*****************************************\n");<br />
printf ("*\t\t\t\t\t*\n*\tPROCESS CREATION \t\t*\n");<br />
printf ("=========================================");<br />
printf ("\n=\t 1: Suspend the process\t\t=");<br />
printf ("\n=\t 2: Resume process \t=");<br />
printf ("\n=\t 3: Shutdown the process \t=");<br />
printf ("\n=\t 4: Exit the system \t=");<br />
printf ("\n=========================================\n");<br />
printf ("\n");<br />
valid=0;<br />
printf("\nEnter choice (1-4): "); <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[i]))<br />
{<br />
printf("\nPlese enter numeric digits only (1-4)\n");<br />
valid = 0;<br />
}<br />
}<br />
}<br />
while((choice2 = submenu())!=3)
{<br />
switch (choice2)<br />
{<br />
case 1:<br />
SuspendThread(pi.hThread);
break;<br />
case 2:<br />
ResumeThread(pi.hThread); <br />
break;<br />
case 3:<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.hThread, 0);
GetLastError();<br />
}<br />
break;<br />
default: printf("Invalid choice: ");<br />
<br />
}}<br />
choice2 = atoi(iobuf);<br />
return choice2; <br />
valid = 0;<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 />
while((choice = menu())!=6)
{<br />
switch (choice)<br />
{<br />
case 1: <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 />
submenu();<br />
<br />
break;<br />
case 2:<br />
printf("\n\tAre you sure you want to quit the system!(y or n) ");<br />
scanf ("%s",ans);<br />
<br />
result = strcmp(ans,"y");
<br />
if (result==0)<br />
<br />
{<br />
TerminateProcess(pi.hProcess, 0);
GetLastError();<br />
exit(EXIT_SUCCESS);
}GetLastError(); <br />
break; <br />
default:<br />
printf("\nInvalid choice: ");<br />
}<br />
}<br />
return (0);<br />
}<br />
|
|
|
|
|
I still think that you should have gone with my suggestion - which was to have one menu and only show valid options.
Where does it crash ? Perhaps if you posted the full code ( at the moment, what you're including is missing ), someone will post it into a project and try to work out what's going wrong, but it would be more helpful if you told us.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Well i wanted to go with your suggestion but then i have the program crushing and i have already intergrated my code it is now large. But even the submenu one that i am thinking above cannot confuse user's of the system if it is used.
-oam-
|
|
|
|
|
First trick of programming - if it crashes, work out why, don't just change to a lesser design
To reiterate - where/why does it crash ? I assume that crush == crash ?
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Christian Graus wrote:
First trick of programming - if it crashes, work out why, don't just change to a lesser design
Yes i am working on it day and night but now i am under presure as i have to submit this tommorrow.
<br />
#include <windows.h><br />
#include <stdio.h><br />
#include <windef.h><br />
#include <winbase.h><br />
#include <stdlib.h><br />
typedef struct _iobuf FILE;<br />
#include <assert.h><br />
#include <sys/types.h><br />
#include <sys/stat.h><br />
#include <string.h><br />
<br />
int menu(void)<br />
{<br />
char iobuf[80];<br />
int i,len,valid;<br />
HANDLE hProcess;<br />
<br />
printf ("\n");<br />
printf ("\t\t\t*****************************************\n");<br />
printf ("\t\t\t*\t\t\t\t\t*\n\t\t\t*\t\tPROCESS\t\t\t*\n");<br />
printf ("\t\t\t*\t\t\t\t\t*\n\t\t\t* CHECKPOINTING AND MIGRATION SYSTEM\t*\n");<br />
printf ("\t\t\t*\t\t\t\t\t*\n");<br />
printf ("\t\t\t=========================================");<br />
printf ("\n\t\t\t=\t 1: Create a Process \t=");<br />
printf ("\n\t\t\t=\t 2: Suspend Process \t=");<br />
printf ("\n\t\t\t=\t 3: Resume Process \t=");<br />
printf ("\n\t\t\t=\t 4: Shutdown Process\t\t=");<br />
printf ("\n\t\t\t=\t 5: Checkpoint Process\t\t=");<br />
printf ("\n\t\t\t=\t 6: Restart Process\t\t=");<br />
printf ("\n\t\t\t=\t 7: Help \t\t\t=");<br />
printf ("\n\t\t\t=\t 8: Quit the system\t\t=");<br />
printf ("\n\t\t\t=========================================\n");<br />
printf ("\n");<br />
<br />
printf("\n\t\t\tEnter choice (1-8): ");<br />
<br />
valid = 0;<br />
while( valid == 0)<br />
{<br />
fgets(iobuf,sizeof(iobuf),stdin);<br />
<br />
len = strlen(iobuf)-1;<br />
iobuf[len] = 0;
valid = 1;
for(i = 0; i < len; i++)
{<br />
if( !isdigit(iobuf[i]))<br />
{<br />
printf("\n\t\t\tPlese enter numeric digits only (1-8):");<br />
valid = 0; <br />
}<br />
}<br />
}
<br />
hProcess = atoi(iobuf);<br />
return hProcess;<br />
<br />
}
<br />
<br />
HWND g_hWnd = NULL;<br />
<br />
BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)<br />
{<br />
DWORD dwProcID;<br />
GetWindowThreadProcessId(hwnd,&dwProcID);<br />
if(dwProcID == (DWORD)lParam)<br />
{<br />
g_hWnd = hwnd;<br />
}<br />
<br />
return TRUE;<br />
}<br />
int main(int argc, char **argv) <br />
{<br />
<br />
FILE* fp;<br />
char ans[4];<br />
int result;<br />
<br />
PROCESS_INFORMATION pi; <br />
STARTUPINFO si; <br />
HANDLE hProcess;<br />
HANDLE hThread = 0;<br />
DWORD NumberOfBytesRead = 0;<br />
BYTE buf[20000];<br />
DWORD bufsize = sizeof buf;<br />
DWORD baseaddr = 0;<br />
DWORD lpAddr = 0;<br />
PMEMORY_BASIC_INFORMATION lpBuffer = 0;<br />
DWORD dwLength = 200000;<br />
DWORD flNewProtect =0;<br />
PDWORD lpflOldProtect = 0;<br />
DWORD dwSize =0;<br />
LPCVOID lpBaseAddress = 0;<br />
DWORD nSize = 0;<br />
MEMORY_BASIC_INFORMATION mbi;<br />
LPDWORD lpNumberOfBytesWritten = 0;<br />
TCHAR lpApplicationName[_MAX_PATH]="";<br />
SYSTEM_INFO sinfo;<br />
LPDWORD lpExitCode = 0;<br />
DWORD pid;<br />
LPVOID base;<br />
HWND hWnd = 0;<br />
DWORD dwProcessID = 0;<br />
UINT GetBase();<br />
LPCONTEXT lpContext = 0;<br />
PHANDLE TokenHandle =0;<br />
BOOL OpenAsSelf=0;<br />
DWORD DesiredAccess=0;<br />
HANDLE ThreadHandle=0;<br />
DWORD dwDesiredAccess = 0;<br />
BOOL bInheritHandle = 0;<br />
DWORD dwThreadId = 0;<br />
<br />
<br />
LPSECURITY_ATTRIBUTES lpThreadAttributes = 0;<br />
DWORD dwStackSize = 0;<br />
LPTHREAD_START_ROUTINE lpStartAddress = 0;<br />
LPVOID lpParameter = 0;<br />
DWORD dwCreationFlags = 0;<br />
LPDWORD lpThreadId = 0;<br />
int nRet = 0;<br />
char *state;<br />
unsigned int regnum = 0;<br />
BOOL OpenThread();<br />
int choice;<br />
<br />
while((choice = menu())!=9)<br />
{<br />
switch (choice)<br />
{ <br />
case 1:<br />
<br />
GetSystemInfo(&sinfo);<br />
lpAddr = 0;<br />
ZeroMemory( &si, sizeof(si) );<br />
si.cb = sizeof(si);<br />
ZeroMemory( &pi, sizeof(pi) );<br />
<br />
printf("\t\t\tEnter process you want to execute: ",lpApplicationName);<br />
scanf ("%s",lpApplicationName);<br />
<br />
GetStartupInfo(&si);<br />
<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 />
<br />
hProcess = pi.hProcess; <br />
<br />
pid = atoi(lpApplicationName);<br />
<br />
if ((hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pi.dwProcessId)) == NULL) <br />
<br />
printf("\t\t\tUnable to open process, the process does not exist!\n");<br />
<br />
VirtualProtectEx(<br />
hProcess,
&lpAddr,
dwSize,
flNewProtect,
lpflOldProtect );
<br />
<br />
<br />
<br />
break;<br />
case 2:<br />
<br />
<br />
<br />
SuspendThread(pi.hThread);
<br />
printf("\n\t\tThe thread of ID: %d",pi.dwProcessId);<br />
printf("\t\t has been suspended!\n");<br />
GetLastError();<br />
<br />
GetThreadContext(<br />
hProcess,
lpContext
);<br />
GetLastError();<br />
<br />
<br />
<br />
<br />
Size: %08x\nProtection: %08x\nType: %08x\n", regnum, state, mbi.BaseAddress, \<br />
mbi.AllocationBase, mbi.AllocationProtect, mbi.RegionSize, mbi.Protect, mbi.Type); <br />
<br />
//}//inner while<br />
<br />
break;<br />
<br />
case 3:<br />
<br />
ResumeThread(pi.hThread);// identifies thread to restart<br />
GetLastError(); <br />
// return ResumeThread(pi.hThread);<br />
<br />
break;<br />
<br />
case 4:<br />
printf("\n\t\t\tYou are about to terminate a running process, do you want to continue ( y or n) ");<br />
scanf ("%s",ans);<br />
<br />
result = strcmp(ans,"y");<br />
<br />
if (result==0)<br />
<br />
TerminateProcess(pi.hProcess, 0);//identifies the process to terminate<br />
GetLastError();<br />
<br />
break;<br />
<br />
case 5://checkpointing<br />
<br />
SuspendThread(pi.hThread);// identifies thread to suspend<br />
<br />
printf("\n\t\tThe thread of ID: %d",pi.dwProcessId);<br />
printf(" \t\thas been suspended!\n");<br />
GetLastError();<br />
<br />
GetThreadContext(<br />
hProcess, // handle to thread with context<br />
lpContext // address of context structure<br />
);<br />
GetLastError();<br />
<br />
ZeroMemory(buf, sizeof(buf));<br />
if( ReadProcessMemory( hProcess, //handle to the process to be suspended<br />
&baseaddr, //address to start reading<br />
&buf, //buffer where to place data to<br />
bufsize, //size of the buffer<br />
NULL ) == FALSE )<br />
/*{<br />
printf("\nProcess memory read failed", GetLastError());<br />
_exit(1);<br />
}<br />
else<br />
{<br />
printf("\nProcess memory read: \n",buf);<br />
}*/<br />
<br />
//fp = fopen(f"checkpoint.bin","w");<br />
//if( fp )<br />
<br />
//printf("Enter the file-name to save the Memory Information: ",fname);<br />
//scanf ("%s",fname);<br />
<br />
regnum = 0;<br />
base = 0;<br />
<br />
while (base < sinfo.lpMaximumApplicationAddress) <br />
<br />
{<br />
VirtualQueryEx(hProcess, base, &mbi, sizeof(mbi));<br />
<br />
if (mbi.State == MEM_COMMIT)<br />
state = "Used";<br />
else if (mbi.State == MEM_FREE)<br />
state = "Free";<br />
else if (mbi.State == MEM_RESERVE)<br />
state = "Reserved";<br />
else<br />
state = "Unknown";<br />
<br />
printf("\n\t\tREGION #%d\nState:%s\nBase Address:%p\nAllocation Base:%p\nAccess Protection: %08x\nRegion \<br />
Size: %08x\nProtection: %08x\nType: %08x\n", regnum, state, mbi.BaseAddress, mbi.AllocationBase, \<br />
mbi.AllocationProtect, mbi.RegionSize, mbi.Protect, mbi.Type);<br />
<br />
base = (LPVOID)((unsigned long)mbi.BaseAddress + (unsigned long)mbi.RegionSize);<br />
/* make base point to one byte past the end of current region, which is either the beginning of the next region, or the beginning of the gap before the next region. <br />
VirtualQueryEx() with this address will tell us about the next region in either case */ <br />
regnum++;<br />
<br />
/*fprintf(fp,"\nREGION #%d\nState:%s\nBase Address:%p\nAllocation Base:%p\nAccess Protection: %08x\nRegion \<br />
Size: %08x\nProtection: %08x\nType: %08x\n", regnum, state, mbi.BaseAddress, \<br />
mbi.AllocationBase, mbi.AllocationProtect, mbi.RegionSize, mbi.Protect, mbi.Type); */<br />
<br />
}//inner while<br />
<br />
/*Sleep(3600);<br />
<br />
TerminateProcess(pi.hProcess, 0);*/<br />
break;<br />
<br />
case 6://restarting the process using information from the file<br />
<br />
lpBaseAddress = 0;<br />
hProcess = mbi.BaseAddress;<br />
<br />
SetThreadContext( <br />
hThread, <br />
lpContext <br />
); <br />
GetThreadContext(<br />
hThread, // handle to thread with context<br />
lpContext // address of context structure<br />
);<br />
//fp = fopen("info.bin","r");<br />
//if( fp )<br />
nSize = 10000; //numbers of bytes in the file<br />
<br />
lpBuffer = buf; //pointer to the file where data is to be read<br />
<br />
WriteProcessMemory(<br />
hThread, // handle to process whose memory is written to<br />
lpBaseAddress, // address to start writing to--dwDesiredAccess<br />
lpBuffer, // pointer to buffer to write data to<br />
nSize, // number of bytes to write<br />
lpNumberOfBytesWritten // actual number of bytes written<br />
);<br />
<br />
printf("Numbers of bytes written: ",lpNumberOfBytesWritten);<br />
CreateThread(<br />
lpThreadAttributes, // pointer to security attributes<br />
dwStackSize, // initial thread stack size<br />
lpStartAddress, // pointer to thread function<br />
lpParameter, // argument for new thread<br />
dwCreationFlags, // creation flags<br />
lpThreadId // pointer to receive thread ID<br />
);<br />
<br />
ResumeThread(hThread);// identifies thread to restart(dwDesiredAccess)<br />
GetLastError();<br />
break;<br />
<br />
case 7:<br />
<br />
printf ("\n");<br />
printf ("\t\t\t*****************************************\n");<br />
printf ("\t\t\t*\t\t\t\t\t*\n\t\t\t*\t\tPROCESS\t\t\t*\n");<br />
printf ("\t\t\t*\t\t\t\t\t*\n\t\t\t* CHECKPOINTING AND MIGRATION SYSTEM\t*\n");<br />
printf ("\t\t\t*\t\t\t\t\t*\n");<br />
printf ("\t\t\t=========================================\n\n");<br />
printf ("\t\t\t<<>>Create a Process:<<>>\n");<br />
printf ("\t\t\tThis option is used to create an executable file specified\<br />
by the user.\n");<br />
printf ("\t\t\tThe file should be in the same directory of the systemt\<br />
or it should and executable file from Windows system directory\n");<br />
printf ("\t\t\t-------------------------------------------------------------\n\n");<br />
printf ("\t\t\t<<>>Stop Process:<<>>\n");<br />
printf ("\t\t\tThe SuspendThread function suspends the specified thread \n");<br />
<br />
printf ("\t\t\t<<>>The ResumeThread:<<>> \n");<br />
printf ("\t\t\tThe function decrements a thread's suspend count. \n");<br />
printf ("\t\t\tWhen the suspend count is decremented to zero, the execution of\<br />
the thread is resumed.\n");<br />
printf ("\t\t\t----------------------------------------------------------------\n\n");<br />
printf ("\t\t\t<<>>Shutdown:<<>> \n");<br />
printf ("\t\t\tThe option terminates the process, and exits with the supplied\<br />
status code.\n");<br />
<br />
printf ("\t\t\t<<>>checkpoint:<<>> \n");<br />
printf ("\t\t\tThis option stops a process and save its state in a file \n");<br />
<br />
printf ("\t\t\t<<>>Restart:<<>> \n");<br />
printf ("\t\t\tThis option restarts the execution of the process from where it left\n");<br />
printf ("\t\t\toff when it was checkpointed\n");<br />
printf ("\t\t\t------------------------------------------------------------------\n\n");<br />
printf ("\t\t\t<<>>Help:<<>> \n");<br />
printf ("\t\t\tGives information about how different options do in the system\n");<br />
<br />
printf ("\t\t\t<<>>Quit:<<>> \n");<br />
printf ("\t\t\tThis option quites the whole system. If there are any running\<br />
processes it will also terminate them while they are still running\n");<br />
<br />
printf ("\t\t\t------------------------------------------------------------------\n");<br />
&sinfo;<br />
<br />
break;<br />
<br />
case 8:<br />
printf("\n\t\t\tAre you sure you want to quit the system!(y or n) ");<br />
scanf ("%s",ans);<br />
<br />
result = strcmp(ans,"y"); //comparing the input and y to quit<br />
<br />
if (result==0)<br />
<br />
{<br />
TerminateProcess(pi.hProcess, 0);//identifies the process to terminate<br />
GetLastError();<br />
exit(EXIT_SUCCESS);//exiting the console<br />
}GetLastError(); <br />
break;<br />
<br />
default: printf("\n\t\t\tYou have entered an invalid choice, check the menu below: \n");<br />
GetLastError(); <br />
}//switch<br />
} //while base <br />
fclose(fp); <br />
return(0);<br />
}<br />
-oam-
|
|
|
|
|
I keep hoping that at some point you will either check the 'Do not treat <'s as HTML tags' box so that your includes come out in your post, or you'll stop just posting all the code over and over, and actually tell us what's going wrong/what error messages you get/etc.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Error 1: It does not validate properly: option 2-6 should not run before option 1. All these option crushes the program
Error 2: It executes the default of the case statement if the user enter "no" if does not want to shutdown the program
-oam-
|
|
|
|
|
Error 1 I explained to you at length last week. If you're unable to pass the handle to process you're creating to the menu function and print/validate the menu choice based on this input, you probably *should* fail this time around, and learn some basic coding before you start creating processes.
Error 2 - I don't understand. It won't shut down if you type 'y' ?
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Christian Graus wrote:
Error 2 - I don't understand. It won't shut down if you type 'y' ?
If i choose optio 8, it will output; Are you sure you want to quit the system(y or n): n
if no is entered then the output is "You have entered an invalid command, check the menu below" and displays menu
instead it should display the menu only
-oam-
|
|
|
|
|
assume myprogram.exe is installed in forlder as:
c:\a\myfolder\myprogram.exe
i hope users can run myprogram.exe from DOS by typing command of its name only:
myprogram.exe (return)
(please note: the command doesn't include path of myprogram.exe).
I know i need to do something in OS, but what and how?
thanks
includeh10
|
|
|
|
|
You'll need to append c:\a\myfolder\ to the user's PATH environment variable (or keep myprogram.exe in a location that's already part in the user's path). The former is recommended.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
This program has be written for an optimized ternary 2D vector addition
operation outlined by Bjarne Stroustrup (C++ Prog Lang, 3rd Ed, 1997,
pages 675-676)
<pre>
Conventional binary operation:
Define: class Point as given below.
Declare: Point p1(1,1), p2(3,3), p;
With a usual global binary addition operator (shown below within comments),
The statment p = p1 + p2; creates and destroys temporary point object.
</pre>
To avoid having to create such a temporary, Dr Stroustrup suggested a
method which has been made use of in writing this program. This involves
defining a temporary class to hold reference to two operands involved.
During the process of assignment, an inlined function is invoked.
The operation is equivalent to invoking an inlined function
<pre>
p.addAndAssign(p1, p2);</pre>
As this operation is also inlined, the net effect is equivalent to
component-wise addition:
<pre>
p.x = p1.x + p2.x; p.y = p1.y + p2.y;</pre>
Though beautiful this idea is, this code does not compile with VC++ 6.0
<pre>
The error messages are
error C2143: syntax error : missing ',' before '&'
error C2059: syntax error : '&'
at the line where the second overloaded operator= is defined:
...
>> Point& operator=(const PointsToBeAdded& pointsToBeAdded) {
...
}
</pre>
It looks like VC++ allows asignment operator = overloading
in which only possible argument is of the type
const reference to an instance of the class in which it is defined.
This also means that object conversion can not be achieved using a
custom assigment operator like:
<pre>
class A { public: int x, y; }
class B { public: int x, y;
B& operator=(const &A a) { // VC++ 6.0 compiler doesn't accept
x = a.y; y = a.x;
}
}
</pre>
Is there any way around this problem. Or is VC++ non-standard conforming.
Have I missed out any header files?
Thanks for taking time to read this posting.
Ganesh
<pre>
// TernaryOpTester.cpp :
#include <iostream>
using namespace std;
class Point
{
public:
int x, y;
Point() : x(0), y(0) {};
Point(int a, int b) : x(a), y(b) {}
~Point() {}
Point(const Point& p) : x(p.x) , y(p.y) {}
// function assignment: Point p, p2(2,2);
// p(2,2); is equivalent to p = p2;
void operator() (int a, int b) { x = a; y = b; }
// you can write for ex: p(p2);
void operator() (const Point& p) { x = p.x; y = p.y; }
Point& operator=(const Point& p) { x = p.x; y = p.y; }
Point& operator=(const PointsToBeAdded& pointsToBeAdded) {
addAndAssign(pointsToBeAdded.p1, pointsToBeAdded.p2);
return *this;
}
void addAndAssign(const Point& p1, const Point& p2) {
x = p1.x + p2.x;
y = p1.y + p2.y;
}
};
ostream& operator<< (ostream& os, const Point& p) {
os << "(" << p.x << ", " << p.y << ")";
return os;
}
// An instance hold reference to operands of binary +
class PointsToBeAdded {
public:
const Point& p1;
const Point& p2;
PointsToBeAdded(const Point& pp1, const Point& pp2) : p1(pp1), p2(pp2) {}
operator Point();
};
// p1 + p2 returns an instance of the above class which is used by
// the assigment operator of Point class
inline PointsToBeAdded operator+(const Point& p1, const Point& p2) {
return PointsToBeAdded(p1, p2); // no addition yet.
}
/*inline Point operator+(const Point& p1, const Point& p2) {
return Point(p1.x + p2.x, p1.y + p2.y);
}*/
int main(int argc, char* argv[])
{
Point p1(1,1), p2(4,4), p;
cout << "p1 = " << p1 << ", p2 = " << p2 << ", p = " << p << endl;
p = p + p1;
cout << "p = p1 + p2 = " << p << endl;
return 0;
}
</pre>
Ganesh
|
|
|
|
|
Hello, I think the problem is that, in the line where Point& operator=(const PointsToBeAdded& pointsToBeAdded) is defined, PointsToBeAdded has not even been declared yet. Please try the following arrangement:
class PointsToBeAdded;
class Point
{
...
Point& operator=(const PointsToBeAdded& pointsToBeAdded);
};
class PointsToBeAdded
{
};
Point& Point::operator=(const PointsToBeAdded& pointsToBeAdded)
{
addAndAssign(pointsToBeAdded.p1, pointsToBeAdded.p2);
return *this;
} Hope this helps.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Hello, THanks for the reply. I figured this out only now.
I did try what you suggested before.
But MS VC++ does not accpept such a construct like GNU CC does.
But this problem can be solved by subclassing a simple Point class:
class Coords2D {
public:
int x,y;
Coords2D() : x(0), y(0) {}
Coords2D(int a, int b) : x(a), y(b) {}
Coords2D(const Coords2D& c) : x(c.x), y(c.y) {}
Coords2D& operator=(const Coords2D& c) { x = c.x; y = c.y; }
};
// An instance hold reference to operands of binary +
class PointsToBeAdded {
public:
const Coords2D& p1;
const Coords2D& p2;
PointsToBeAdded(const Coords2D& pp1, const Coords2D& pp2) : p1(pp1), p2(pp2) {}
//operator Point();
};
class Point : public Coords2D
{
...
};
...
and so on....
Here is the error message
TernaryOpTester.cpp
H:\C++\Projects\Test\tmp\TernaryOpTester.cpp(79) : error C2027: use of undefined type 'PointsToBeAdded'
H:\C++\Projects\Test\tmp\TernaryOpTester.cpp(58) : see declaration of 'PointsToBeAdded'
H:\C++\Projects\Test\tmp\TernaryOpTester.cpp(79) : error C2228: left of '.p1' must have class/struct/union type
H:\C++\Projects\Test\tmp\TernaryOpTester.cpp(79) : error C2027: use of undefined type 'PointsToBeAdded'
H:\C++\Projects\Test\tmp\TernaryOpTester.cpp(58) : see declaration of 'PointsToBeAdded'
H:\C++\Projects\Test\tmp\TernaryOpTester.cpp(79) : error C2228: left of '.p2' must have class/struct/union type
Tool returned code: 2
Ganesh
|
|
|
|
|
I am trying to create an RE that recognizes C-comment syntax.
Example: "/\*[^*]*\*/" recognizes any C-comment that does not have the character '*' within the comment text.
Problem: The character '*' needs to be recognized within the comment.
Esentialy I need an RE that acts like this:
bool IsComment(char* pStr)
{
if( !pStr || !*pStr || strncmp(pStr,"\\*",2) )
return false;
pString += 2;
while( *pStr && strncmp(pStr,"*//",2) )
++pStr;
return !strncmp(pStr,"*//",2) ? true : false;
}
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Do you even need anything special in the middle of the regex? I'd think that the endpoint strings of /* and */ would be enough. Something like:
/\*.*?\*/
using a non-greedy match on .* to get only one comment. Using the default greedy match would treat /*foo*/ bar /*baz*/ as one big comment.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ
Strange things are afoot at the U+004B U+20DD
|
|
|
|
|
Well, I am not using Regex++ or any thing like that. The one I am using (mine), only supports basic REs with character classes like \w and [:word:], thrown in for good measure. So it does not recognizes that expression. I've seen that expression in Regex++, but don't understand how it works.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
I'm most familiar with the Perl regex syntax, so that's what I was using. The ? after a wildcard match means "match as few characters as possible without making the entire match fail". The difference is apparent with that sample from my earlier post:
/*foo*/ bar /*baz*/
/\*.*\*/ matches /* then foo*/ bar /*baz then */ (note the .* slurps up as much as possible, this is the default "greedy" behavior)
/\*.*?\*/ matches /* then foo then */ (the .*? only slurps up "foo" because it can stop there and still have the entire match succeed)
If you know what your input will be, and know that there will never be two comments on the same line, you should be able to go with /\*.*\*/
--Mike--
Visual C++ MVP
LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ
Strange things are afoot at the U+004B U+20DD
|
|
|
|
|
Thanks for the explanation.
I went to write simple color coded text editor a few years ago and ended up with a code editor for C/C++ and Pascal, that acts a lot like the VC++ editor. I am trying to make the backend user programmable via regular expressions, so the user can set it up for any language.
At the moment a programer can program it, within limits, using a built-in text state class. But this method is flawed and not user friendly enough for me.
Note: I have no way to know what the input will be.
Thanks again!
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
When I transfer a file, I immediately follow the transfer with a "MTDM" (change file time) command so the file reflects the time it was actually last modified on my machine.
The server always reports that the file wasn't found, even though I got a 226 (Transfer OK) response after the transfer completed. Do I have to flush a cache or some such thing?
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
hi
does anyone has an expirience in programming using parasolid kernel?
i need a light samples on subject, programming reference etc.
google is really poor on this....
all help will be highly appreciated.
4apai
There're no impossible tasks. There're tasks that required infinite period of execution time.
|
|
|
|
|