从Windows XP到Windows 7获取程序,MFC vs C#vs C ++ [英] Getting a program from Windows XP to Windows 7, MFC vs C# vs C++

查看:110
本文介绍了从Windows XP到Windows 7获取程序,MFC vs C#vs C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我继承了一个项目(我在实验室中工作),以将定制的程序从Windows XP移植到Windows7.该程序最初是在Microsoft Visual Studio .Net版本7.0和MFC中创建的.

我曾尝试仅使用Visual Studio进行导入和转换,但是却遇到了很多麻烦.现在,我已经考虑过尝试通过复制已有的代码来重写程序,但是我需要学习MFC.尝试使用C#或坚持使用C ++/MFC会更快吗?该程序用于运行一个仪器以收集数据,总计约6MB.

当前,我正在遍历MFC教程,试图学习我能做的事,在这里我看到了有关MFC书籍的另一篇文章,但是关于哪本书是一本好书的建议却有些模棱两可.我认为,2008年的任何一本书都是不错的.

有没有人有任何建议作为解决此问题的最佳方法?我有一定的C ++背景.

这是在VS2010中转换后的构建输出的初始部分:

Ok, so I have inherited a project (I work in a lab) to port a custom built program from Windows XP to Windows 7. The program was originally created in Microsoft Visual Studio .Net Version 7.0 and MFC.

I have tried to just import and convert with Visual Studio, but I get tons of erros. Now I have thought about trying to rewrite the program by copying the code already there but I need to learn MFC. Would it be faster to try and use C# or stick with C++/MFC? The program is made to run an instrument to collect data and is in total about 6MB.

Currently, I am running through MFC tutorials trying to learn what I can and I saw another thread on here about MFC books but the suggestions were a little ambiguous about which book is a good book. I took away from it that any 2008 book is decent.

Does anyone have any suggestions as the best way to attack this problem? I have some background in C++.

Here is the initial part of the build output after converting in VS2010:

;------ Build started: Project: WinSTM, Configuration: Release Win32 ------
1>  StdAfx.cpp
1>  _WIN32_WINNT not defined. Defaulting to _WIN32_WINNT_MAXVER (see WinSDKVer.h)
1>  ChildFrm.cpp
1>  CntrItem.cpp
1>  ColorFrameCtrl.cpp
1>  ColorPickerDlg.cpp
1>  Common.cpp
1>  Coord.cpp
1>  DBLog.cpp
1>c:\users\andy\desktop\winstm code repository\code\copy of winstm 12-17-09\DBLog.h(23): warning C4995: ''CDaoDatabase'': name was marked as #pragma deprecated
1>c:\users\andy\desktop\winstm code repository\code\copy of winstm 12-17-09\DBLog.h(24): warning C4995: ''CDaoRecordset'': name was marked as #pragma deprecated
1>  DIB.cpp
1>DIB.cpp(636): error C2666: ''pow'' : 6 overloads have similar conversions
1>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\math.h(583): could be ''long double pow(long double,int)''
1>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\math.h(581): or       ''long double pow(long double,long double)''
1>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\math.h(535): or       ''float pow(float,int)''
1>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\math.h(533): or       ''float pow(float,float)''
1>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\math.h(497): or       ''double pow(double,int)''
1>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\math.h(122): or       ''double pow(double,double)''
1>          while trying to match the argument list ''(double, float)''
1>DIB.cpp(782): warning C4018: ''<'' : signed/unsigned mismatch
1>DIB.cpp(792): warning C4018: ''<'' : signed/unsigned mismatch
1>  DlgChartSettings.cpp
1>  DlgCompareData.cpp
1>  DlgExportMovie.cpp
1>DlgExportMovie.cpp(434): warning C4996: ''fopen'': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\stdio.h(234) : see declaration of ''fopen''
1>  DlgGPIB_Diag.cpp
1>  DlgGetPath.cpp
1>pathpicker\DlgGetPath.cpp(334): warning C4996: ''strcpy'': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\string.h(105) : see declaration of ''strcpy''
1>  DlgHardwareSettings.cpp
1>DlgHardwareSettings.cpp(103): warning C4996: ''_gcvt'': This function or variable may be unsafe. Consider using _gcvt_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\stdlib.h(729) : see declaration of ''_gcvt''
1>DlgHardwareSettings.cpp(104): warning C4996: ''_gcvt'': This function or variable may be unsafe. Consider using _gcvt_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\stdlib.h(729) : see declaration of ''_gcvt''
1>  DlgHdrChan.cpp
1>  DlgHdrDelay.cpp
1>  DlgHdrGain.cpp
1>  DlgHdrLine.cpp
1>  DlgHdrParameters.cpp
1>  DlgHdrSpec.cpp
1>  Generating Code...
1>  Compiling...
1>  DlgHdrZ.cpp
1>  DlgHeader.cpp
1>  DlgIlluminateLut.cpp
1>DlgIlluminateLut.cpp(275): warning C4244: ''initializing'' : conversion from ''double'' to ''int'', possible loss of data
1>DlgIlluminateLut.cpp(276): warning C4244: ''initializing'' : conversion from ''double'' to ''int'', possible loss of data
1>  DlgInstrument_ADC_DAC.cpp
1>  DlgInstrument_CAMAC.cpp
1>  DlgInstrument_Channels.cpp



这是一份简短的列表..我总共有534个错误和760个警告.

在解决了与上述建议相关的所有错误之后,我的错误计数减少到7!我在下面将它们与它们所引用的代码部分一起发布了:

1> ScanAcq.cpp(2336):错误C3867:"CDlg_ScanAcq :: InitScan":函数调用缺少参数列表;使用''& CDlg_ScanAcq :: InitScan''创建指向成员的指针
1> ScanAcq.cpp(2401):错误C3867:"CDlg_ScanAcq :: InitLineScan":函数调用缺少参数列表;使用''& CDlg_ScanAcq :: InitLineScan''创建指向成员的指针
1> ScanAcq.cpp(2462):错误C3867:"CDlg_ScanAcq :: InitPointSpecScan":函数调用缺少参数列表;使用''& CDlg_ScanAcq :: InitPointSpecScan''创建指向成员的指针
1> ScanAcq.cpp(2555):错误C3867:"CDlg_ScanAcq :: InitMultiGapScan":函数调用缺少参数列表;使用``& CDlg_ScanAcq :: InitMultiGapScan''创建指向成员的指针
1> ScanAcq.cpp(2617):错误C3867:"CDlg_ScanAcq :: InitCITSScan":函数调用缺少参数列表;使用``& CDlg_ScanAcq :: InitCITSScan''创建指向成员的指针

在这段代码中:



This is a short list..the total amount of errors I have are 534 errors and 760 warnings.

After taking care of all of the errors related to suggestions above, my error count reduced to 7! I posted them below along with the code section they refer to:

1>ScanAcq.cpp(2336): error C3867: ''CDlg_ScanAcq::InitScan'': function call missing argument list; use ''&CDlg_ScanAcq::InitScan'' to create a pointer to member
1>ScanAcq.cpp(2401): error C3867: ''CDlg_ScanAcq::InitLineScan'': function call missing argument list; use ''&CDlg_ScanAcq::InitLineScan'' to create a pointer to member
1>ScanAcq.cpp(2462): error C3867: ''CDlg_ScanAcq::InitPointSpecScan'': function call missing argument list; use ''&CDlg_ScanAcq::InitPointSpecScan'' to create a pointer to member
1>ScanAcq.cpp(2555): error C3867: ''CDlg_ScanAcq::InitMultiGapScan'': function call missing argument list; use ''&CDlg_ScanAcq::InitMultiGapScan'' to create a pointer to member
1>ScanAcq.cpp(2617): error C3867: ''CDlg_ScanAcq::InitCITSScan'': function call missing argument list; use ''&CDlg_ScanAcq::InitCITSScan'' to create a pointer to member

From this section of code:

ScanFunction = CDlg_ScanAcq::InitScan;
ScanFunction = CDlg_ScanAcq::InitLineScan;
ScanFunction = CDlg_ScanAcq::InitPointSpecScan;
ScanFunction = CDlg_ScanAcq::InitMultiGapScan; 
ScanFunction = CDlg_ScanAcq::InitCITSScan;



以及以下2个错误:



and the following 2 errors:

1>graph\sizecbar.cpp(109): error C2440: ''static_cast'' : cannot convert from ''UINT (__thiscall CSizingControlBar::* )(CPoint)'' to ''LRESULT (__thiscall CWnd::* )(CPoint)''
1>          Cast from base to derived requires dynamic_cast or static_cast
1>graph\sizecbar.cpp(593): error C2065: ''i'' : undeclared identifier




引用本节:




Referring to this section:

ON_WM_NCHITTEST()





and

CSizingControlBar* pBar = arrSCBars[i +
            ((m_htEdge == HTTOP || m_htEdge == HTLEFT) ? -1 : 1)];




来自更大的细分市场




from this larger segment

void CSizingControlBar::StartTracking(UINT nHitTest)
{
    SetCapture();
    // make sure no updates are pending
    RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_UPDATENOW);
    
    BOOL bHorz = IsHorzDocked();
    m_szOld = bHorz ? m_szHorz : m_szVert;
    CRect rc;
    GetWindowRect(&rc);
    CRect rcEdge;
    VERIFY(GetEdgeRect(rc, nHitTest, rcEdge));
    m_ptOld = rcEdge.CenterPoint();
    m_htEdge = nHitTest;
    m_bTracking = TRUE;
    CSCBArray arrSCBars;
    GetRowSizingBars(arrSCBars);
    // compute the minsize as the max minsize of the sizing bars on row
    m_szMinT = m_szMin;
    for (int i = 0; i < arrSCBars.GetSize(); i++)
        if (bHorz)
            m_szMinT.cy = max(m_szMinT.cy, arrSCBars[i]->m_szMin.cy);
        else
            m_szMinT.cx = max(m_szMinT.cx, arrSCBars[i]->m_szMin.cx);
    if (!IsSideTracking())
    {
        // the control bar cannot grow with more than the size of 
        // remaining client area of the mainframe
        m_pDockSite->RepositionBars(0, 0xFFFF, AFX_IDW_PANE_FIRST,
            reposQuery, &rc, NULL, TRUE);
        m_szMaxT = m_szOld + rc.Size() - CSize(4, 4);
    }
    else
    {
        // side tracking: max size is the actual size plus the amount
        // the neighbour bar can be decreased to reach its minsize
        for (int i = 0; i < arrSCBars.GetSize(); i++)
         if (arrSCBars[i] == this) break;
		
        CSizingControlBar* pBar = arrSCBars[i +
            ((m_htEdge == HTTOP || m_htEdge == HTLEFT) ? -1 : 1)];
		
        m_szMaxT = m_szOld + (bHorz ? pBar->m_szHorz :
            pBar->m_szVert) - pBar->m_szMin;
	}
    OnTrackInvertTracker(); // draw tracker
}




谢谢大家的帮助,

安德鲁




Thanks everyone for your help,

Andrew

推荐答案

经历了不少苦难. :-) C#?它是完全重写的,也许可以使用您的旧项目作为参考.即使您要修复和升级旧项目,也可能会出现这种情况.在不查看项目的情况下很难说出更多确定的信息.抱歉,没有简单的食谱.

—SA
Through suffering, no less. :-) C#? It''s total rewriting, perhaps using your legacy project as a reference. This would be likely a case even it you want to fix and upgrade your legacy project; hard to say anything more certain without looking at your project. Sorry, no easy recipe.

—SA


我决定将其发布为新的解决方案,因此更容易发现是否有人.

通过查看您的错误消息,第一个是_WIN32_WINNT未定义.在这种情况下,VS2010将使用最新的定义,这(IIRC)表示它将使用Windows 7项目,因此可能无法在XP上运行.要解决此问题,请转到解决方案资源管理器,然后右键单击解决方案名称,然后选择属性".在配置属性/C/C ++"选项卡下,选择预处理器.在右框中,您将看到预处理器定义,其外观类似于
I decided to post this as a new solution, so it would be easier to find if anyone looks.

By looking at your error messages, the first this is _WIN32_WINNT not defined. In this case VS2010 will use the latest definition, which (IIRC) means it will use Windows 7 items, and therefore might not run on XP. To resolve this go to the solution explorer and right click on the solution name and select "Properties". Under the "Configuration Properties/C/C++ tab, select Preprocessor. In the right box you''ll see Preprocessor Definitions that will look something like
WIN32;_DEBUG;_WINDOWS;(PreprocessorDefinitions)

将其更改以添加WINVER = 0x0501.现在它应类似于

Change it to add WINVER=0x0501. It should now look like

WIN32;_DEBUG;_WINDOWS;WINVER=0x0501;%(PreprocessorDefinitions)

允许它使用XP功能,这些功能也将在Windows 7上运行.

接下来,您将发出有关不建议使用CDaoDatabase的警告-的确如此,Windows 7不再支持它,但是如果您安装了MDAC可再发行组件,它仍然可以工作.最终应更改为停止使用DAO并开始使用ADO或其他一些数据库技术.

下一批警告是pow功能.您的代码中可能有类似

This allows it to use XP features, which will also work on Windows 7.

Next, you have a warning about CDaoDatabase being deprecated - this is true, it''s no longer supported on Windows 7, but if you install the MDAC redistributable, it will still work. Eventually this should be changed to stop using DAO and start using ADO or some other database technology.

The next batch of warnings are the pow function. You probably have something like

float x;
x = pow(2, 12);

的内容.在这种情况下,您要将两个int传递给pow函数,但是pow函数没有接受两个int的签名(请参阅

in your code. I this case, you''re passing two ints to the pow function, but the pow funtion does not have a signature that accepts two ints (see MSDN[^]), so the ints need to be promoted to something else. For instance, the first argument could be promoted to a float or a double, but the compiler doesn''t know which one - so you need to tell it by casting:

x = pow((double)2, 12);



接下来,有一些关于不安全"功能的警告.这些通常是易于导致缓冲区溢出错误的函数,因此Microsoft提供了安全"的替代方法,例如:

代替fopen,使用fopen_s
代替strcpy,使用strcpy_s
等等.您也可以在MSDN上找到有关这些文档的文档

较早的功能(fopen,strcpy)仍然可以使用,您只会收到这些警告.如果您不想要警告(并且我不喜欢任何警告),则可以(如警告消息中所述)在预处理器定义(我们之前在其中添加WINVER)中定义_CRT_SECURE_NO_WARNINGS.因此您的预处理器定义可能类似于:



Next, there are several warnings about "unsafe" functions. These are typically functions that tend to cause buffer overflow errors, so Microsoft provides a "safe" replacement... such as:

instead of fopen, use fopen_s
instead of strcpy, use strcpy_s
and so on. You can find the documentation for these also on MSDN>

The older functions (fopen, strcpy) will still work, you''ll just receive these warnings. If you don''t want the warnings (and I don''t like any warnings) you can (as mentioned in the warning message) define _CRT_SECURE_NO_WARNINGS in the preprocessor definitions (where we added the WINVER earlier). So your Preprocessor definitions might look like:

WIN32;_DEBUG;_WINDOWS;WINVER=0x0501;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)



关于从double到int转换的警告很可能来自诸如



The warning about conversion from double to int is most likely from code such as

double dVal = 2.5;
int iMyVal = dVal;


的代码
最后(在您发布的消息中)关于有符号/无符号不匹配的警告表示您正在将有符号值与无符号值进行比较,例如:



And last (of the messages you posted) the warning about signed/unsigned mismatch means you''re comparing a signed value to an unsigned value, such as:

unsigned long ul_Val1 = 25499;
ing iOtherVal = 2944;
if (ul_Val1 < iOtherVal)...



更正这些项目时,您可能会看到错误/警告的数量急剧下降.

希望有帮助.

[NEW STUFF HERE]
好吧...既然您有7个问题,它们应该相对容易.第一个(5个问题)在错误消息中给出了解决方法



When you correct these items, you''ll probably see the number of errors/warning drop drastically.

Hope that helps.

[NEW STUFF HERE]
OK... now that you''re down to 7 problems, they should be relatively easy. The first (5 problems) give the soltuion in the error message

1>ScanAcq.cpp(2336): error C3867: ''CDlg_ScanAcq::InitScan'': function call missing argument list; use ''&CDlg_ScanAcq::InitScan'' to create a pointer to member


如前所述,您需要使用&创建指向此函数的指针.这应该可以解决这5个问题.


As it says, you need to use the & to create a pointer to this function. This should solve those 5 problems.

ScanFunction = &CDlg_ScanAcq::InitScan;
ScanFunction = &CDlg_ScanAcq::InitLineScan;
ScanFunction = &CDlg_ScanAcq::InitPointSpecScan;
ScanFunction = &CDlg_ScanAcq::InitMultiGapScan; 
ScanFunction = &CDlg_ScanAcq::InitCITSScan;


最后两个错误


The final two errors

1>graph\sizecbar.cpp(109): error C2440: ''static_cast'' : cannot convert from ''UINT (__thiscall CSizingControlBar::* )(CPoint)'' to ''LRESULT (__thiscall CWnd::* )(CPoint)''
1>          Cast from base to derived requires dynamic_cast or static_cast
1>graph\sizecbar.cpp(593): error C2065: ''i'' : undeclared identifier

也相对容易.首先,这基本上说它不能从UINT ....转换为LRESULT ...,这意味着您有一个函数(NCHITTEST),它返回UINT并需要返回LRESULT.在.cpp和.h文件中查找您的OnNcHitTest或其名称的真正含义,然后将返回类型从UINT更改为LRESULT-Microsoft更改了几种框架方法的返回类型.

关于我未被声明的标识符的最终错误可能是由以下原因引起的:

are also relatively easy. The first of this says basically that it can''t convert from UINT.... to LRESULT... which means that you have a function (the NCHITTEST) that returns a UINT and needs to return an LRESULT. Look for your OnNcHitTest or whatever it''s name really is in both the .cpp and .h files and change the return type from UINT to LRESULT - Microsoft changed the return type on several of the framework methods.

The final error about i being undeclared identifier can be caused by something like this:

for (int i=0; i< 1000; i++)
{
    //do some stuff in here
    //and more stuff
}
if (i == 1000)    //here i is undeclared because it was declared INSIDE the for loop.

在VS的早期版本中这是可以的,但现在已在适当范围内.要解决此问题,请将i ouside的声明移动到循环中:

This was OK in prior versions of VS, but is now properly scoped. To solve it, move the declaration of i ouside the loop:

int i = 0;
for (i=0; i< 1000; i++)
{
    //do some stuff in here
    //and more stuff
}
if (i == 1000)  // now it''s OK


希望这可以解决您的问题-但您仍然必须进行彻底的测试-仅因为所有这些内容都可以编译和链接并不意味着它将正常运行.

祝你好运.


Hope this resolves your issues - but you still must test throroughly - just because it all compiles and links doesn''t mean it will work correctly.

Good luck.


通常这不是什么大问题.如果仅在VS2010中打开该解决方案,它将转换几乎所有需要完成的工作.

如果在那之后您仍然收到大量错误",则仅发送1/2吨错误,这样我们就可以知道它们是什么,这将有所帮助.纠正起来可能相对简单.

如果该程序最初是正确编写的,则应在Windows 7上按原样"运行.
Normally this shouldn''t be much of a problem. If you just open the solution in VS2010 it will convert almost everything that needs to be done.

If, after that, you still receive "tons of errors" it would help if you''d post only 1/2 ton of the errors so we can see what they are. It may be relatively simple to correct.

If the program was decently written in the first place it should run "as is" on Windows 7.


这篇关于从Windows XP到Windows 7获取程序,MFC vs C#vs C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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