Jump to content

Math.dll


layer
 Share

Recommended Posts

hey folks!!! i made my first Dll which can Divide, Multiply, Subtract, and Add! o:) here ya go..

and heres the test thingy!:

$add= DllCall ("Math.dll", "int", "Add", "int", 1, "int", 2)
MsgBox (4096, "Testing", $add[0])
$multiply= DllCall ("Math.dll", "int", "Multiply", "int",  3, "int", 4)
MsgBox (4096, "Testing", $multiply[0])
$divide= DllCall ("Math.dll", "int", "Divide", "int", 10, "int", 2)
MsgBox (4096, "Testing", $divide[0])
$subtract= DllCall ("Math.dll", "int", "Subtract", "int", 14, "int", 7)
MsgBox (4096, "Testing", $subtract[0])

make sure the Math.dll is in the same dir as the script (i think, im not sure if there is a specific location..)

EDIT if ya want the source, just say so :):lmao:

Edited by layer
FootbaG
Link to comment
Share on other sites

I think we all want the source, shouldn't be too big to post.

How you got this to 25k is beyond me, though... :lmao:

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

idk, is that big or small? im not to familiar with whats big and whats not :lmao: anyway, heres teh source, :)

DLL.H

#ifndef _DLL_H_
#define _DLL_H_

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */


class DLLIMPORT DllClass
{
  public:
    DllClass();
    virtual ~DllClass(void);

  private:

};


#endif /* _DLL_H_ */

DLLMAIN.CPP

/* Replace "dll.h" with the name of your header */
#include "dll.h"
#include <windows.h>

DllClass::DllClass()
{

}


DllClass::~DllClass ()
{

}


BOOL APIENTRY DllMain (HINSTANCE hInst   /* Library instance handle. */ ,
                       DWORD reason     /* Reason this function is being called. */ ,
                       LPVOID reserved   /* Not used. */ )
{
    switch (reason)
    {
      case DLL_PROCESS_ATTACH:
        break;

      case DLL_PROCESS_DETACH:
        break;

      case DLL_THREAD_ATTACH:
        break;

      case DLL_THREAD_DETACH:
        break;
    }

    /* Returns TRUE on success, FALSE on failure */
    return TRUE;
}

extern "C"__declspec(dllexport) int Add (int a, int b)
{
       return(a + b);
}

extern "C"__declspec(dllexport) int Multiply (int a, int b)
{
       return(a * b);
}

extern "C"__declspec(dllexport) int Divide (int a, int b)
{
       return(a / b);
}

extern "C"__declspec(dllexport) int Subtract (int a, int b)
{
       return(a - b);
}

idk, i really dont know any functions in C++, but i know some operators, kind of sort of not really? o:)

FootbaG
Link to comment
Share on other sites

Seems very big to me, look at Larry's tcp DLL. It's like 5 kB?

I made a simple MsgBox thing, 25 kB... we're including too much crap I think :lmao:

EDIT:

I shaved of 12kB by excluding the header.

Simply this now:

#include <windows.h>
extern "C" __declspec(dllexport) int Hello();

int Hello(){
    MessageBox( NULL, "Hello world!", NULL, MB_OK ); 
    return 1;            
}
Edited by Insolence
"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

seems like excluding the header "dll.h" gives me a million errors o:) hmmm... :lmao: got too much on my mind to think right now...

EDIT: btw, neat dll you got there, i was trying to create a messagebox dll :) youve answered it, thanks :)

Edited by layer
FootbaG
Link to comment
Share on other sites

No problem :lmao:

I don't see how you get errors. Make sure you stop trying to include it in the header, and you get rid of all the DLL events.

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Ouch Valik, ouch.

Maybe I could show you a thing or two about something? Do you know _everything_ about _everything_?

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

The ~25K DLL size is probably coming from one of a couple of things, the first is that your DLLs are being built with debugging symbols inside. A debugger can use the symbols to show you what line the execution is at when you're debugging so you can check variable values, etc. Without the debug information your final binary will generally be manifold times smaller, but you'll only see assembly code when you go to debug it.

Another factor may be including the windows.h header file. If you try to use a function in C++ that's not in the same module (C++ file) that you're working in, the compiler will throw an error because it doesn't know WTF you're talking about. Header files are used as a place to put a declaration of a function that just has the name and how many and what kind of parameters it takes; by including a header you're telling the compiler "Chill, take for granted that there's a function with this name that's blueprinted elsewhere, I'll give you a file or library for it at link time."

Having said that, windows.h has got, you guessed it, declarations (actually it itself #includes other files) for every effing thing that someone thought that you might need for programming for MS Windows. So, even though you just want a function like MessageBox() you're also getting the declarations for printing, NT services, OLE, etc. functionality that you care not a whit about...

Depending on the pre-defined function that you're using, you can sometimes find the header file that contains its actual declaration and just include that rather than the entire mess, but headers include other headers for things that they require, so it can get tedious whittling down to just the things you need...

Generally a DLL will have a number of functions inside so that the final, optimized size is big enough that 20K or so in size isn't that much difference.

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Link to comment
Share on other sites

Thanks Dave... :lmao:

I didn't know once you included something like windows.h, it included a bunch of other crap.

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

well, you know what, i dont care if the blind leads the blind cause im learning a lot more out of what Insolence told me and DaveF rather then someone just saying oh here, put this in your IDE and compile it.. and DaveF ill take that into consoderation :lmao: thanks a bunch and LazyCat has sent me some info too, which im going to check out in a bit

FootbaG
Link to comment
Share on other sites

DaveF, what you don't mention, though, is that in a Release build, any even remotely half-decent compiler will optimize out unused stuff so its a waste of time figuring out the exact header. The real size in that DLL is from all the useless CRT startup code around the entry point.

I don't see how you get errors. Make sure you stop trying to include it in the header, and you get rid of all the DLL events.

So you don't see that ignorning the header will cause an error when the compiler finds the definition for a class constructor/destructor but no declaration? The class doesn't even need to be there, it's leftover wizard generated code. And the events in DllMain() are trivial as they are just #define's so they can stay or go, doesn't really matter. The part that needs to go is the entire DllMain(), but just deleting it won't make it go away as the compiler will generate a DllMain() for you.
Link to comment
Share on other sites

well, i have to owe it all to lazycat! while you guys were chattering back and forth :) LazyCat was helping me with this size problem, now it's only 11.5KB :) all with the keystroke of "-s"... thanks LazyCat! :lmao:

heres the new Dll o:)

FootbaG
Link to comment
Share on other sites

11.5? Thats nice but with a little tweaking, I can get 2,560 bytes before UPX...

Suggestions: Worry about how code works, not how to reduce size, or if you're going to worry about reduced size, learn all the compiler/linker tricks.

Link to comment
Share on other sites

yea, thanks for the advice :lmao: i wasnt really interested in how big the Dll size was as you can see above (Is 25K big? o:)) as long as it gets the job done, i cant complain... besides, i still have 3 quarters left on my hard drive and i used to have 1 quarter, i just deleted a whole bucn of stuff i didnt need.. thanks!

FootbaG
Link to comment
Share on other sites

So you don't see that ignorning the header will cause an error when the compiler finds the definition for a class constructor/destructor but no declaration?  The class doesn't even need to be there, it's leftover wizard generated code.  And the events in DllMain() are trivial as they are just #define's so they can stay or go, doesn't really matter.  The part that needs to go is the entire DllMain(), but just deleting it won't make it go away as the compiler will generate a DllMain() for you.

<{POST_SNAPBACK}>

I don't get it?

This is my code, I got rid of the header and everything generated by Dev C++:

#include <windows.h>
extern "C" __declspec(dllexport) int Hello();

int Hello(){
    MessageBox( NULL, "Hello world!", NULL, MB_OK ); 
    return 1;            
}

Was that all addressed to me?

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...