在win32下没有问题的程序,为什么复制到mfc工程下会有错误?
提示该内存不能为Written.

解决方案 »

  1.   

    #include "stdafx.h"
    #include "Import3DSFile.h"
    #include "Import3DSFileDlg.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif#define FILE_NAME  "face.3ds" /////////////////////////////////////////////////////////////////////////////
    // CImport3DSFileDlg dialogCImport3DSFileDlg::CImport3DSFileDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CImport3DSFileDlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CImport3DSFileDlg)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }void CImport3DSFileDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CImport3DSFileDlg)
    // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CImport3DSFileDlg, CDialog)
    //{{AFX_MSG_MAP(CImport3DSFileDlg)
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CImport3DSFileDlg message handlersBOOL CImport3DSFileDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    // TODO: Add extra initialization here

    return TRUE;  // return TRUE  unless you set the focus to a control
    }// If you add a minimize button to your dialog, you will need the code below
    //  to draw the icon.  For MFC applications using the document/view model,
    //  this is automatically done for you by the framework.void CImport3DSFileDlg::OnPaint() 
    {
    if (IsIconic())
    {
    CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
    CDialog::OnPaint();
    }
    }// The system calls this to obtain the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CImport3DSFileDlg::OnQueryDragIcon()
    {
    return (HCURSOR) m_hIcon;
    }BEGIN_EVENTSINK_MAP(CImport3DSFileDlg, CDialog)
        //{{AFX_EVENTSINK_MAP(CImport3DSFileDlg)
    ON_EVENT(CImport3DSFileDlg, IDC_OPENGL, 2 /* InitOpenGL */, OnInitOpenGLOpengl, VTS_NONE)
    ON_EVENT(CImport3DSFileDlg, IDC_OPENGL, 5 /* ReDraw */, OnReDrawOpengl, VTS_NONE)
    ON_EVENT(CImport3DSFileDlg, IDC_OPENGL, 6 /* ReSize */, OnReSizeOpengl, VTS_I2 VTS_I2)
    //}}AFX_EVENTSINK_MAP
    END_EVENTSINK_MAP()void CImport3DSFileDlg::OnInitOpenGLOpengl() 
    {
    // TODO: Add your control notification handler code here
    //刷新的背景色
    glClearColor(1.0,1.0,1.0,1.0);

    glEnable(GL_TEXTURE_2D);
    glEnable(GL_DEPTH_TEST);    
        
        g_Load3ds.Import3DS(&g_3DModel, FILE_NAME); // 将3ds文件装入到模型结构体中
    }void CImport3DSFileDlg::OnReDrawOpengl() 
    {
    // TODO: Add your control notification handler code here
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glLoadIdentity();

    SwapBuffers(::wglGetCurrentDC());
    }void CImport3DSFileDlg::OnReSizeOpengl(short w, short h) 
    {
    // TODO: Add your control notification handler code here if (h==0)
    h=1; glMatrixMode(GL_PROJECTION);
    glLoadIdentity(); gluPerspective(45.0f,(GLfloat)w/(GLfloat)h, .5f ,150.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glViewport(0,0,w,h);
    }
      

  2.   

    #ifndef _MAIN_H
    #define _MAIN_H#include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <fstream>
    #include <vector>
    #include <gl\gl.h>
    #include <gl\glu.h>
    #include <gl\glaux.h>
    #include <crtdbg.h>
    using namespace std;#define SCREEN_WIDTH 400
    #define SCREEN_HEIGHT 300
    #define SCREEN_DEPTH 16
    #define MAX_TEXTURES 100 // 最大的纹理数目
    // 定义3D点的类,用于保存模型中的顶点
    class CVector3 
    {
    public:
    float x, y, z;
    };// 定义2D点类,用于保存模型的UV纹理坐标
    class CVector2 
    {
    public:
    float x, y;
    };
    //  面的结构定义
    struct tFace
    {
    int vertIndex[3]; // 顶点索引
    int coordIndex[3]; // 纹理坐标索引
    };//  材质信息结构体
    struct tMaterialInfo
    {
    char  strName[255]; // 纹理名称
    char  strFile[255]; // 如果存在纹理映射,则表示纹理文件名称
    BYTE  color[3]; // 对象的RGB颜色
    int   texureId; // 纹理ID
    float uTile; // u 重复
    float vTile; // v 重复
    float uOffset;     // u 纹理偏移
    float vOffset; // v 纹理偏移
    } ;
    //  对象信息结构体
    struct t3DObject 
    {
    int  numOfVerts; // 模型中顶点的数目
    int  numOfFaces; // 模型中面的数目
    int  numTexVertex; // 模型中纹理坐标的数目
    int  materialID; // 纹理ID
    bool bHasTexture; // 是否具有纹理映射
    char strName[255]; // 对象的名称
    CVector3  *pVerts; // 对象的顶点
    CVector3  *pNormals; // 对象的法向量
    CVector2  *pTexVerts; // 纹理UV坐标
    tFace *pFaces; // 对象的面信息
    };//  模型信息结构体
    struct t3DModel 
    {
    int numOfObjects; // 模型中对象的数目
    int numOfMaterials; // 模型中材质的数目
    vector<tMaterialInfo> pMaterials; // 材质链表信息
    vector<t3DObject> pObject; // 模型中对象链表信息
    };#endif 
      

  3.   

    // Import3DSFileDlg.h : header file
    //
    #include "3DS.h"#if !defined(AFX_IMPORT3DSFILEDLG_H__E700A500_2D92_4FAC_8D46_6F4A140B1B45__INCLUDED_)
    #define AFX_IMPORT3DSFILEDLG_H__E700A500_2D92_4FAC_8D46_6F4A140B1B45__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000/////////////////////////////////////////////////////////////////////////////
    // CImport3DSFileDlg dialogclass CImport3DSFileDlg : public CDialog
    {
    // Construction
    public:
    CImport3DSFileDlg(CWnd* pParent = NULL); // standard constructor
    CLoad3DS g_Load3ds;
    t3DModel g_3DModel; // Dialog Data
    //{{AFX_DATA(CImport3DSFileDlg)
    enum { IDD = IDD_IMPORT3DSFILE_DIALOG };
    // NOTE: the ClassWizard will add data members here
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CImport3DSFileDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    HICON m_hIcon; // Generated message map functions
    //{{AFX_MSG(CImport3DSFileDlg)
    virtual BOOL OnInitDialog();
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    afx_msg void OnInitOpenGLOpengl();
    afx_msg void OnReDrawOpengl();
    afx_msg void OnReSizeOpengl(short w, short h);
    DECLARE_EVENTSINK_MAP()
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    private:
    };//{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_IMPORT3DSFILEDLG_H__E700A500_2D92_4FAC_8D46_6F4A140B1B45__INCLUDED_)