Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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


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;


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
Posted
Updated 16-Jun-11 16:19pm
v5
Comments
Sergey Chepurin 16-Jun-11 9:27am    
Correct the errors first. You can disable warnings for the time being by setting in "Properties" Warning level->Off(/W0). You can remove warnings later improving the code.

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
 
Share this answer
 
Comments
AndrewG1231 15-Jun-11 16:19pm    
Later on I will post some of the errors I've been getting online by improving the question, maybe that will help with the suggestions. I would prefer not to suffer too much!
Sergey Alexandrovich Kryukov 16-Jun-11 11:25am    
Certainly. My idea is: rewriting is not suffering, fixing someone's bugs is. More of good work is better then less of idiotic work.
Hope we could help you by reducing total amount of suffering, not by reloading it from one person to another.
--SA
AndrewG1231 15-Jun-11 20:16pm    
The code has been added to the question, if you have any ideas let me know.
Sergey Alexandrovich Kryukov 16-Jun-11 11:29am    
Sorry, it's pretty much useless. First, this is not code, but a compiler output, not very useful without code. Amount of code might make questions to CodeProject useless. You will have to make massive work isolate problems, create small samples of the problems which may need expert help and present them. Right now, I don't see such problems. They are all of go-start-and-finish type: find library API, see the difference, find corrected call, etc.
--SA
Albert Holguin 16-Jun-11 10:16am    
"no easy recipe"... very true... my 5
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)
Change it to add WINVER=0x0501. It should now look like
WIN32;_DEBUG;_WINDOWS;WINVER=0x0501;%(PreprocessorDefinitions)
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);
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);


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)


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)...


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

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
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.
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.
 
Share this answer
 
v3
Comments
Albert Holguin 16-Jun-11 10:18am    
fact of the matter is... there's a lot of problems to fix... but you gave him a good start... my 5 for it! :)
krmed 16-Jun-11 11:38am    
Thanks - I appreciate it.
Sergey Alexandrovich Kryukov 16-Jun-11 11:30am    
Impressive effort, my 5.
--SA
krmed 16-Jun-11 11:39am    
Thanks - I appreciate it.
AndrewG1231 16-Jun-11 15:32pm    
Thanks for the direction, I definitely feel like I can make some progress (and will probably ask another question after I go through everything). Why would these errors not have stopped the program originally?
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.
 
Share this answer
 
Comments
AndrewG1231 15-Jun-11 16:18pm    
I have been messing with it, on a copy of the code of course, so I will start from after conversion and improve my question in a bit with some of the errors. Most are declarations of variable errors and overloaded function errors at first where most variables are missing data types. I am not sure why these occur..and if arbitrarily choosing a data type is bad for how the program processes info. I am definitely appreciative of the help, thanks!
AndrewG1231 15-Jun-11 20:15pm    
I improved my question a bit by adding the code...any help you can give is appreciated.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900