Error C2440

Jul 22, 2009 at 10:09am
Alright so I'm getting these errors upon compiling... any solution?


c:\documents and settings\cory\my documents\visual studio 2008\projects\test v1\test v1\testv1.cpp(19) : error C2440: 'initializing' : cannot convert from 'int' to 'const DamagePacketFp'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\cory\my documents\visual studio 2008\projects\test v1\test v1\testv1.cpp(20) : error C2440: 'initializing' : cannot convert from 'int' to 'const DWORD *'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\cory\my documents\visual studio 2008\projects\test v1\test v1\testv1.cpp(21) : error C2440: 'initializing' : cannot convert from 'int' to 'const BYTE **'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast






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
#include <windows.h>

#define US_VERSION

#ifndef US_VERSION // JP version
#define DMG_PACKET_PROC 0x45FCC0
#define MONSTER_LIST1 0x8E96F0
#define MONSTER_LIST2 0x9D80E0
#define MONSTER_HP_OFFSET 0xAD64
#else // US version
#define DMG_PACKET_PROC 0x459620
#define MONSTER_LIST1 0x943C48
#define MONSTER_LIST2 0xA327C8
#define MONSTER_HP_OFFSET 0xAD6C
#endif


typedef int (__cdecl * DamagePacketFp)(int, int, int, int, int, int, int);
const DamagePacketFp meleeDamage = DMG_PACKET_PROC;
const DWORD* monsterList1 = MONSTER_LIST1;
const BYTE** monsterList2 = MONSTER_LIST2;

BOOL kill = FALSE;

DWORD CALLBACK ThreadProc(LPVOID lpParam)
{
  DWORD mobID;

  while (1) {
	Sleep(100);
	if (!kill)
	  continue;

	for (mobID = 0; mobID < 0x1F4; mobID++) {
	  if (monsterList1[mobID] == 0)
		continue;

	  if (*(DWORD*)(monsterList2[mobID]+MONSTER_HP_OFFSET) > 0) {
		meleeDamage(1, 1, 1, 0, 0, mobID, 0);
		break;
	  }
	}
  }

  return 1;
}

DWORD CALLBACK HotkeyProc(LPVOID lpParam)
{
  while (1) {
	Sleep(300);
	if (GetAsyncKeyState(VK_F5))
	  kill = !kill;
  }

  return 1;
}

BOOL CALLBACK _DllMainCRTStartup(HINSTANCE hInst, DWORD fdwReason, LPVOID lpvReserved)
{
  if (fdwReason == DLL_PROCESS_ATTACH) {
	if (!CreateThread(NULL, 0, &ThreadProc, NULL, 0, NULL))
	  return FALSE;

	if (!CreateThread(NULL, 0, &HotkeyProc, NULL, 0, NULL))
	  return FALSE;
  }

  return TRUE;
}
Jul 22, 2009 at 5:45pm
Help anyone?
Jul 22, 2009 at 6:17pm
1
2
3
const DamagePacketFp meleeDamage = DMG_PACKET_PROC;
const DWORD* monsterList1 = MONSTER_LIST1;
const BYTE** monsterList2 = MONSTER_LIST2;


You can't do this. DMG_PACKET_PROC, MONSTER_LIST1, and MONSTER_LIST2 are all defined as integers. You cannot cast them to various types of pointers like this.

I don't know what you're trying to do, but whatever it is you're going about it the wrong way.
Jul 22, 2009 at 9:02pm
So you don't have any helping words on this?

I tried used reinterpret_cast and static_cast, both turned up no positive results.
Jul 22, 2009 at 9:16pm
Using c style casts:
1
2
3
4
typedef int (__cdecl * DamagePacketFp)(int, int, int, int, int, int, int);
const DamagePacketFp meleeDamage = (DamagePacketFp)DMG_PACKET_PROC;
const DWORD* monsterList1 = (DWORD*)MONSTER_LIST1;
const BYTE** monsterList2 =(const BYTE**) MONSTER_LIST2;
Jul 22, 2009 at 11:11pm
Okay that fixed my problem with those 3 lines, however I'm getting a LINK error now:

1>LINK : fatal error LNK1561: entry point must be defined
Jul 23, 2009 at 12:43am
No. No No. No no no no no.

C style casts do not solve the problem, they simply stop the compiler from reporting it. Even if you get this to compile, it will explode when you try to run it.

The problem is what you are trying to do is fundamentally flawed. It's not something you're allowed / supposed to do. You shouldn't be doing it at all.

Whatever you're trying to do, you're going about it in completely the wrong way. I can't give you any more info on how to fix it because I don't know what you're trying to do -- perhaps you could say what it is you're trying to accomplish so that I could show you how to do it.
Jul 23, 2009 at 4:56am
I wasn't saying that casting would solve the "problem "- and to be honest I don't really know
what is the OP is really trying to achieve - only he knows that (maybe he's trying to crack some game or the other).

Topic archived. No new replies allowed.