Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Help] compiling dll
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Mon Apr 28, 2008 6:26 am    Post subject: Reply with quote

Rot1 wrote:
make a .def file and insert:

Code:
LIBRARY <DLL NAME>
EXPORTS
<FUNCTION YOU WISH TO EXPORT>


then, include it in the resource folder (at MSVC++ 2k8)

rebuild sulotion in Release mode

well i did it
i defined the def file in resource.h and then include the resource in the dllmain
now when i import the function i get other error message:
"the specified module could not be found" ?!?! what the hell Shocked

_________________
Stylo
Back to top
View user's profile Send private message
benlue
Moderator
Reputation: 0

Joined: 09 Oct 2006
Posts: 2142

PostPosted: Mon Apr 28, 2008 6:52 am    Post subject: Reply with quote

Not sure whether your problem is the same since it isn't too specific. I've seen different people ask me about this and i tell them to unregister C:\Windows\System32\scrrun.dll and register the COM DLL manually. This might not solve your problem. This helped me when i got that error but i can't assure it will get you your fix.
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Mon Apr 28, 2008 7:15 am    Post subject: Reply with quote

just add an .h files with:

Code:
#ifdef __cplusplus
extern "C" { 
             
#endif

__declspec( dllexport ) void Function();

#ifdef __cplusplus
}
#endif
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Mon Apr 28, 2008 11:08 am    Post subject: Reply with quote

Rot1 wrote:
just add an .h files with:

Code:
#ifdef __cplusplus
extern "C" { 
             
#endif

__declspec( dllexport ) void Function();

#ifdef __cplusplus
}
#endif


huh Shocked
i got another error: "Attempted to read or write protected memory. This is often an indication
that other memory is corrupt" Shocked WTH is all of these errors ?!!?

_________________
Stylo
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Mon Apr 28, 2008 11:23 am    Post subject: Reply with quote

1qaz wrote:
visual studio 2008


From looking at your screenshot too, looks like you have Express edition, which removes a few things including some file types.

As others said, create the .def file using notepad, change the extension from .txt to .def

Then inside Visual Studio while your project is open, goto:

Project -> <ProjectName> Properties

Click the + next to Configuration Properties, then click the + next to Linker. Under the Linker items click on 'Input', then where it says Module Definition File, type in the name of the .def file you made.


Your .DEF file should look like:

Code:
LIBRARY <ProjectName>
EXPORTS
    FunctionName @1
    FunctionName @2


Add as many functions as you need to export, be sure to step the number +1 for the @ number. Also change the <ProjectName> to what ever name your DLL compiles to. For example, if I wanted to export two functions 'Add'' and 'Subtract' and my DLL compiles to math.dll, my .def would look like this:

Code:
LIBRARY math
EXPORTS
   Add @1
   Subtract @2


Hope that helps. Smile

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Mon Apr 28, 2008 11:45 am    Post subject: Reply with quote

1qaz wrote:
Rot1 wrote:
just add an .h files with:

Code:
#ifdef __cplusplus
extern "C" { 
             
#endif

__declspec( dllexport ) void Function();

#ifdef __cplusplus
}
#endif


huh Shocked
i got another error: "Attempted to read or write protected memory. This is often an indication
that other memory is corrupt" Shocked WTH is all of these errors ?!!?


remove the .def file, and change void Function(); to the function you wanna export.
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Mon Apr 28, 2008 12:21 pm    Post subject: Reply with quote

Wiccaan i did exactly what you wrote but i'm still getting the error:
"Attempted to read or write protected memory. This is often an indication
that other memory is corrupt" it says build succeeded but when i tick my checkbox it says that error :s
do i need to #include the .def file in the dllmain by any chance?

btw i'm using the full visual studio 2008 not the express edition Confused

_________________
Stylo
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Mon Apr 28, 2008 12:47 pm    Post subject: Reply with quote

Ok so you say it happens when you click a checkbox. Whats your checkbox code for when it's clicked?
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Mon Apr 28, 2008 1:21 pm    Post subject: Reply with quote

well it coded in c# so:
Code:

IntPtr hwnd = FindWindow(null,<window name>);
IntPtr hdc = GetDC(hwnd);
IntPtr x = <imported function name from my dll>(param1,param2);

that's it :\

_________________
Stylo
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Mon Apr 28, 2008 1:33 pm    Post subject: Reply with quote

Well mind not "blurring" out the function names and params? Those are kind of important to the error at hand. You are attempting to access something that you do not have access to, which is causing the error.

With this being coded in C#, I'm not sure if you have to take extra measures when importing a C++ DLL or not. I don't code in C#.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Mon Apr 28, 2008 10:09 pm    Post subject: Reply with quote

oh sry i haven't thought it's that matter
but the function name is PostMessage
i'm trying to make a dll like PMX that hop over the hook to the function
using the PMX method so relate to the Function as PostMessage2(hwnd,msg,wparam,lparam);

omg i think i forgot something very stupid now it's working without any errors lol i forgot to call some procedure XD
thanks alot for your help <3 you guys Very Happy
btw my function goes like this : __declspec(naked) and not (dllexport)
and there's no error so is that ok?

_________________
Stylo
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Tue Apr 29, 2008 7:55 am    Post subject: Reply with quote

__declspec(naked) is mostly used if it is injected, not called from an outside source.

http://msdn2.microsoft.com/en-us/library/h5w10wxs(VS.80).aspx

I would suggest you don't use it unless you are using it to write code caves and such.

Instead your function should be exported using:

Inside your .h file that defines the function exports:

Code:
#ifdef YOURDLL_EXPORTS
#define YOURDLL_API __declspec(dllexport)
#else
#define YOURDLL_API __declspec(dllimport)
#endif


And your function should defined such as:

Code:
YOURDLL_API void __stdcall YourFunction( param1, param2, param3 );


Inside your .cpp your function should mimic that as well:

Code:
YOURDLL_API void __stdcall YourFunction( param1, param2, param3 );


Then the last step is to go into the project properties:

View -> ProjectName Properties
Click the + next to Configuration Properties
Click the + next to C/C++
Click on Preprocessor.

Inside there you should see a setting Preprocessor definitions. You need to add the name of the define you used in the block inside the .h file to this line to tell the compiler that you wish to export them in this compile:

Our example was:

Code:
#ifdef YOURDLL_EXPORTS


So we would add YOURDLL_EXPORTS to this line to look something like:

Code:
WIN32;NDEBUG;_WINDOWS;_USRDLL;YOURDLL_EXPORTS

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Tue Apr 29, 2008 8:25 am    Post subject: Reply with quote

i have 2 .h files and 3 .cpp files in the project
i think i screw it up a little bit XD.

my dll name is pmx2.dll
my function name is postmessage2.

i wrote in "targetver.h"
Code:

#ifdef pmx2_EXPORTS
#define YOURDLL_API(didnt know what to write here) __declspec(dllexport)
#else
#define YOURDLL_API (didnt know what to write here) __declspec(dllimport)
#endif



now about this line:
Code:

YOURDLL_API void __stdcall YourFunction( param1, param2, param3 );


didnt know where to put it

and the other line after it i wrote in the dllmain.cpp file
but i get a lot of error when i compile the code :S

_________________
Stylo
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Tue Apr 29, 2008 8:30 am    Post subject: Reply with quote

1qaz wrote:
i have 2 .h files and 3 .cpp files in the project
i think i screw it up a little bit XD.

my dll name is pmx2.dll
my function name is postmessage2.

i wrote in "targetver.h"
Code:

#ifdef pmx2_EXPORTS
#define YOURDLL_API(didnt know what to write here) __declspec(dllexport)
#else
#define YOURDLL_API (didnt know what to write here) __declspec(dllimport)
#endif



now about this line:
Code:

YOURDLL_API void __stdcall YourFunction( param1, param2, param3 );


didnt know where to put it

and the other line after it i wrote in the dllmain.cpp file
but i get a lot of error when i compile the code :S


you're still stuck ?

look, delete all .h and .def files and do this.

make sure your .cpp file is compileable

then right click (header folder) -> add new item -> .h (header) file

and there type:

Code:
#ifdef __cplusplus
extern "C" { 
             
#endif

__declspec( dllexport ) X Y; // Make sure it's dllEXPORT!, not import, X = Return value of function (No return value = void), Y = Your function, eg: Function();

#ifdef __cplusplus
}
#endif
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Tue Apr 29, 2008 8:58 am    Post subject: Reply with quote

ok i deleted my .h files and .def file
after that my cpp file was compileable
then i added a new header file and called it myHeader.h
i wrote in it:
Code:

#ifdef __cplusplus
extern "C"

             
#endif

__declspec( dllexport ) bool PostMessage2(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

#ifdef __cplusplus
}
#endif


now when i compile it i get warning message at the bottom
frame pointer register ebp modified by inline assembly code (but i dont think it matter).

now i #include "myHeader.h" in dllmain.cpp
compiled it and succeeded
in my application i imported the function from my dll and when i run it i get
"attempted to read or write protected memory. this is often an indication that other memory is corrupt"

_________________
Stylo
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites