MFC的一个程序,求帮忙。

kaichuang1992 2015-04-07 12:38:34
刚刚接触C++,一直调试有错误,可能语法逻辑有问题,但是找不出来,求帮忙解答,感谢。
visual studio 2010默认建的MFC aplication,*.h 和 *.cpp 文件附下
=======================================================

// geffeDlg.h : header file

#pragma once

// CgeffeDlg dialog
class CgeffeDlg : public CDialogEx
{
// Construction
public:
CgeffeDlg(CWnd* pParent = NULL); // standard constructor

// Dialog Data
enum { IDD = IDD_GEFFE_DIALOG };

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support


// Implementation
protected:
HICON m_hIcon;

// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public:
CString m_IN;
CString m_OUT;
afx_msg void OnBnClickedButton();
afx_msg void OnEnChangeEditIn();
afx_msg void OnEnChangeEditOut();
};

//int main(int argc, char* argv[]);
unsigned char buf[1000],buf1[1000],buf2[1000],b[10000],c[1000];
void cypt(unsigned char b[]);
void Geffe(unsigned char buf[],unsigned char buf1[],unsigned char buf2[],unsigned char b[]);
void output_binary(unsigned char c);
void lfsr_output_byte(int n,unsigned char c,unsigned char init_state,unsigned char output_bytes[],int byte_length);
unsigned char fn_feedback( unsigned char n,unsigned char c,unsigned char curr_state);

=====================================================================================

// geffeDlg.cpp : implementation file
//

#include "stdafx.h"
#include <iostream>
#include "geffe.h"
#include "geffeDlg.h"
#include "afxdialogex.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#endif
using namespace std;

// CAboutDlg dialog used for App About

class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();

// Dialog Data
enum { IDD = IDD_ABOUTBOX };

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

// Implementation
protected:
DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()


// CgeffeDlg dialog




CgeffeDlg::CgeffeDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CgeffeDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_IN = _T("");
m_OUT = _T("");
}

void CgeffeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT_IN, m_IN);
DDX_Text(pDX, IDC_EDIT_OUT, m_OUT);
}

BEGIN_MESSAGE_MAP(CgeffeDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON, &CgeffeDlg::OnBnClickedButton)
ON_EN_CHANGE(IDC_EDIT_IN, &CgeffeDlg::OnEnChangeEditIn)
ON_EN_CHANGE(IDC_EDIT_OUT, &CgeffeDlg::OnEnChangeEditOut)
END_MESSAGE_MAP()


// CgeffeDlg message handlers

BOOL CgeffeDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// 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
}

void CgeffeDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}

// 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 CgeffeDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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
{
CDialogEx::OnPaint();
}
}

// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CgeffeDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}

void CgeffeDlg::OnBnClickedButton()
{
UpdateData(true);

lfsr_output_byte(5,(unsigned char)144,(unsigned char)152, buf, 100);
lfsr_output_byte(5,(unsigned char)44,(unsigned char)152, buf1, 100);
lfsr_output_byte(5,(unsigned char)24,(unsigned char)152, buf2, 100);

Geffe(buf,buf1,buf2,b);

cypt(b);

//system("pause");
return;

UpdateData(false);
}
//return next state 反馈
unsigned char fn_feedback( unsigned char n,unsigned char c,unsigned char curr_state)
{
unsigned char t = c & curr_state;
unsigned char s = t & (unsigned char)128;//get first bit
for(int i =1; i< n; i++)
{
s = s ^ ( (t << i) & (unsigned char)128 );
}
return (unsigned char)((curr_state << 1) | (s >> (n-1))); //return next state
}

//产生LFSR序列
void lfsr_output_byte(int n,unsigned char c,unsigned char init_state,unsigned char output_bytes[],int byte_length)
{
unsigned char next_state = init_state;

for(int i = 0; i < byte_length; i++)
{
unsigned char temp = (unsigned char)0;
for(int j=0; j< 8; j++)
{
temp = temp | ( (next_state & (unsigned char)128) >> j );
next_state = fn_feedback(n, c, next_state);
}
output_bytes[i] = temp;
}
}


//geffe生成器
void Geffe(unsigned char buf[],unsigned char buf1[],unsigned char buf2[],unsigned char b[])
{
for(int i=0; i< 10; i++)
{
b[i]=buf[i]*buf1[i]+buf2[i]*buf1[i]+buf2[i];
output_binary( (unsigned char)b[i]);
}
}



//加密解密函数
void cypt(unsigned char b[])
{
unsigned char m_IN[1000],m_OUT[1000];
int j;
for(j=0;m_IN[j]!='\0';j++)
{
m_OUT[j]=m_IN[j]^b[j];
cout<<m_OUT[j];
}
// for(int k=0;k<j;k++)
// {
// m_IN[k]=m_OUT[k]^b[k];
// }
}

...全文
209 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lx624909677 2015-04-07
  • 打赏
  • 举报
回复
上面的错误,清理下工程重新生成试试
kaichuang1992 2015-04-07
  • 打赏
  • 举报
回复
哇 那个错误解决了!谢谢 又出了新的错误额: 1>LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt 1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\Microsoft.Cpp.Win32.Targets(268,5): error MSB6006: "link.exe" exited with code 1123.
孤客天涯 2015-04-07
  • 打赏
  • 举报
回复
改成extern unsigned char buf[1000],buf1[1000],buf2[1000],b[10000],c[1000];试试
kaichuang1992 2015-04-07
  • 打赏
  • 举报
回复
统一变量类型之后 就是报上面的错误 然后就不知道怎么办了
kaichuang1992 2015-04-07
  • 打赏
  • 举报
回复
1> All outputs are up-to-date. 1>geffeDlg.obj : error LNK2005: "unsigned char * buf" (?buf@@3PAEA) already defined in geffe.obj 1>geffeDlg.obj : error LNK2005: "unsigned char * buf1" (?buf1@@3PAEA) already defined in geffe.obj 1>geffeDlg.obj : error LNK2005: "unsigned char * buf2" (?buf2@@3PAEA) already defined in geffe.obj 1>geffeDlg.obj : error LNK2005: "unsigned char * b" (?b@@3PAEA) already defined in geffe.obj 1>geffeDlg.obj : error LNK2005: "unsigned char * c" (?c@@3PAEA) already defined in geffe.obj 1>LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt 1>
孤客天涯 2015-04-07
  • 打赏
  • 举报
回复
报的什么错?

16,503

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧