为什么我的Windows窗体应用程序是在项目中自动退出? [英] why my windows forms application is autoexiting in project?

查看:89
本文介绍了为什么我的Windows窗体应用程序是在项目中自动退出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private:
	void split_it()
	{
		FILE *fpi, *fpo;//file pointers for the input and output files respectively.
		char * dr = new char[1024];
		char inputfilename[100] = "", tmp[20] = ".part", tname[80] = "", c;
		int n = 2, j = 0, l = 0, m = 0, rem = 0;
		long divided = 0;
		double k = 0;
		n = int(No_of_Parts; Value);
		size_t size;

		for each (char t in Input_Path - > Text)
		{
			inputfilename[j] = t;
			j++;
		}

		j = 0;

		if ((fpi = fopen(inputfilename, "rb")) == NULL)
		{
			System::Windows::Forms::MessageBox::Show("Invalid File Name:");
			exit(0);
		}

		fseek(fpi, 0, SEEK_END);
		k = ftell(fpi);
		rewind(fpi);

		for (j = strlen(inputfilename); j> = 0; j--)
		{
			if (inputfilename[j] == '.')
			{
				for (m = j - 1; inputfilename[m] != '/'; m--)
				{
					tname[l] = inputfilename[m];
					l++;
				}
			}
		}
		strrev(tname);

		for (j = 0; j< n; j++)
		{
			c = j + '0';
			output[j].outputfiles = new char[20];
			strcpy(output[j].outputfiles, inputfilename);
			tmp[strlen(tmp)] = c;
			strcat(output[j].outputfiles, tmp);

			strcpy(tmp, ".part");
		}

		divided = long(k) / n;

		rem = long(k) - (divided*n);

		m = divided / 512;

		for (j = 0; j< (n - 1); j++)
		{
			l = 0;
			fpo = fopen(output[j].outputfiles, "wb+");

			while (l != m)
			{
				size = fread(dr, 1, 512, fpi);
				fwrite(dr, size, 1, fpo);
				l++;
			}

			m = divided - (m * 512);
			size = fread(dr, 1, m, fpi);
			fwrite(dr, size, 1, fpo);
			fclose(fpo);
			m = divided / 512;
		}

		l = 0;
		fpo = fopen(output[j].outputfiles, "wb+");

		while (l != m)
		{
			size = fread(dr, 1, 512, fpi);
			fwrite(dr, size, 1, fpo);
			l++;
		}

		m = divided - (m * 512);
		m = m + rem;
		size = fread(dr, 1, m, fpi);
		fwrite(dr, size, 1, fpo);
		fclose(fpi);
		fclose(fpo);

	}



我在visual studio中创建了CLR c ++项目。添加了新的Windows窗体。

表格应用程序工作正常。但是当我调用上面的函数来使用OpenFileDialog组件拆分所选文件时,正确地拆分文件,然后应用程序自动退出而不是返回。


I m created the CLR c++ Project in visual studio.Added the new Windows Form.
Form application was working correctly.But when i call the above function to split the selected file using the OpenFileDialog component.it splits the file correctly,then the application Exiting automatically instead of returning back.

推荐答案

好吧,你应该尝试制作更好的代码......我建议你阅读有关编写可靠和可维护代码的书。



这里有一些建议:

- 在多个自我记录的问题中拆分代码。

- 避免硬代码常量

- 避免内存泄漏。 />
- 为变量赋予有意义的名称。

- 使用现有函数来改变字符串的格式。

- 制作可重复使用的代码(不要混用带有业务逻辑的UI代码。

- 首次使用时声明变量。

- 避免显式内存管理。
- 使用C ++样式转换

- 避免硬编码缓冲区大小可能不够大。

- 避免混合使用C,C ++和没有充分理由的C ++ / CLI代码。

- 正确处理Unicode字符。

- ...



正如其他人提到的,你应该使用调试器。
Well, you should try to make better code... I would suggest you to read book on writing solid and maintainable code.

Here are some suggestions:
- Split code in multiple, self-documented question.
- Avoid hard-code constant
- Avoid memory leaks.
- Give meaningful names to variables.
- Uses existing functions to change the format of a string.
- Make reusable code (don't mix UI code with business logic).
- Declare variable on their first use.
- Avoid explicit memory management.
- Uses C++ style cast
- Avoid hard-code buffer size that might not always be big enough.
- Avoid mixing C, C++ and C++/CLI code without good reason.
- Properly handle Unicode characters.
- ...

As someone else mentioned, you should use a debugger.


这篇关于为什么我的Windows窗体应用程序是在项目中自动退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆