Issue with conversion from Visual C++ 6.0 to Visual Studio 2012 - c++

I have a Visual C++ 6.0 project which I need to update and I import it to Visual Studio 2012 with no problems, however, during compilation, I get the following four errors:
Error 1 error C2440: 'static_cast' : cannot convert from 'void
(__thiscall CTrendDlg::* )(int)' to 'void (__thiscall CCmdTarget::*
)(UINT)' c:\users\nima\desktop\ffls_scode\trenddlg.cpp 89
Error 6 error C2440: 'static_cast' : cannot convert from 'void
(__thiscall CManualDlg::* )(int)' to 'void (__thiscall CCmdTarget::*
)(UINT)' c:\users\nima\desktop\ffls_scode\manualdlg.cpp 175
Error 7 error C2440: 'static_cast' : cannot convert from 'void
(__thiscall CManualDlg::* )(int)' to 'void (__thiscall CCmdTarget::*
)(UINT)' c:\users\nima\desktop\ffls_scode\manualdlg.cpp 177
Error 8 error C2440: 'static_cast' : cannot convert from 'void
(__thiscall CManualDlg::* )(int)' to 'void (__thiscall CCmdTarget::*
)(UINT)' c:\users\nima\desktop\ffls_scode\manualdlg.cpp 178
The first error is originating from the following line of code, and the rest are similar:
ON_COMMAND_RANGE(IDC_CHECK_PEN, IDC_CHECK_GRID, OnCheckButtons)
ON_COMMAND_RANGE(IDC_REF_L1, IDC_REF_L16, OnCarriagePos)
ON_COMMAND_RANGE(IDC_VALVE_L1, IDC_VALVE_L4, OnValve)
ON_COMMAND_RANGE(IDC_SAMPLE_L_A, IDC_SAMPLE_L_B, OnDetector)
Where (as an instance) OnCheckButtons function is defined in TrendDlg.cpp as follows:
void CTrendDlg::OnCheckButtons(int id)
{
UINT state;
RECT rect = {m_rect.left-60, m_rect.top-10, m_rect.right+40, m_rect.bottom+30};
state = ((CButton*)GetDlgItem(id))->GetState();
if ((state & 0x0003) == 1)
{
switch (id)
{
case IDC_CHECK_PEN:
m_pen = TRUE;
break;
case IDC_CHECK_LINE:
m_line = TRUE;
break;
case IDC_CHECK_BUBBLES:
m_bubble = TRUE;
break;
case IDC_CHECK_GRID:
m_grid = TRUE;
}
}
else
{
switch (id)
{
case IDC_CHECK_PEN:
m_pen = FALSE;
break;
case IDC_CHECK_LINE:
m_line = FALSE;
break;
case IDC_CHECK_BUBBLES:
m_bubble = FALSE;
break;
case IDC_CHECK_GRID:
m_grid = FALSE;
}
}
InvalidateRect(&rect);
}
my message map range is also defined as:
BEGIN_MESSAGE_MAP(CTrendDlg, CDialog)
Why is the compiler trying to cast CTrendDlg and CManualDlg type to CCmdTarget type? is there a change in class structure from VC 6.00 to VS2012?
I appreciate your help.

Your handler should be defined like this:
void CTrendDlg::OnCheckButtons(UINT id)
So basically change int to UINT

See here how this macro ON_COMMAND_RANGE should be used:
1) You need a proper signature, return void and the parameter should be of type UINT
2) Qualify your method with class name:
ON_COMMAND_RANGE(IDC_CHECK_PEN, IDC_CHECK_GRID, &CTrendDlg::OnCheckButtons)
^^^^^^^^^^^^
VS 6.0 is quite old, modern VS versions are more standard conformant.

Related

c++ multithreading - trying to make non-const objects const

I have a c++, sfml program and upon trying to implement multi threading have ran into a problem. First off I have little experience with multi threading. When I go to assign the thread tasks it is throwing 22 new errors all relating to objects being const but the objects are not const. Thanks.
sorry if the title is poorly worded.
here's some code to look over
class NewKey {
public:
sf::Image Img;
sf::Texture Tex;
sf::Sprite Sprite;
sf::Vector2i Velocity;
sf::Vector2i Acceleration;
sf::Vector2i NextPos;
bool isMovingLeft() {
if (Velocity.x < 0)
return true;
else
return false;
}
bool isMovingRight() {
if (Velocity.x > 0)
return true;
else
return false;
}
void velocityCap() {
if (Velocity.x >= 130)
Velocity.x = 130;
if (Velocity.y >= 130)
Velocity.y = 130;
if (Velocity.x <= -130)
Velocity.x = -130;
if (Velocity.y <= -130)
Velocity.y = -130;
}
void loseSpeed(int x) {
if (isMovingLeft()) {
Acceleration.x += x;
}
else if (isMovingRight())
Acceleration.x -= x;;
}
void StepVelocity() {
Velocity += Acceleration;
Acceleration = sf::Vector2i(0, 0);
}
};
void foo() {
NewKey Key;
std::thread thread1;
std::unique_ptr <sf::RenderWindow> window = std::make_unique<sf::RenderWindow>(sf::VideoMode(100, 100, 32), "Main Window", sf::Style::None);
Key.NextPos = Gravity(Key, window, thread1);
thread1.join();
}
sf::Vector2i Gravity(NewKey& Key, std::unique_ptr <sf::RenderWindow>& window, std::thread& thread1) {
int windSpeed = 2;
int dropRate = 10;
thread1 = std::thread([=] {
if (Key.Velocity.x == 1)
Key.loseSpeed(1);
else
Key.loseSpeed(windSpeed);
Key.StepVelocity();
Key.velocityCap();
if (Key.Velocity.y < 10 && Key.Velocity.y > 0) {
Key.Velocity.y = 0;
}
});
sf::Vector2i Result = sf::Vector2i(window->getPosition() + Key.Velocity);
return Result;
}
int main()
{
foo();
}
the errors
Severity Code Description Project File Line Suppression State
Error (active) E1086 the object has type qualifiers that are not compatible with the member function "NewKey::loseSpeed" Error C:\Users\Jacob Krumholz\source\repos\FallingKeys\Error\Error.cpp 61
Error (active) E1086 the object has type qualifiers that are not compatible with the member function "NewKey::loseSpeed" Error C:\Users\Jacob Krumholz\source\repos\FallingKeys\Error\Error.cpp 63
Error (active) E1086 the object has type qualifiers that are not compatible with the member function "NewKey::StepVelocity" Error C:\Users\Jacob Krumholz\source\repos\FallingKeys\Error\Error.cpp 64
Error (active) E1086 the object has type qualifiers that are not compatible with the member function "NewKey::velocityCap" Error C:\Users\Jacob Krumholz\source\repos\FallingKeys\Error\Error.cpp 65
Error (active) E0137 expression must be a modifiable lvalue Error C:\Users\Jacob Krumholz\source\repos\FallingKeys\Error\Error.cpp 67
Error C3861 'Gravity': identifier not found Error C:\Users\Jacob Krumholz\source\repos\FallingKeys\Error\Error.cpp 53
Error C2662 'void NewKey::loseSpeed(int)': cannot convert 'this' pointer from 'const NewKey' to 'NewKey &' Error C:\Users\Jacob Krumholz\source\repos\FallingKeys\Error\Error.cpp 61
Error C2662 'void NewKey::loseSpeed(int)': cannot convert 'this' pointer from 'const NewKey' to 'NewKey &' Error C:\Users\Jacob Krumholz\source\repos\FallingKeys\Error\Error.cpp 63
Error C2662 'void NewKey::StepVelocity(void)': cannot convert 'this' pointer from 'const NewKey' to 'NewKey &' Error C:\Users\Jacob Krumholz\source\repos\FallingKeys\Error\Error.cpp 64
Error C2662 'void NewKey::velocityCap(void)': cannot convert 'this' pointer from 'const NewKey' to 'NewKey &' Error C:\Users\Jacob Krumholz\source\repos\FallingKeys\Error\Error.cpp 65
Error C3490 'y' cannot be modified because it is being accessed through a const object Error C:\Users\Jacob Krumholz\source\repos\FallingKeys\Error\Error.cpp 67

Libtorrent set_settings error

I'm trying to set the session settings but I'm getting an error I don't quite understand, I am able to get the session settings OK and according to the Libtorrent docs I simply pass the session_settings structure to set_settings once I have changed any values.
using namespace libtorrent;
session* Session;
session_status* Session_Status;
session_settings* Session_Settings;
bool Start_Client_Sess()
{
Session = new session;
Session_Status = new session_status;
Session_Settings = new session_settings;
Session->settings( );
std::cout << "upload_rate_limit " << Session_Settings->upload_rate_limit << " \n";
std::cout << "dht_announce_interval " << Session_Settings->dht_announce_interval << " \n";
Session_Settings->upload_rate_limit = 200;
Session_Settings->dht_announce_interval = 1800;
Session->set_settings( Session_Settings ); // error
}
Error:
1>Source\Client_F.cpp(66): error C2664: 'void libtorrent::session::set_settings(const libtorrent::session_settings &)' : cannot convert argument 1 from 'libtorrent::session_settings *' to 'const libtorrent::session_settings &'
1> Reason: cannot convert from 'libtorrent::session_settings *' to 'const libtorrent::session_settings'
1> No constructor could take the source type, or constructor overload resolution was ambiguous
As the error message says, you don't have to pass a pointer to this function.
Session->set_settings( *Session_Settings );

C++/Cx is it possible to call CreateTask().then with a String instead of a IAsyncAction?

Basically I have the next function that I need to call Async:
void waitForFrames(){
CMFTWrapper::IsRunning = true;
while (CMFTWrapper::IsRunning){
result = WaitForSingleObjectEx(CMFTWrapper::FrameEvent, INFINITE, true);
if (result != WAIT_OBJECT_0){
// capture aborted, quit.
}
else if (CMFTWrapper::count > 0){
// copy the bitmap data
}
}
}
Now I tried doing it like this:
create_task(waitForFrames())
.then([this](task<void> frameTask)
{
XTRACE(L"=================================FINISHED WITH FRAME TASK\n");
});
This gives me the next error:
Error 26 error C2228: left of '.then' must have class/struct/union C:\Users\Alin Rosu\Workspace\vidyomobile_windows_phone\Vidyo.DeviceManager\WinRT\DeviceDetection\LmiVideoCapturerWinRTImplementation.cpp 181 1 Vidyo.DeviceManager
Error 24 error C2784: 'Concurrency::task<_Ty> Concurrency::create_task(const Concurrency::task<_Ty> &)' : could not deduce template argument for 'const Concurrency::task<_Ty> &' from 'void' C:\Users\Alin Rosu\Workspace\vidyomobile_windows_phone\Vidyo.DeviceManager\WinRT\DeviceDetection\LmiVideoCapturerWinRTImplementation.cpp 180 1 Vidyo.DeviceManager
Error 25 error C2784: 'Concurrency::task<details::_TaskTypeFromParam<_Ty>::_Type> Concurrency::create_task(_Ty,Concurrency::task_options)' : could not deduce template argument for '_Ty' from 'void' C:\Users\Alin Rosu\Workspace\vidyomobile_windows_phone\Vidyo.DeviceManager\WinRT\DeviceDetection\LmiVideoCapturerWinRTImplementation.cpp 180 1 Vidyo.DeviceManager
Error 45 error LNK1104: cannot open file 'C:\Users\Alin Rosu\Workspace\vidyomobile_windows_phone\Build\ARM\Release\Vidyo.DeviceManager\LmiDeviceManagerWinRT.lib' C:\Users\Alin Rosu\Workspace\vidyomobile_windows_phone\Vidyo.DeviceManager.Test\LINK Vidyo.DeviceManager.Test
Now I tried changing the return value of the function to other stuff from void (Dword, int) but still I get a similar error.
Watching over examples I found on the net, all the functions that use this, that I found return back IAsyncAction.
Example:
create_task(m_pMediaCapture->StartRecordToStorageFileAsync(m_EncodingProfile, m_recordStorageFile))
.then([this](task<void> recordTask)
{
XTRACE(L"=================================will try to get record task\n");
}
How can I do this with my normal function, so that it can run async?
You can pass a lambda directly to the create_task function:
create_task( [](){ /* code here */ } ).
So in your scenario the following should work:
create_task([](){ waitForFrames(); })
.then([this](task<void> frameTask){
XTRACE(L"=================================FINISHED WITH FRAME TASK\n");
});

error C2440: 'type cast' : cannot convert from 'overloaded-function' to

I have a piece of code which worked fine on a previous projet. A part of it was even copied from a working demo project and I don't know how I can have this error on a new project now.
When compiling, I have the following error :
1>d:\visual studio 2012\netsdk_poc\mfc_netsdk2\mfc_netsdk2\netsdkfunctions.cpp(33): error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'fDisConnect'
The code :
class CNetSDKFunctions{
void __stdcall DisConnectBackCallFunc(LONG lLoginID, char *pchDVRIP,
LONG nDVRPort, DWORD dwUser)
{
CNetSDKFunctions* pThis = (CNetSDKFunctions*)dwUser;
if (pThis == NULL)
{
ASSERT( FALSE );
return ;
}
//pThis->ReConnect(lLoginID, pchDVRIP, nDVRPort);
}
BOOL CNetSDKFunctions::InitSDK()
{
long m_PlayerHandle;
H264_DVR_GetLastError();
H264_DVR_Init(NULL, 0);
//Here it is :
BOOL logResult = H264_DVR_Init( (fDisConnect) DisConnectBackCallFunc, (DWORD) this );
....
}
And fDisConnect definition :
typedef void (CALL_METHOD *fDisConnect)(long lLoginID, char *pchDVRIP, long nDVRPort, unsigned long dwUser);

Getting a mysterious type conversion when using the get function from Maya API class MArgList

I am using the MArgList class from the Maya API to retrieve arguments entered in the Maya command line. According to the class reference MArgList::get should be able to take an int or double as its second argument but it seems to be expecting a bool only and so throws a conversion error during compiling. The following is the code section and the errors generated. Any thoughts on what might be causing this would be much appreciated. The code was typed straight out of a tutorial on Maya plugin development, so it is a mystery why it is not working.
const int nPosts = 5;
const double radius = 0.5;
const double height = 5.0;
unsigned index;
index = args.flagIndex( "n", "number" );
if( MArgList::kInvalidArgIndex != index )
args.get( index + 1, nPosts );
unsigned index;
index = args.flagIndex( "r", "radius" );
if( MArgList::kInvalidArgIndex != index )
args.get( index + 1, radius );
unsigned index;
index = args.flagIndex( "h", "height" );
if( MArgList::kInvalidArgIndex != index )
args.get( index + 1, height );
1>Posts1Cmd.cpp(37): error C2664: 'MStatus MArgList::get(unsigned int,bool &) const' : cannot convert parameter 2 from 'const int' to 'bool &'
1>Posts1Cmd.cpp(39): error C2086: 'unsigned int index' : redefinition
1> Posts1Cmd.cpp(34) : see declaration of 'index'
1>Posts1Cmd.cpp(42): error C2664: 'MStatus MArgList::get(unsigned int,bool &) const' : cannot convert parameter 2 from 'const double' to 'bool &'
1>Posts1Cmd.cpp(44): error C2086: 'unsigned int index' : redefinition
1> Posts1Cmd.cpp(34) : see declaration of 'index'
1>Posts1Cmd.cpp(47): error C2664: 'MStatus MArgList::get(unsigned int,bool &) const' : cannot convert parameter 2 from 'const double' to 'bool &'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
If you are going to get new values from the get function, you cannot have the target variables const.
Try
int nPosts = 5;
double radius = 0.5;
double height = 5.0;
Also, you should not declare a new index variable for each call. Just declare it once and reuse it.