Tuesday, July 14, 2009

How can I run an exe file by C# Windows programming?

How can I run an exe file by C# Windows programming? I have problems in running an exe file by clicking the button that i made in c# windows programing, can anyone of you write the code of event handler in c# through which i can run exe file by just clicking the button,rest of the code is:


using System;


using System.Windows.Forms;


using System.Drawing;


class ButtonForm : Form {


Button MyButton = new Button();


public ButtonForm() {


Text = "Respond to a Button";


MyButton = new Button();


MyButton.Text = "Press Here";


MyButton.Location = new Point(100, 200);


// Add button event handler to list.


MyButton.Click += new EventHandler(MyButtonClick);


Controls.Add(MyButton);


}


[STAThread]


public static void Main() {


ButtonForm skel = new ButtonForm();


Application.Run(skel);


}


// Handler for MyButton.


{ Please guide me with this part.


}


}


Thank u in advance.

How can I run an exe file by C# Windows programming?
Okay, you already have a function defined, you need to go to your Form.cs file, where the EventHandler is located.





MyButton.Click += new EventHandler(MyButtonClick);





This points to the MyButtonClick function.





**************************************...


Now you need to add:





using System.Diagnostics;








Then create a process:


Process TheProcessYouNamed;





private void MyButtonClick(object sender, EventArgs e)


{


TheProcessYouNamed = Process.Start("EXEToRun.exe");








TheProcessYouNamed.CloseMainWindow();


}


File handling in C?

hi guys and gals. i've gotta submit a project. i hav to handle student details such as name, roll number,5 marks, avg,result and rank. i need to save it in a file using C. cud u plz help me gettin the codes. plz.

File handling in C?
Unless you're working with a database system (and you probably aren't), the file management is the least of your worries.





First, develop a program that handles the records in an array (or better, an STL vector or a linked list) in memory. That's where you're going to have to add records, delete records, sort records, etc. It's easier to manage it here than in a file.





Second, write code that goes through your array/list and writes each record to a file. You'll then write the opposite of that which builds a list from the file. These you'll call when your program quits and when it starts. If you want to get fancy, you might save more frequently than this in case of crashes, either on a timer or before and after sorting or other operations.





Now to the crux of your question, how to do this. That's going to depend a lot on what API you're using. In windows you'd use CreateFile and WriteFile. Using standard C or C++ with streams will give you other options.





I've added a link here to an article that goes over some of the standard C options for reading and writing files.





http://www.exforsys.com/content/view/207...
Reply:The file save fuction is differ C# then GML.





To write GML go to http://www.gamemaker.nl/download.html

cabbage

Most important file in c drive?

wat is the most important file/files in the c drive that will coz serious problems for windows to run if they are deleted by accident?

Most important file in c drive?
content of windows folder or system files like ntldr.sys....


Hi! How do I open a file in C and create one if it doesn't exist?

I have a problem with creating a file in C. I would like to open existing file (or create one if it doesn't exist) and write something into it:


/* open the file */


if ((shfd = open(argv[2], O_CREAT | O_RDWR, 0677)) %26lt; 0)


my_error("open failed");


/* map a portion of the file to buffer in memory */


if ((mem = mmap(0,SIZE,PROT_READ | PROT_WRITE, MAP_SHARED, shfd, 0)) == (void *)-1)


my_error("mmap failed");


sprintf(mem, "%d", getpid());


However, when the file doesn't exist and is created, its empty, and I get "bus error" message at the last line... If I try to write something to the file that already exists and is empty, I get the same message. If it exists and is not empty, it works fine...


Could anyone please help? I would really appreciate any help, since I don't know why I'm getting that error...





Thanks a lot for your time.

Hi! How do I open a file in C and create one if it doesn't exist?
You can't extend a file with mmap(). You can map


memory that you might write into, but when you close


or fsync the file, it will NOT be extended.





The historical way to do this is to lseek to the position


you want and write a single byte. The filesystem will


arrange that the intervening bytes will look like zeros.





I've modified your program snippet to open a file,


mmap it, and scribble in a bunch of bytes -- while


preserving whatever is there. It's not particularly


clever, but it should show most of the details you're


looking for. You can contact me through YA if you


have questions.





#include %26lt;sys/types.h%26gt;


#include %26lt;sys/stat.h%26gt;


#include %26lt;fcntl.h%26gt;


#include %26lt;sys/stat.h%26gt;


#include %26lt;unistd.h%26gt;


#include %26lt;sys/mman.h%26gt;


#include %26lt;stdio.h%26gt;


#include %26lt;string.h%26gt;


#include %26lt;stdlib.h%26gt;





int


main(int argc, char* argv[])


{


  int shfd;


  struct stat statbuff;


  char *filename = argc%26gt;1 ? argv[1]   : "testfile";


  int mmapsize = argc%26gt;2 ? atoi(argv[2]) : 100000;


  char *mem;





  /* open the file */


  if ((shfd = open(filename, O_CREAT | O_RDWR, 0677)) %26lt; 0)


    perror("open failed"), exit(-1);





  /* if it is too small, we will extend the file for the mmap */


  if (fstat(shfd, %26amp;statbuff) != 0)


    perror("stat"), exit(-1);


  if (statbuff.st_size %26lt; mmapsize) {


    if (lseek(shfd, mmapsize-1, SEEK_SET) == (off_t)-1)


      perror("lseek"), exit(-1);


    if (write(shfd, "\0", 1) %26lt; 0)


      perror("write"), exit(-1);


  }





  /* map a portion of the file to buffer in memory */


  if ((mem = mmap(0, mmapsize, PROT_READ | PROT_WRITE, MAP_SHARED, shfd, 0)) == MAP_FAILED)


    perror("mmap failed"), exit(-1);





  /* scribble on the file *after* whatever was already there */


  if (statbuff.st_size %26lt; mmapsize)


    memset(mem+statbuff.st_size, 'X', mmapsize-statbuff.st_size);





  if (close(shfd) %26lt; 0)


    perror("close"), exit(-1);





  return 0;


}
Reply:Hmmm, I dont follow how you are trying to do it but this is how I always do it.





void main()


{


FILE *Pfile;


char FileName[] = "nameoffile";


char buffer[];





//open file or create if it doesnt exsist


Pfile = fopen(FileName, "w"); // w = open for write


// r = open for read


// wb = open binary for write


//fill buffer with what you want to write to file


strcat(buffer, "stuff you want to add to file");


//write buffer to the file


fwrite(%26amp;buffer, strlen(buffer), 1, Pfile);


//DONT forget to close the file when done!!


fclose(Pfile);


}


Reading data from file using C++?

I have a text file representing time-voltage signal 2 colums of numbers, in scientific format eg.


time voltage


0.003 1.553e-8


... ...





how do I read them into a mx2 matrix using C++?





used to working with C, not familar with C++

Reading data from file using C++?
You could use class ifstream.


It makes very easy to read from a file as an input stream.
Reply:If you are not required to use the C++ library, then use the C one. I always preferred the C one. Even in my college courses, where we were expected to use C++ I was not penalized for using the standard C library. If you are going to school, you might want to double check if this is acceptable. IMO the C++ standard library using too confusing and abstracted of a syntax to be understandable. Plus I knew how to look at standard C code on paper and determine what the result would be, in C++ I wasn't and still can't always do this.


Do I need to file Schedule C?

I started the business in 2006 and claimed a loss of the business income and filed a Schedule C for 2006.But, I only participated passively(less than 500 hours) in my business for 2007. I did not sell any inventory nor did I buy anymore. I used some items from the inventory for personal use. I did not have any expenses for 2007. I plan to close the business this year 2008. Do i need to file a Schedule C for 2007 and if so what line items would i need to file out?





Appreciate any help.

Do I need to file Schedule C?
I'm not sure but you do have to claim your inventory if you did not close the business prior to 2007 even if you did not sell any inventory. It is still considered an asset. I would consult with an accountant on this.
Reply:If you were in possession on inventory that you did not sell, can you not write off the depreciation?
Reply:its sounds like no you do not if you had no expenses cant see what you would fill out

phlox

How to use java file in c#?

Hai all,





I have one doubt in c#.


I have few files in java.


Can i use those java file in c#.





For example DataSheet is a class in java.


Can i use that DataSheet class in my windows application.





But that java file is opened like J#.





Then i have another doubt. What is language interoperability.


Any relation is between language interoperability and the above case.





Any one please guide.





Thanks advance

How to use java file in c#?
Use Java in C# using IVKM.NET (http://www.codeproject.com/useritems/csh...


Or this http://www.thescripts.com/forum/post1025...





Language interoperability is the ability of code to interact with code that is written using a different programming language. Language interoperability can help maximize code reuse and, therefore, improve the efficiency of the development process.





Yes, language interoperability is demonstrated in this case. See http://www.velocityreviews.com/forums/t1... for more details on how C# and Java interoperate with examples,