error C2039:string_view

Pages: 12
hello all,

how can fixed this error

error C2039: 'string_view' : is not a member of 'std'

i use VS 2010

All solutions set to "/std:c++17" in language standard

where is language standard in VS2010

Maybe this is a stupid question but are you sure VS2010 supports C++17?

I'm asking because VS2010 sounds like it's from the year 2010,
and C++17 is the 2017 version of the C++ standard.
omg , thanks for reply
Is there an alternative to std::string_view ?
Maybe you could try boost::string_view.
erorr , C2653: 'boost' : is not a class or namespace
Boost is a 3rd party library. You download the Boost libraries, compile them and set your project's directory lookup to include the Boost libraries.

https://www.boost.org/

I sure haven't a clue how to get Boost working with VS 2010, that is an antique.
Note that std::string_view is mostly used as an "optimization" to avoid copying characters unnecessarily. If string handling is not a performance critical part of your program you can probably just use std::string instead without problem.
Why not just upgrade to the latest VS2022 compiler? The community version is free.

https://visualstudio.microsoft.com/vs/
thanks so much George P , i'll dawnload it.

thanks for reply Peter87 ,
I want to use this class in my project, is it possible to edit?

class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once
#include <Windows.h>
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <sstream>
#include <stdint.h>

//#include <chrono>

class Memory
{
public:
	Memory()
	{
		dwModuleBase = (DWORD)GetModuleHandle(NULL);
		if (dwModuleBase == 0x00)
		{
			//logger.log_windows_error("Memory::GetModuleHandle failed");
		}
	}

	template <typename T>
	inline T Read(LPVOID lpAddress) const
	{
		return *(T*)lpAddress;
	}

	template<typename T, bool EnableVirtual = true>
	inline void Write(LPVOID lpAddress, T _tValue) const
	{
		if (EnableVirtual) {
			DWORD dwOldProtect{};
			VirtualProtect(lpAddress, sizeof(T), PAGE_EXECUTE_READWRITE, &dwOldProtect);
			*(T*)lpAddress = _tValue;
			VirtualProtect(lpAddress, sizeof(T), dwOldProtect, &dwOldProtect);
		}
		else
		{
			*(T*)lpAddress = _tValue;
		}
	}


	// NOTE:
	// THE MASK MUST BEGIN WITH AN X IT CAN'T BEGIN WITH A WILDCARD.
	LPVOID AOBScan(LPVOID lpStartAddress, const std::pair<std::vector<uint8_t>, std::string_view>& pair, size_t dwScanSize = 0x1000 )
	{
		//boost::string_view
		const std::vector<uint8_t>& bytes = pair.first;
		std::string_view mask = pair.second;
		auto dwAddressToRead = reinterpret_cast<DWORD>(lpStartAddress);
		LPVOID lpPossibleHit = 0x00;
			
		size_t i{};
		while (i < dwScanSize) {

			if (Read<uint8_t>(reinterpret_cast<LPVOID>((DWORD)lpStartAddress + i)) == bytes[0]) {

				// FOUND A POSSIBLE HIT.
				lpPossibleHit = reinterpret_cast<LPVOID>((DWORD)lpStartAddress + i);
			
				
				for (size_t j{ 1 }; j < bytes.size(); j++) {
			
					if (mask[j] == '?') continue;
					if (Read<uint8_t>(reinterpret_cast<LPVOID>((DWORD)lpPossibleHit + j)) != bytes[j])
					{
						lpPossibleHit = 0x00;
						break;
					}

				}

				if (lpPossibleHit != 0x00) return lpPossibleHit;

			}

			
			++i;
		}

		return 0x00;

	}

	
};


errors:
1
2
3
4
5
6
7
8
9
10
11
12
13
 error C4519: default template arguments are only allowed on a class template
 error C2039: 'string_view' : is not a member of 'std'
 error C2065: 'string_view' : undeclared identifier
 error C2065: 'dwModuleBase' : undeclared identifier
 error C2065: 'dwModuleBase' : undeclared identifier
 error C2039: 'string_view' : is not a member of 'std'
 error C2065: 'string_view' : undeclared identifier
 error C2146: syntax error : missing ';' before identifier 'mask'
 error C2065: 'mask' : undeclared identifier
 error C2601: 'i' : local function definitions are illegal
 error C2065: 'i' : undeclared identifier
 error C2065: 'dwScanSize' : undeclared identifier
 fatal error C1903: unable to recover from previous error(s); stopping compilation


thanks for replay seeplus .
It is not my computer and its system is 32 bit and this computer is very weak
There are newer compilers/IDEs available that can do Win32 API and C++ console mode coding with a newer C++ standard, and can work on a 32-bit machine. Code::Blocks is one.

https://www.codeblocks.org/

Visual Studio 2019 Community (Free) Edition is still available and supported. Check the system requirements:

https://docs.microsoft.com/en-us/visualstudio/releases/2019/system-requirements
thanks for answer George P,
i install codeblocks 20.03 ,
i select "std:c++17" in language standard ,The error was resolved, but new errors


1
2
3
4
5
6
7
8
9
10
11
12
13
14
main.cpp: In function 'void ourFunct()':
main.cpp:47:10: error: expected '(' before '{' token
     __asm{
          ^
          (
main.cpp:49:1: error: 'mov' was not declared in this scope
 mov esi,ecx
 ^~~
main.cpp: In function 'DWORD MainThread(LPVOID)':
main.cpp:373:30: error: invalid conversion from 'void (*)()' to 'void*' [-fpermissive]
     Hook((void*)hookAddress, ourFunct, hookLength);
                              ^~~~~~~~
main.cpp:12:33: note:   initializing argument 2 of 'bool Hook(void*, void*, int)'
 bool Hook(void * toHook, void * ourFunct, int len)



---------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
 #include <Windows.h>
#include <iostream>
#include <string>
#include <TCHAR.H>
#include "main.h"

using namespace std;


DWORD jmpBackAddy;
 DWORD  buffer_ptr;
bool Hook(void * toHook, void * ourFunct, int len)
{
    if (len < 5)
    {
        return false;
    }
    else
    {

    }

    DWORD curProtection;
    VirtualProtect(toHook, len, PAGE_EXECUTE_READWRITE, &curProtection);

    memset(toHook, 0x90, len);

    DWORD relativeAddress = ((DWORD)ourFunct - (DWORD)toHook) - 5;

    *(BYTE*)toHook = 0xE9;
    *(DWORD*)((DWORD)toHook + 1) = relativeAddress; // <-- I DID NOT UNDERSTAND THIS

    DWORD temp;
    VirtualProtect(toHook, len, curProtection, &temp);

    return true;
}
//



//
void __declspec(naked) ourFunct()
{


    __asm{

mov esi,ecx
cmp eax,1000040
je codey
jmp code20


code20:
cmp eax,1001010
je codey
jmp code

codey:
mov eax,0
jmp code


hid:
mov eax,1001010
jmp code
code:
        mov dword ptr ds:[esi],eax
        lea eax,dword ptr ds:[edi+4]
		jmp jmpBackAddy
    }



}

DWORD WINAPI MainThread(LPVOID param)
{
    int hookLength = 7;//5 for jump + 3 remaining

   // DWORD hookAddress = 0x4E9DEA; // it's right

	DWORD hookAddress = 0x4E972C; // it's right
    jmpBackAddy = hookAddress + hookLength;
    Hook((void*)hookAddress, ourFunct, hookLength);


    return 0;
}
BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved) {
	switch (dwReason) {
	case DLL_PROCESS_ATTACH:
		CreateThread(0, 0, MainThread, hModule, 0, 0);
		break;
	}

	return TRUE;
}


Code::Blocks uses a different compiler which has a different syntax for inline assembly.

https://stackoverflow.com/questions/46248230/msvc-inline-asm-to-gcc
Last edited on
omg , i think Code::Blocks is bad , i'll back to VS

Is there in c plus plus similar to string_view' ?

string_views are essentially lightweight but safer char pointers. Probably you can replace it by using a const std::string& reference.
Last edited on
Or write your own version of string_view. It's not that difficult. It's based around 2 pointers - to start and one-past end - and the size. Only read-only operations are allowed.

thanks so much Ganado
i change

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

LPVOID AOBScan(LPVOID lpStartAddress, const std::pair<std::vector<uint8_t>, std::string_view>& pair, size_t dwScanSize = 0x1000 )
	{
		//boost::string_view
		const std::vector<uint8_t>& bytes = pair.first;
		std::string_view mask = pair.second;
		auto dwAddressToRead = reinterpret_cast<DWORD>(lpStartAddress);
		LPVOID lpPossibleHit = 0x00;

		size_t i{};
		while (i < dwScanSize) {

			if (Read<uint8_t>(reinterpret_cast<LPVOID>((DWORD)lpStartAddress + i)) == bytes[0]) {

				// FOUND A POSSIBLE HIT.
				lpPossibleHit = reinterpret_cast<LPVOID>((DWORD)lpStartAddress + i);


				for (size_t j{ 1 }; j < bytes.size(); j++) {

					if (mask[j] == '?') continue;
					if (Read<uint8_t>(reinterpret_cast<LPVOID>((DWORD)lpPossibleHit + j)) != bytes[j])
					{
						lpPossibleHit = 0x00;
						break;
					}

				}

				if (lpPossibleHit != 0x00) return lpPossibleHit;

			}


			++i;
		}

		return 0x00;

	}



to
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
	LPVOID AOBScan(LPVOID lpStartAddress, const std::pair<std::vector<uint8_t>, const std::string>& pair, size_t dwScanSize = 0x1000 )
	{
		//boost::string_view
		const std::vector<uint8_t>& bytes = pair.first;
		const std::string mask = pair.second;
		auto dwAddressToRead = reinterpret_cast<DWORD>(lpStartAddress);
		LPVOID lpPossibleHit = 0x00;
			
		size_t i{};
		while (i < dwScanSize) {

			if (Read<uint8_t>(reinterpret_cast<LPVOID>((DWORD)lpStartAddress + i)) == bytes[0]) {

				// FOUND A POSSIBLE HIT.
				lpPossibleHit = reinterpret_cast<LPVOID>((DWORD)lpStartAddress + i);
			
				
				for (size_t j{ 1 }; j < bytes.size(); j++) {
			
					if (mask[j] == '?') continue;
					if (Read<uint8_t>(reinterpret_cast<LPVOID>((DWORD)lpPossibleHit + j)) != bytes[j])
					{
						lpPossibleHit = 0x00;
						break;
					}

				}

				if (lpPossibleHit != 0x00) return lpPossibleHit;

			}

			
			++i;
		}

		return 0x00;

	}


i got error here

size_t i{};
error C2601: 'i' : local function definitions are illegal
vs 2010

Last edited on
thanks for reply seeplus,

Please can give me example , Because I'm a beginner



Pages: 12