Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NEED help creating a dll.

Status
Not open for further replies.

ben146

Programmer
Jan 30, 2003
11
US
Hi all,i am new to programming so bear with me.i want to create a dll for counter-strike.i am using microsoft visual c++ ver.7 . i have the source files and header files for the hook.also three folders that came with it marked engine,common,and misc,i take it these are the source file for the game.my question is do i select new project >win32 then name it.the select dll then empty project to add my own files?if so do i only add the header and source files for the hook?or do i need to add the files in engine ,common ,and misc plus the hook files?if so does it matter what order?if someone could tell me how to do it i would appreciate it.im about ready to pull my hair out.also are there any special settings i need on the compiler to do this?
 
Hi, if your code is all contained within classes the easiest thing to do would be create an "extension" DLL. You go to create a new project and choose the MFC AppWizard (DLL) choice. A dialog should come up asking if you want a regular or extension DLL - choose extension.

Go under the project menu to "add files". Add your headers and source files for the classes to be in the DLL. Then change each class you are exporting in the headers and write this in their just before the class name:

[tt]
class AFX_EXT_CLASS SomeClass
{
.....
};[/tt]

Compile the DLL. It should produce both the DLL file and also a .LIB file in the debug/release folder.

In your application project where you want to use the classes from the DLL you need to copy the headers in the project folder from the DLL folder. That is, the ammended files which have the AFX_EXT_CLASS before each class name.

Go under your project menu to "Settings" and click on the "link" tab. There should be a text field in there called something like "Object/Library Modules" - add the path to the DLL's .LIB file in that text field.
Then, place the actual DLL into the application project folder.

Finally, to use the classes from your new DLL you simply #include the header files and then you can use those DLL classes just like any other classes!

[rockband]
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
That's true, but the only problem is (if I remember correct) that thos extension dll's can ONLY be used by other MFC projects. They cannot be used by any other kind of VC project, or any other language. If that's no problem, it's probably the easiest solution for what you want though.
Greetings,
Rick
 
Thx for the quik reply guys,i appreciate it.i am a little confused qednick on the classes.im not sure what you mean.also so u know.the way these dll's work is they use a loader that u have to compile seperately to load the dll.then from what i gather they hook off of the main program counter strike.also the cheats i have used that these guys made...the dll along with the loader and menu are in a diff directory than the counter strike exe.ther are about fifteen different .cpp pages.like aimbot.cpp,client.cpp apihook.cpp ect.then all the header files to go with.aimbot.h, client.h, apihook.h ect...but then there are the 3 folders i mentioned earlier that are labled engine,common, and misc.that contain even more cpp and header files.wwhat do you think?thx
 
Well, if you don't know what classes are then I guess LazyMe is correct - you shouldn't be using MFC LOL
You should look to create a regular DLL and export the functions you need. You can do this either "implicitly" or "explicity" at run time.
It's a bit more involved than 'extension' DLLs but I answered a similar question here (or maybe in C++: Microsoft forum) about 5-6 weeks ago giving full details on how to create and use them. Scroll back through the threads or click the 'search; tab above to see if you can find it.
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
I found it - it was in C++: Microsoft forum and is

thread207-434734

posted on Xmas day
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
Thx qednick,i found the classes listed inside the header files and changed every instance to class AFX_EXT_CLASS SOMECLASSES.(Thiers 15 header files)now its giving me an error:unexpected end of file found.whe i compile them idavidualy.but when i select project new>win32>dll>empty project and add the source files they compile fine.the only thing is when i go to link them it gives me more errors on unresolved externals.would it help u if i pasted the build log?Build Log ------- Build started: Project: BaseHook, Configuration: Release|Win32 -------

Environment Space ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\M-ike\Application Data
CLIENTNAME=Console
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=MIKE
ComSpec=C:\Windows\system32\cmd.exe
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\M-ike
include=C:\Program Files\Microsoft Visual Studio .NET\Vc7\include;C:\Program Files\Microsoft Visual Studio .NET\Vc7\atlmfc\include;C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\include\prerelease;C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\include;C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\include
lib=C:\Program Files\Microsoft Visual Studio .NET\Vc7\lib;C:\Program Files\Microsoft Visual Studio .NET\Vc7\atlmfc\lib;C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\lib\prerelease;C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\lib;C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\lib
LIBPATH=
LOGONSERVER=\\MIKE
MSDevDir=C:\Program Files\Microsoft Visual Studio\Common\MSDev98
NUMBER_OF_PROCESSORS=1
OS=Windows_NT
Path=C:\Program Files\Microsoft Visual Studio .NET\Vc7\bin;C:\Program Files\Microsoft Visual Studio .NET\Common7\Tools\bin\prerelease;C:\Program Files\Microsoft Visual Studio .NET\Common7\Tools\bin;C:\Program Files\Microsoft Visual Studio .NET\Common7\tools;C:\Program Files\Microsoft Visual Studio .NET\Common7\ide;C:\Program Files\HTML Help Workshop\;C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\bin;C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\Common Files\Adaptec Shared\System
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 15 Model 0 Stepping 10, GenuineIntel
PROCESSOR_LEVEL=15
PROCESSOR_REVISION=000a
ProgramFiles=C:\Program Files
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\DOCUME~1\M-ike\LOCALS~1\Temp
TMP=C:\DOCUME~1\M-ike\LOCALS~1\Temp
USERDOMAIN=MIKE
USERNAME=M-ike
USERPROFILE=C:\Documents and Settings\M-ike
VSCOMNTOOLS="C:\Program Files\Microsoft Visual Studio .NET\Common7\Tools\"
windir=C:\Windows
_ACP_ATLPROV=C:\Program Files\Microsoft Visual Studio .NET\Vc7\bin\ATLPROV.DLL
_ACP_INCLUDE=C:\Program Files\Microsoft Visual Studio .NET\Vc7\include;C:\Program Files\Microsoft Visual Studio .NET\Vc7\atlmfc\include;C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\include\prerelease;C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\include;C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\include
_ACP_LIB=C:\Program Files\Microsoft Visual Studio .NET\Vc7\lib;C:\Program Files\Microsoft Visual Studio .NET\Vc7\atlmfc\lib;C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\lib\prerelease;C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\lib;C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\lib;C:\Program Files\Microsoft Visual Studio .NET\Vc7\include;C:\Program Files\Microsoft Visual Studio .NET\Vc7\atlmfc\include;C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\include\prerelease;C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\include;C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\include
_ACP_PATH=C:\Program Files\Microsoft Visual Studio .NET\Vc7\bin;C:\Program Files\Microsoft Visual Studio .NET\Common7\Tools\bin\prerelease;C:\Program Files\Microsoft Visual Studio .NET\Common7\Tools\bin;C:\Program Files\Microsoft Visual Studio .NET\Common7\tools;C:\Program Files\Microsoft Visual Studio .NET\Common7\ide;C:\Program Files\HTML Help Workshop\;C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\bin;C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\Common Files\Adaptec Shared\System
Command Lines Creating temporary file "C:\DOCUME~1\M-ike\LOCALS~1\Temp\RSP000005.rsp" with contents
[
/O2 /Ob1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "BASEHOOK_EXPORTS" /D "_MBCS" /D "_WINDLL" /GF /FD /EHsc /MT /Gy /YX"stdafx.h" /Fp".\Release/BaseHook.pch" /Fo".\Release/" /Fd".\Release/" /W3 /c /TP
"timehandling.cpp"
"stringfinder.cpp"
"sprites.cpp"
"playeritems.cpp"
"misc\parsemsg.cpp"
"opengl.cpp"
"netlib.cpp"
"menu.cpp"
"mempatcher.cpp"
"interpreter.cpp"
"color.cpp"
"client.cpp"
"calcscreen.cpp"
"bind.cpp"
"attack.cpp"
"apihook.cpp"
"Winamp.cpp"
"WinMain.cpp"
"RedirectFunction.cpp"
"IRC.cpp"
"GPatch.cpp"
]
Creating command line "cl.exe @"C:\DOCUME~1\M-ike\LOCALS~1\Temp\RSP000005.rsp" /nologo"
Creating command line "rc.exe /d "NDEBUG" /l 0x40c /fo".\Release/BaseHook.res" "BaseHook.rc""
Creating temporary file "C:\DOCUME~1\M-ike\LOCALS~1\Temp\RSP000006.rsp" with contents
[
/OUT:".\Release/[R]ed[F]usion.dll" /INCREMENTAL:NO /NOLOGO /DLL /PDB:".\Release/BaseHook.pdb" /IMPLIB:".\Release/BaseHook.lib" /MACHINE:I386 odbc32.lib odbccp32.lib winmm.lib opengl32.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
"Release\BaseHook.res"
"Release\GPatch.obj"
"Release\IRC.obj"
"Release\RedirectFunction.obj"
"Release\WinMain.obj"
"Release\Winamp.obj"
"Release\apihook.obj"
"Release\attack.obj"
"Release\bind.obj"
"Release\calcscreen.obj"
"Release\client.obj"
"Release\color.obj"
"Release\interpreter.obj"
"Release\mempatcher.obj"
"Release\menu.obj"
"Release\netlib.obj"
"Release\opengl.obj"
"Release\parsemsg.obj"
"Release\playeritems.obj"
"Release\sprites.obj"
"Release\stringfinder.obj"
"Release\timehandling.obj"
]
Creating command line "link.exe @"C:\DOCUME~1\M-ike\LOCALS~1\Temp\RSP000006.rsp""
Output Window Compiling...
timehandling.cpp
stringfinder.cpp
sprites.cpp
playeritems.cpp
parsemsg.cpp
opengl.cpp
netlib.cpp
menu.cpp
c:\Documents and Settings\M-ike\Desktop\RF 1.2\dll\menu.h(27) : warning C4018: '>=' : signed/unsigned mismatch
mempatcher.cpp
mempatcher.cpp(364) : warning C4018: '<' : signed/unsigned mismatch
mempatcher.cpp(597) : warning C4018: '<' : signed/unsigned mismatch
mempatcher.cpp(621) : warning C4018: '<' : signed/unsigned mismatch
interpreter.cpp
c:\Documents and Settings\M-ike\Desktop\RF 1.2\dll\interpreter.h(52) : warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data
color.cpp
color.cpp(81) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
color.cpp(82) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
color.cpp(83) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
color.cpp(85) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
color.cpp(86) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
color.cpp(87) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
color.cpp(88) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
color.cpp(141) : warning C4018: '>' : signed/unsigned mismatch
client.cpp
calcscreen.cpp
bind.cpp
attack.cpp
apihook.cpp
Winamp.cpp
WinMain.cpp
RedirectFunction.cpp
IRC.cpp
GPatch.cpp
Compiling resources...
Linking...
Results Build log was saved at &quot;file://c:\Documents and Settings\M-ike\Desktop\RF 1.2\dll\Release\BuildLog.htm&quot;
BaseHook - 0 error(s), 13 warning(s)
I hope this helps.maybe then u can tell me what he did here...thx
 
Most of that may as well be written in Greek! [bugeyed]
When you say you changed all the classes to &quot;AFX_EXT_CLASS SOMECLASSES&quot; you didn't actually put the Words &quot;SomeClass&quot; in there did you? That was meant to be a substitute for your class names. If you look up in the thread you'll see the only thing you should have added was the bit in blue.
Also, you can compile the header files but unless you actually include all the .cpp files in the project it's not going to work.
The warnings about signed/unsigned mismatches and also the conversion from double to float/poss loss of data are worth ignoring for now.
Unresolved externals means that something is still missing and the linker can't find it. The biggest cause of these are missing .lib files from the link.
Perhaps this is the list of missing .lib files:

usion.dll&quot; /INCREMENTAL:NO /NOLOGO /DLL /PDB:&quot;.\Release/BaseHook.pdb&quot; /IMPLIB:&quot;.\Release/BaseHook.lib&quot; /MACHINE:I386 odbc32.lib odbccp32.lib winmm.lib opengl32.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib


If you recall how I told you to add the .lib file for a DLL into an application project (above) by going under &quot;Project->Settings&quot; and clicking on the &quot;Link&quot; tab - these .lib files should be in there.

[hammer]

PS: If you get any more error messages, copy and paste them from VC++'s 'output' window
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
LOL qednick..no i did not put in in as you wrote it.heres what i put:&quot;class AFX_EXT_CLASS Randomaiming&quot;.i did that where ever it called class in the header files.i just did like u said and added the AFX_EXT_CLASS.Im still working on this dll.i have 5 books the size of sears catalogs im flipping through.but thank you for helping.i have to say you have been very helpfull.but i will try to compile them again and i will post the errors so you can see.i think i am trying to build it wrong becuase i am including the header files..ill go back and do what you said.thx again.
 
If you create a regular dll (NOT an extension) like you did win32 dll, you do not need the AFX_EXT_CLASS. This is only used for exporting classes from extension dll's and importing them from client. In your win32 dll you can NOT export classes. You can only export functions from a regular dll. The upside however, is that it can be called by any kind of application (like the ordinary windows dll's).
Greetings,
Rick
 
Thx for replying lazyme.i think what im going to try this morning is just to create a new win32 project then select an empty dll.then add the source files and header files(without the AFX_EXT_CLASS)also i think qednick is right about the missing .lib files.i went into the linker tab and the only thing close to what he said was where i saw additional libraries.it was blank.but when i clicked on it it just brings up a box that i guess i enter the path to the lib.files.but im not sure where they are.i know im a little ahead of myself here,but if i can figure out how to build this dll.once i have that down then i can go back and edit the .cpp and headers to customize the hook.i just wanna make sure i can do that first.im using visual.net ver.7 c++.
 
if you wand yor dll functions to be accessible you will
declare them as
__declspec(dllexport) function declaration(...)

if you want to import a function from dll you will declare it as
__declspec(dllimport) function declaration(...);

if you declare a class you will declare
class __declspec(dllexport) classname{...};

and
class __declspec(dllimport) classname{...}; to import it from dll.
you could make conditional compilling to use the same headers for both:

#if !defined(MY_DLL_IMPLEMENT)
#define dllapi __declspec(dllimport)
#else
#define dllapi __declspec(dllexport)
#endif

and in all .cpp source files for your dll you will put
#define MY_DLL_IMPLEMENT before any #includes.

It is recommended each .dll projects to have a unique name instead of MY_DLL_IMPLEMENT because you can use dll functions inside other dll functions of other dlls.
Ion Filipski
1c.bmp


filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top