PDA

View Full Version : Simple Dll Compiled From Commandline Unlike what google returns vc++ proj


blabberer
September 16th, 2011, 20:06
Sometimes Google in its infinite wisdom will never get you what you remember you saw earlier in the same Google come what may or use whatever search term you may imagine

so i was searching for this simple dll tutorial which i vividly remember and i couldn't find it

and hence this blog

so you want to create a dll and you want to do it in command line
not using start->program->vs->new->project->name->win32->console->crap>dll>bs->whatever->magic->finish->stdafx.h->pch->build f7->search the whole comp for dll

ok here is how you do it

make a new directory somewhere the dir i created is named NOFIXED

add these files to the directory

Code:


NOFIXED:\>cd NOFIXED

NOFIXED:\>dir /b
AddNumbers.bat
AddNumbers.c
AddNumbers.def
AddNumbers.h
CallAddNum.c
NOFIXED:\>


AddNumbers.c is the source code for dll and it contains

Code:

NOFIXED:\>type AddNumbers.c
#include <windows.h>
#include "AddNumbers.h"


BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpReserved ){
switch( fdwReason ){
case DLL_PROCESS_ATTACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}


_declspec (dllexport) ULONG AddNumbers(ULONG a, ULONG b){
return((ULONG)(a+b));
}

NOFIXED:\>


AddNumbers.h is the Header File You Would Need To Link To The Dll when You Create An EXE and it contains

Code:


NOFIXED:\>type AddNumbers.h
#include <windows.h>
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,LPVOID lpReserved );
_declspec (dllexport) ULONG AddNumbers(ULONG a, ULONG b);

NOFIXED:\>


AddNumbers.def is the module definition File that is required to Build a Dll and it contains

Code:


NOFIXED:\>type AddNumbers.def
EXPORTS
AddNumbers
NOFIXED:\>


CallAddNum.c is the source code for the exe that links to the AddNumbers.dll that you are going to Build and Call the function in the dll and it contains

Code:


NOFIXED:\> type CallAddNum.c
#include <stdio.h>
#include "AddNumbers.h"

int main (void){

printf("3 + 5 = %x\n" , AddNumbers(3,5));
return 0;
}
NOFIXED:\>


and finally AddNumbers.Bat contains the command line to build the exe and dll

and it contains the following commands
cl is the compiler
/nologo suppresses copyright message
/c compiles only no linking
/LD tells the compiler to create a dll and not an exe
link is the linker
/dll tells the linker to link the compiled obj code into a dll
def:"AddNumbers.def" is the module def file which creates AddNumbers.Lib And AddNumbers.Exp which you use when you compile any exe to link to the dll

Code:



NOFIXED:\>type AddNumbers.bat
cl /nologo /c /LD AddNumbers.c
link /NOLOGO /dll /def:"AddNumbers.def" AddNumbers.obj
cl /nologo CallAddNum.c AddNumbers.lib
NOFIXED:\>


now open vs2008commandprompt

start -> program -> microsoft visual c++ 2008 Express Edition -> visual studio tools -> visual studio 2008 command prompt

navigate to the present NOFIXED Directory
and run the AddNumbers.bat you should get you dll and exe compiled

Code:


NOFIXED:\>dir /b & AddNumbers.bat & dir /b
AddNumbers.bat
AddNumbers.c
AddNumbers.def
AddNumbers.h
CallAddNum.c

NOFIXED:\>cl /nologo /c /LD AddNumbers.c
AddNumbers.c

NOFIXED:\>link /NOLOGO /dll /def:"AddNumbers.def" AddNumbers.obj
Creating library AddNumbers.lib and object AddNumbers.exp

NOFIXED:\>cl /nologo CallAddNum.c AddNumbers.lib

CallAddNum.c
AddNumbers.bat
AddNumbers.c
AddNumbers.def
AddNumbers.dll
AddNumbers.exp
AddNumbers.h
AddNumbers.lib
AddNumbers.obj
CallAddNum.c
CallAddNum.exe
CallAddNum.obj

NOFIXED:\>


run the exe to check if you have succeeded

Code:


NOFIXED:\>CallAddNum.exe
3 + 5 = 8

NOFIXED:\>



that is all for now

blabberer
April 13th, 2012, 16:02
i see only 283 views for this thread when i see it here but in the actual blog
i see 10000 + views ???
what is the right count ? did 10000 people really look at the simple dll blog iam flattered

Code:


Simple Dll Compiled From Commandline Unlike what google returns vc++ proj Edit Blog Entry
Rate this Entry

* Excellent
* Good
* Average
* Bad
* Terrible
*

0 Comments
by
blabberer

* View Profile
* View Forum Posts
* Private Message
* View Blog Entries
* View Articles
* Send Email

, September 16th, 2011 at 19:21 (10001 Views)

Sometimes Google in its infinite wisdom will never get you what



about 8000 + views for type info blog

are my blogs so great if yes then i should add a few google ads adsense hidden I frames clickjacking / pop ups / pop unders / pop overs to genrate some petty cash

Kayaker
April 13th, 2012, 22:15
Well, it's obvious that your blogs are awesome, to get so many hits

(Or maybe the spiders are awesome..

blabberer
April 14th, 2012, 08:45
Quote:

(Or maybe the spiders are awesome..


wow the spiders must really hate anything windows 98 related then the hit rate there languishes at 2000 odd

jokes apart how does the counter really work (is google analytics or some some sort of backend supporting it ?)

anyway the blog is first hit for this search query (first among 23 million pages that might contain these keywords )

https://www.google.com/search?q=simple%20dll%20command%20line

Kayaker
April 14th, 2012, 15:21
Made me look..

Views are simply updated every time a page is hit (SET views = views + 1), there is no google-analytics code on this site, or anything else I can see that would artificially pull in hits.

I ordered the blogs by Views and the results make me think that it's a combination of good title keywords, plus which articles are currently listed on the main blog page (and which spiders would follow to generate a 'views + 1'), and how long they have been on that page.

http://www.woodmann.com/forum/blog.php

The blog with the greatest number of views (almost 100,000) is the one by ^DAEMON^ - Reading Virtual Memory. I can see those title keywords by themselves generating a lot of non-spider interest. Other top hits (yours was #8) had title keywords such as 'writing tracer', 'hidden callbacks', 'hooking'.

However, many of the other top ones used title keywords that I wouldn't expect to come up readily on google at all, yet they had high view ratings and are also still listed on the main blog page, so presumably they are mostly "spider hits" rather than "real people hits".

Besides, normal spiders which obey the robots.txt rules are prevented from slurping the forum posts themselves (showthread.php, etc.), and are only allowed to "see" the archive listings (which is the main point behind the "Search Engine Friendly Archives" and the Blog pages. So in general the forum post Views are "real", blog post Views are "real + spider" generated.