A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

[Problem] Can't seem to get this conversion working! [C++]

1k views · started by Chris ·
#1
[Problem] Can't seem to get this conversion working! [C++]
So what I had before was this;

int WINAPI __stdcall Func1();
int WINAPI __stdcall Func2();
int WINAPI __stdcall Func3();


And it was called like so;

*(PDWORD)&Func_1= Something((DWORD)GetProcAddress(GetModuleHandleA("somedll.dll"), "function"), (DWORD)Func1, (DWORD)SomeFunc1);
*(PDWORD)&Func_2= Something((DWORD)GetProcAddress(GetModuleHandleA("somedll.dll"), "function"), (DWORD)Func2, (DWORD)SomeFunc2);
*(PDWORD)&Func_3= Something((DWORD)GetProcAddress(GetModuleHandleA("somedll.dll"), "function"), (DWORD)Func3, (DWORD)SomeFunc3);


This all worked fine and dandy until I added it into a class, now when I run it I get this error;

error C2440: 'type cast' : cannot convert from 'int (__stdcall MyClass::* )()' to 'DWORD'


I am adding them to the class header like so;

class MyClass
{
protected:
private:
public:
int WINAPI __stdcall Func1();
int WINAPI __stdcall Func2();
int WINAPI __stdcall Func3(;
};


Does anyone know what's wrong?
#2
Did you solve this? Using DLLs can be tricky some times. It's pretty obvious it's having problems casting from int to DWORD. Maybe searching in google could help, or post an example DLL and code that gives the error.
#3
Riddle wrote:
Did you solve this? Using DLLs can be tricky some times. It's pretty obvious it's having problems casting from int to DWORD. Maybe searching in google could help, or post an example DLL and code that gives the error.


I actually ended up figuring this out after studying C++ much more throughly. I was attempting to build a packet editor using a C reference (meaning the code I was looking at was in C) and it only very vaguely did what I needed, so I was really poking around in the dark. The issue was this;

i was calling the pointer of the other function (Func1) into the new function function (Something) (aka The pointer for the function) but because of the fact that the function was part of the same class it actually ends up calling the pointer for the function this->Func1 which returns the current classes pointer and the offset of the function which does not lead to the actual pointer of the function, causing problems when it attempts to recast. I am pretty sure this was the issue, I believe I ended up making a few class variables public and removing the functions from the actual class.