1   1  /  1  页   跳转

程序莫名崩溃

程序莫名崩溃

写了一个小程序,用来利用taskkill.exe终止进程.

//------------------temp.cpp--------------------//
#include "stdafx.h"

#include <CMyProcess.h>

void main()
{
    char  szProcess[16];
    printf("Please Enter The Process Name.\n");
    scanf("%s",szProcess);
    CMyProcess* mp;
    mp->TKTerminateProcess(szProcess);
}


//---------------CMyProcess.h------------------//
////////////////////////////////
//TODO:If you want to use this header file,please include these header files.....
/**************************\
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <string.h>
\**************************/

///////////////////////////////
//Begin Header File


class CMyProcess
{
private:
    HANDLE hProcess;
    BOOL bRet;
    BOOL bCreateProcess;
public:
    BOOL TKTerminateProcess(char pName[]);
    BOOL MyTerminate(char lpCmdLine[]);
};



BOOL CMyProcess::TKTerminateProcess(char pName[])
{
    printf("注意:这个方法只对Win2K\\XP\\2003有效!\n\n");
    if(pName!=NULL)
    {
        char pCmdLine[]="taskkill /f /im ";
        strcat(pCmdLine,pName);
        return this->MyTerminate(pCmdLine);
    }
    return FALSE;
}
BOOL CMyProcess::MyTerminate(char lpCmdLine[])
{
           STARTUPINFO si={sizeof(si)};
        PROCESS_INFORMATION pi;
        bCreateProcess=::CreateProcess(  NULL,
                                lpCmdLine,
                                NULL,
                                NULL,
                                FALSE,
                                CREATE_NEW_CONSOLE,
                                NULL,
                                NULL,
                                &si,
                                &pi
                                );
        if(bCreateProcess)
        {
            printf("Successed!\n");
            ::CloseHandle(pi.hThread);
            ::CloseHandle(pi.hProcess);
        }
        else
        {
            printf("Failed!\n");
        }

        return bCreateProcess;
}




可是运行后,终止进程时却崩溃了.WINDOWS要求发送错误报告.而终止其它进程则可以正常完成.请问这是什么原因?
最后编辑2006-09-23 19:27:20
分享到:
gototop
 

新手忙帮不上,帮你顶一下是可以的.


顶一下...............
gototop
 

换成char[]也不行
以前好像崩溃都是因为用了没有定义长度的char[]
gototop
 

顶一下
gototop
 
1   1  /  1  页   跳转
页面顶部
Powered by Discuz!NT