Cannot convert 'TCHAR*' to 'const char*'

gdany

I don't know why I get these two errors when I run the code. error: argument of type 'BOOL (Movement::)(HWND__, LPARAM)' does not match 'BOOL ()(HWND__*, LPARAM)' error: argument of type 'BOOL (Movement::)(HWND__, LPARAM)' does not match 'BOOL ()(HWND__*, LPARAM)'

The cpp file is this:

#include "movement.h"
#include <windows.h>
#include <tchar.h>
#include <iostream>

using namespace std;

#pragma comment(lib, "user32.lib")

Movement::Movement()
{
    xLoc = 10;
    yLoc = 50;
    while(true){
            windowHandle = NULL;
            EnumWindows(MyEnumProc, 0);

            MoveWindow(windowHandle, getXLoc(), getYLoc(), 1220, 930, false);
            Sleep(5);
        }
}
BOOL CALLBACK Movement::MyEnumProc(HWND hWnd, LPARAM lParam)
{
    TCHAR title[500];
    ZeroMemory(title, sizeof(title));

    //string strTitle;

    GetWindowText(hWnd, title, sizeof(title)/sizeof(title[0]));

    //_tprintf(_T("Found window: %s\n"), title);

    //strTitle += title; // Convert to std::string
    if(_tcsstr(title, _T("Firefox")))
    {
        windowHandle = hWnd;
        return FALSE;
    }
    return TRUE;
}
int Movement::getXLoc(){
    if(xLoc<70&&yLoc<=30){
        xLoc += 1;
        Sleep(10);
    }else if(yLoc>30){
        xLoc -= 1;
        Sleep(10);
    }
    return xLoc;
}
int Movement::getYLoc(){
    if(yLoc>10&&xLoc<30){
        yLoc -= 1;
        Sleep(10);
    }else if(xLoc>=30&&yLoc<70){
        yLoc += 1;
        Sleep(10);
    }
    return yLoc;
}

This is the Header File:

#ifndef MOVEMENT_H
#define MOVEMENT_H

#include <windows.h>
#include <iostream>

using namespace std;

class Movement
{
public:
    Movement();
protected:
    HWND windowHandle;
    BOOL CALLBACK MyEnumProc(HWND hWnd, LPARAM lParam);
    int xLoc;
    int yLoc;
    int getXLoc();
    int getYLoc();
};

#endif // MOVEMENT_H
JaredPar

The problem here is that EnumWindows is expecting a WNDENUMPROC parameter which is a typedef for

BOOL (*)(HWND, LPARAM);

In your code sample MyEnumProc has the type

BOOL (Movement::*)(HWND, LPARAM);

The difference exists because it is an instance method on Movement. To fix this you need to make MyEnumProc a static method

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Cannot convert 'const char*' to 'WCHAR*' in argument passing

Convert const char** to void*?

cannot convert from 'const char [3]' to 'char *' x100000 (Qt Creator C++ Windows 32)

error: cannot convert 'std::basic_string<char>::iterator ...' to 'const char* for argument '1' ...'

cannot convert 'const char*' to 'LPCWSTR {aka const wchar_t*}'

Error: Cannot convert 'const value_type' to 'char'

How to convert TCHAR to const char?

cannot convert from const char* to const char *&

convert std::string to const tchar*

C2440: '=': cannot convert from 'const char [9]' to 'char*'

error: cannot convert 'const char**' to 'const char (*)[64]'

IntelliSense: argument of type "_TCHAR *" is incompatible with parameter of type "const char *"

Convert const char* to QString

error: cannot convert const string to const char* for argument 1 to size_t strlen(const char*)

cannot convert ‘char**’ to ‘char*’

Cannot convert parameter 1 from char to const char for strcmp

QObject::connection(const QObject*, const char*, const char*, Qt::ConnectionType) "Cannot convert argument 3 from 'fileProcessor' to const QObject *"

C/C++ strcmp cannot convert argument 1 from 'char' to 'const char *'

C++ error: cannot convert ‘std::basic_string<char>’ to ‘const char*’

const(char)* cannot be modified

Cannot convert argument 1 from 'const char [11]' to 'LPCWSTR'

overloading std::exception - what() cannot convert const char*

Cannot convert const char to string constructing string

error C2440: '=': cannot convert from 'const char *' to 'LPCWSTR'

Am I converting properly from "const char *" to "TCHAR*"?

How to convert const std::filesystem::directory_entry to tchar?

error cannot convert 'coll' (type 'std::__cxx11::list<char>') to type 'const char&'

Convert a QString to a const char*

sqlite '=': cannot convert from 'const char [164]' to 'char *'