|
Joined: Aug 2005
Posts: 128
Vogon poet
|
OP
Vogon poet
Joined: Aug 2005
Posts: 128 |
Hi, I want to start making dlls, I know some C, I used this:
#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'
|
|
|
|
Joined: Feb 2004
Posts: 2,013
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,013 |
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.
|
|
|
|
Joined: Jan 2003
Posts: 247
Fjord artisan
|
Fjord artisan
Joined: Jan 2003
Posts: 247 |
If you have any questions about DLLs you can contact me or posts questions here. I'll be glad to answer them for you.
|
|
|
|
Joined: Aug 2005
Posts: 128
Vogon poet
|
OP
Vogon poet
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
|
|
|
|
Joined: Aug 2005
Posts: 128
Vogon poet
|
OP
Vogon poet
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:
#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:
LIBRARY dll
EXPORTS
ret = _ret@24
I tried to use the c++ code from nLINKn, but was useless.  . Any C manual or at least some help ? EDIT: Forgot to say, I compile the file like that: 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.
|
|
|
|
Joined: Oct 2003
Posts: 3,641
Hoopy frood
|
Hoopy frood
Joined: Oct 2003
Posts: 3,641 |
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
|
|
|
|
Joined: Aug 2005
Posts: 128
Vogon poet
|
OP
Vogon poet
Joined: Aug 2005
Posts: 128 |
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:
/* 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:
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:
#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:
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:
; 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: * $dll: no such routine 'ret'
I also tried adding the ret function in the definition file like that: But still not working. This starts annoying me. Any ideeas what can I do ?
|
|
|
|
Joined: Aug 2005
Posts: 128
Vogon poet
|
OP
Vogon poet
Joined: Aug 2005
Posts: 128 |
BUZZ!!! Anyone can help me ?
|
|
|
|
Joined: Dec 2002
Posts: 3,534
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,534 |
Please don't be impatient, if someone can help you they'll reply..  -Andy
|
|
|
|
Joined: Aug 2005
Posts: 128
Vogon poet
|
OP
Vogon poet
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 
|
|
|
|
buster2007
|
buster2007
|
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.comthank you.
|
|
|
|
Joined: Feb 2004
Posts: 2,013
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,013 |
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.
|
|
|
|
buster2007
|
buster2007
|
k.. thanks, i found what i needed
|
|
|
|
|