mIRC Homepage
Posted By: stefys99 My first dll - 14/08/05 01:15 AM
Hi, I want to start making dlls, I know some C, I used this:
Code:
#include <stdio.h>
#include <windows.h>
#include <sys/types.h>

int __stdcall ret(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause)
{
    if (show) sprintf(data,"echo -a Do not hide of me :)");
    sprintf(data,"echo -a %s",data);
    return 2;
    
}

int main (void)
{
    return 0;
}

It's a useless dll, but i have to understand how they work first... I compiled the file as .dll, but i get: * $dll: no such routine 'ret'
Posted By: FiberOPtics Re: My first dll - 14/08/05 01:33 AM
Take a look at this tutorial by Necroman.

You get that error message, most likely because you did not export the ret function, in the definition file.
Posted By: ClickHeRe Re: My first dll - 14/08/05 10:57 AM
If you have any questions about DLLs you can contact me or posts questions here. I'll be glad to answer them for you.
Posted By: stefys99 Re: My first dll - 14/08/05 11:56 AM
I just posted one, and you didn't answer me :P:P

P.S. I'll look at that tutorial
Posted By: stefys99 Re: My first dll - 18/08/05 03:30 PM
Well, I read the manual, but it's for C++ and I have C
That's the source of the dll.dll:
Code:
#define WIN32_LEAN_AND_MEAN 

#include <stdio.h>
#include <windows.h>
#include <string.h>


extern int __stdcall ret(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause)
{
       if (show) sprintf(data,"echo -a Do not hide of me :)");
       else sprintf(data,"echo -a %s",data);
       return 2;
}

int main (void)
{
    return 0;
}

Then the dll.def:
Code:
LIBRARY dll
EXPORTS
ret = _ret@24

I tried to use the c++ code from nLINKn, but was useless. frown. Any C manual or at least some help ?

EDIT: Forgot to say, I compile the file like that:
Quote:

c:\dev-cpp\bin\gcc.exe "C:\Documents and Settings\x\My Documents\dll.c" -o "C:\Documents and Settings\x\My Documents\dll.dll" -g3 -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -g3

Maybe it's compilling it as exe instead of dll ?
Posted By: argv0 Re: My first dll - 21/08/05 12:53 AM
i dont know why you're definint int main() {}

thats not necessary

and yes, to compile a dll you need to tell the compiler to link it differently
Posted By: stefys99 Re: My first dll - 22/08/05 10:39 PM
Quote:
i dont know why you're definint int main() {}

I was getting error when I was trying to compile without main function. That's cos i was compiling it as EXE.

I found a way to make it as dll.
I clicked new project at Dev-C++ and C DLL
It gave me this:
Code:
/* Replace "dll.h" with the name of your header */
#include "dll.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

[color:red]DLLIMPORT void HelloWorld ()
{
    MessageBox (0, "Hello World from DLL!\n", "Hi", MB_ICONINFORMATION);
}[/color]


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;
}


I removed the red lines, and I wrote that instead of them:
Code:
int __stdcall ret(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause)
{
       if (show) sprintf(data,"echo -a Do not hide of me :)");
       else sprintf(data,"echo -a %s",data);
       return 2;
}

This project created 2 files: dllmain.c and dll.h
The dllmain.c was the one I've shown you before.
This is the dll.h:
Code:
#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 */


[color:red]DLLIMPORT void HelloWorld (void);[/color] 


#endif /* _DLL_H_ */


I replaced the red line from here with:
Code:
int __stdcall ret(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause);

I also changed the order of headers from dllmain.c, so dll.h was included last (cos windows.h is needed by dll.h for setting the prototype, cos prototype contains types of variables defined in windows.h)

Compiled with no errors, everything was fine.
I set the project name dll1, so dll1.dll was created, also libdll1.def was created.
The contents of libdll1.def are:
Code:
; dlltool --base-file C:\DOCUME~1\x\LOCALS~1\Temp/cca03464.base --output-exp dll1.exp --dllname dll1.dll --output-def libdll1.def --no-export-all-symbols --add-stdcall-alias --exclude-symbol=DllMainCRTStartup@12 --def C:\DOCUME~1\x\LOCALS~1\Temp/cca03464.def --output-lib libdll1.a
EXPORTS


For some reason the function ret() wasn't added to exports (means he didn't recognize it, means I did something wrong)... Also, I tried using //echo -a : $dll(dll1.dll,ret,just a lil test), but I get the same error:
Quote:

* $dll: no such routine 'ret'

I also tried adding the ret function in the definition file like that:
Code:
ret = _ret@24

But still not working. This starts annoying me. Any ideeas what can I do ?
Posted By: stefys99 Re: My first dll - 24/08/05 08:02 PM
BUZZ!!! Anyone can help me ?
Posted By: SladeKraven Re: My first dll - 25/08/05 02:40 AM
Please don't be impatient, if someone can help you they'll reply.. smile

-Andy
Posted By: stefys99 Re: My first dll - 26/08/05 07:15 PM
Not necessary anymore. Fixed. If someone else is using Dev-C++ for making dlls in C, tell me, I can help smile
Posted By: buster2007 Re: My first dll - 04/09/05 06:55 AM
hi stefy... i'd like to look at the source code of some dlls, just to have a better picture of how functions look like etc.

could you send some to me? some that are more simple and easy to understand ... 2-3 files to help me learn. i know how to compile them so it's no problem.
my address is buster2007@gmail.com

thank you.
Posted By: FiberOPtics Re: My first dll - 04/09/05 02:38 PM
If you go to scripting sites such as for example www.mirc.net and www.mircscripts.org you can download DLLs there and check their source, as people who want to submit DLLs are to include their source with the DLL. The reason for this is that this way the admins of the site can verify that there is no harmful code, and that you can learn from the code to make DLLs yourself.
Posted By: buster2007 Re: My first dll - 05/09/05 05:30 AM
k.. thanks, i found what i needed
© mIRC Discussion Forums