mIRC Home    About    Download    Register    News    Help

Print Thread
#127479 14/08/05 01:15 AM
Joined: Aug 2005
Posts: 128
S
Vogon poet
OP Offline
Vogon poet
S
Joined: Aug 2005
Posts: 128
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'

#127480 14/08/05 01:33 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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.


Gone.
#127481 14/08/05 10:57 AM
Joined: Jan 2003
Posts: 249
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Jan 2003
Posts: 249
If you have any questions about DLLs you can contact me or posts questions here. I'll be glad to answer them for you.

#127482 14/08/05 11:56 AM
Joined: Aug 2005
Posts: 128
S
Vogon poet
OP Offline
Vogon poet
S
Joined: Aug 2005
Posts: 128
I just posted one, and you didn't answer me :P:P

P.S. I'll look at that tutorial

#127483 18/08/05 03:30 PM
Joined: Aug 2005
Posts: 128
S
Vogon poet
OP Offline
Vogon poet
S
Joined: Aug 2005
Posts: 128
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 ?

Last edited by stefys99; 18/08/05 03:35 PM.
#127484 21/08/05 12:53 AM
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
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


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
#127485 22/08/05 10:39 PM
Joined: Aug 2005
Posts: 128
S
Vogon poet
OP Offline
Vogon poet
S
Joined: Aug 2005
Posts: 128
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 ?

#127486 24/08/05 08:02 PM
Joined: Aug 2005
Posts: 128
S
Vogon poet
OP Offline
Vogon poet
S
Joined: Aug 2005
Posts: 128
BUZZ!!! Anyone can help me ?

#127487 25/08/05 02:40 AM
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Please don't be impatient, if someone can help you they'll reply.. smile

-Andy

#127488 26/08/05 07:15 PM
Joined: Aug 2005
Posts: 128
S
Vogon poet
OP Offline
Vogon poet
S
Joined: Aug 2005
Posts: 128
Not necessary anymore. Fixed. If someone else is using Dev-C++ for making dlls in C, tell me, I can help smile

#127489 04/09/05 06:55 AM
Joined: Aug 2005
Posts: 39
B
Ameglian cow
Offline
Ameglian cow
B
Joined: Aug 2005
Posts: 39
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.

#127490 04/09/05 02:38 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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.


Gone.
#127491 05/09/05 05:30 AM
Joined: Aug 2005
Posts: 39
B
Ameglian cow
Offline
Ameglian cow
B
Joined: Aug 2005
Posts: 39
k.. thanks, i found what i needed


Link Copied to Clipboard