C, C++ and VC++ Snippets

Posts 46–57 of 57 · Page 4 of 4
Quote Originally Posted by Frought View Post
Snippet Name : AeriaAVA
Key Words : CIN , COUT xD
Code:
#include <iostream>
#include <string>
using namespace std;

class MPGH{
public:
    string y;
    void Name(string y){
    myname = y;
    }
    string Set(){
        return myname;
    }
private:
    string myname;
};

int main()
{
MPGH Ahmed;
Ahmed.Name("AeriaAVA");
cout << Ahmed.Set() << endl;
system("PAUSE");
return 0;
}
it'd be better if you used get and set functions. Also, why is the set function getting ?
Even better, use a using declaration instead of a using directive (at function scope). get/set methods are pointless if they are literally just assignments (might as well make the class member public because it is public in all but name).
Quote Originally Posted by Fovea View Post
Even better, use a using declaration instead of a using directive (at function scope). get/set methods are pointless if they are literally just assignments (might as well make the class member public because it is public in all but name).
Tell my idiotic university professors that :3. Spent first year of Uni having to comply with their bollocks checkstyle which basically said NO PUBLIC VARIABLES and also that EVERY METHOD must be javadoc'd. So you'd end up with ridiculous classes like (note: Java):

Code:
class Foo
{
    private string Name;
    private int Id;
    private double Bar;
    ....


    /**
     * Get the name of this class instance
     * @ return string the name of this class
    **/
    public string GetName()
    {
        return this.Name;
    }
    
    /**
     * Get the identifying number of this class instance
     * @ return int id of this class instance
    **/
    public int GetId()
    {
        return this.Id;
    }

    /**
     * Get the value of Bar for this class instance
     * @ return double value of Bar
    **/
    public double GetBar()
    {
        return this.Bar;
    }
  
    /**
     * Set the name of this class instance
     * @ param newName the new name for this class instance
    **/
    public void SetName(string newName)
    {
        this.Name = newName;
    }

    /**
     * Set the id of this class instance
     * @ param newId the new Idfor this class instance
    **/
    public void SetId(int newId)
    {
        this.Id = newId;
    }

    /**
     * Set the bar value of this class instance
     * @ param newBar the new Bar for this class instance
    **/
    public void SetBar(double newBar)
    {
        this.Bar = newBar
    }
       
}
It's enough to make you want to slit your wrists.
Quote Originally Posted by [implicit] View Post
For when type safety isn't important, such as using a function definition to allow you to pass any parameters, error check depending on other characteristics. It's very dependant on the situation, normally va-args are bad.
Code:
struct foo {
const char* name;
void (*fn)(...);
};
Also, I guess I have to post a snippet, strcmp with length param.
Code:
bool strcmp(char* str1, char* str2, uint length) {
	for(uint i = 0; i < length; ++i) {
		if(*str1++ != *str2++)
			return false;
	}
	return true;
}
Also AeriaAvA, instead of declaring using namespace std on a global scope, it's okay if you put it into local scopes such as your main function or your class.
Why , It will help me?


---------- Post added at 03:26 AM ---------- Previous post was at 03:25 AM ----------

Quote Originally Posted by Auxilium View Post


it'd be better if you used get and set functions. Also, why is the set function getting ?
I'm just at the basics of C++ when i go advanced i will make that
Quote Originally Posted by Auxilium View Post
Also, why is the set function getting ?
I thought the same things... like.. wtf :S
DLL in open Form Application => Borland C++
Tüm herkese selamlar

Code:
#include "Unit1.h"
#include <vcl.h>
#include <windows.h>
#pragma hdrstop
#pragma argsused
void FormApp()
{
Application->Initialize();
Application->Title = "MPGH";
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved)
{
if (fwdreason == DLL_PROCESS_ATTACH)
{
CreateThread(NULL,NULL, (LPTHREAD_START_ROUTINE)FormApp, NULL, NULL, NULL);
}
else if (fwdreason == DLL_PROCESS_DETACH)
{
ExitProcess(0);
}
return true;
}
Embarcadero C++ => Form Applicaton in DLL OPEN bla bla bla/little speak english...
C++ in ASM REGİSTERS
read and write for very important,necessary...

Code:
DWORD RDWORD(DWORD paddy);
void MDWORD(DWORD paddy, DWORD pval);
Code:
DWORD RDWORD(DWORD paddy){
    DWORD retval;
    __asm {
        mov ebx,[paddy]
        xor eax,eax
        mov eax,DWORD PTR DS:[ebx]
        mov retval,eax
    }
    return retval;
}

void MDWORD(DWORD paddy, DWORD pval){
    __asm {
        mov ebx,paddy
        xor eax,eax
        mov eax,pval
        mov DWORD PTR DS:[ebx],eax
    }
}
Sample game code;
DWORD ADDR_CHARB = RDWORD(KO_CHARB); read 4 bit KO_CHARB = Pointer...
Quote Originally Posted by Akar View Post
read and write for very important,necessary...

Code:
DWORD RDWORD(DWORD paddy);
void MDWORD(DWORD paddy, DWORD pval);
Code:
DWORD RDWORD(DWORD paddy){
    DWORD retval;
    __asm {
        mov ebx,[paddy]
        xor eax,eax
        mov eax,DWORD PTR DS:[ebx]
        mov retval,eax
    }
    return retval;
}

void MDWORD(DWORD paddy, DWORD pval){
    __asm {
        mov ebx,paddy
        xor eax,eax
        mov eax,pval
        mov DWORD PTR DS:[ebx],eax
    }
}
Sample game code;
DWORD ADDR_CHARB = RDWORD(KO_CHARB); read 4 bit KO_CHARB = Pointer...
And you need assembly for this....why?
Nice snippet. One thing I'd point out is that using inline assembly ties this to 32-bit MSVC. For newer projects I'd generally prefer standard C++ pointer access or compiler intrinsics where possible. Still a clean example for legacy code and game memory work.
I could be rusty with my knowledge of assembly but isn't this:

Code:
DWORD RDWORD(DWORD paddy){
    DWORD retval;
    __asm {
        mov ebx,[paddy]
        xor eax,eax
        mov eax,DWORD PTR DS:[ebx]
        mov retval,eax
    }
    return retval;
}
the same as:

Code:
DWORD RDWORD(DWORD* paddy)
{
     return *paddy;
}

?
Quote Originally Posted by Void View Post
I could be rusty with my knowledge of assembly but isn't this:

Code:
DWORD RDWORD(DWORD paddy){
    DWORD retval;
    __asm {
        mov ebx,[paddy]
        xor eax,eax
        mov eax,DWORD PTR DS:[ebx]
        mov retval,eax
    }
    return retval;
}
the same as:

Code:
DWORD RDWORD(DWORD* paddy)
{
     return *paddy;
}

?

If mine isn't rusty either, then yes, yes it is. Well done you've successfully added function call overhead to a simple dereferencing operation!
makes your dll smaller:
Code:
#pragma optimize("gsy", on)
Posts 46–57 of 57 · Page 4 of 4

Post a Reply

Similar Threads

Tags for this Thread

Need help?