调试通过,启动程序初始化失败!!高手求教!!
自己写的一个支持mfc的控制台程序,主要功能为读取一个txt文件,扫描每一行中的数据进行一些处理后,将数据存到一个数组里。最后调用一个写图像函数。程序调试通过,但是启动运行的时候出现提示“应用程序正常初始化(0xc0150002)失败。请单击“确定”,终止应用程序”。编程工具vs2008,因为程序很简单,主要源代码如下:
#include "stdafx.h"
#include "test14.h"
#include "ImageWriter.h"
#include <math.h>
#define PI 3.14159
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 唯一的应用程序对象
CWinApp theApp;
struct Point //点结构
{
float x;
float y;
float z;
};
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// 初始化 MFC 并在失败时显示错误
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: 更改错误代码以符合您的需要
_tprintf(_T("错误: MFC 初始化失败\n"));
nRetCode = 1;
}
else
{
// TODO: 在此处为应用程序的行为编写代码。
//下面为自己写的代码
CStdioFile sfile1;
if(!sfile1.Open("3.txt",CFile::modeRead))
{
printf("Open file error!");
return 0;
}
Point pt={0.0,0.0,0.0}; //绝对值最大的x,y,z坐标
unsigned int num=0;
CString strLine;
while(sfile1.ReadString(strLine))
{
num++;
}
sfile1.Close();
float *cha=new float[num*4];
memset(cha,0,sizeof(float)*num*4);
unsigned int num1=0;
CStdioFile sfile5;
if(!sfile5.Open("3.txt",CFile::modeRead))
{
printf("Open file error!");
return 0;
}
CString strLine2;
while(sfile5.ReadString(strLine2))
{
Point pt1;
int i=strLine2.ReverseFind(' ');
int j=strLine2.Find(' ');
CString strData1=strLine2.Mid(i+1,strLine2.GetLength()-i);
CString strData2=strLine2.Mid(0,j);
int k=i-j-1;
CString strData3=strLine2.Mid(j+1,k);
pt1.z=atof(strData1.GetBuffer(0));
pt1.y=atof(strData3.GetBuffer(0));
pt1.x=atof(strData2.GetBuffer(0));
//strData1.ReleaseBuffer();
//strData2.ReleaseBuffer();
//strData3.ReleaseBuffer();
//求所有点中绝对值最大的x,y,z
if(fabs(pt1.x)>fabs(pt.x))
{
pt.x=pt1.x;
}
if(fabs(pt1.y)>fabs(pt.y))
{
pt.y=pt1.y;
}
if(fabs(pt1.z)>fabs(pt.z))
{
pt.z=pt1.z;
}
float sin1=sqrt(pt1.x*pt1.x+pt1.y*pt1.y)/sqrt(pt1.x*pt1.x+pt1.y*pt1.y+pt1.z*pt1.z);
float cos1=pt1.z/sqrt(pt1.x*pt1.x+pt1.y*pt1.y+pt1.z*pt1.z);
float sin2=pt1.y/sqrt(pt1.x*pt1.x+pt1.y*pt1.y);
float cos2=pt1.x/sqrt(pt1.x*pt1.x+pt1.y*pt1.y);
cha[num1]=sin1;
num1++;
cha[num1]=cos1;
num1++;
cha[num1]=sin2;
num1++;
cha[num1]=cos2;
num1++;
}
sfile5.Close();
float rMax=sqrt(pt.x*pt.x+pt.y*pt.y+pt.z*pt.z);
float *data= new float[num*3];
memset(data,0,sizeof(float)*num*3);
unsigned int num2=0; //总的点数乘以3
for(unsigned int j=0;j<num;j++)
{
data[num2]= rMax*cha[4*j]*cha[4*j+3];
num2++;
data[num2]= rMax*cha[4*j]*cha[4*j+2];
num2++;
data[num2]= rMax*cha[4*j+1];
num2++;
}
char *filename="1.tiff";
Boundbox box;
box.Xmax=pt.x;
box.Xmin=-pt.x;
box.Ymax=pt.y;
box.Ymin=-pt.y;
box.Zmax=pt.z;
box.Zmin=-pt.z;
writeToImage(filename,box,data,num,POINT);
delete [] data;
delete [] cha;
system("pause");
}
return nRetCode;
}