| View previous topic :: View next topic |
| Author |
Message |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
|
| Back to top |
|
 |
benlue Moderator
Reputation: 0
Joined: 09 Oct 2006 Posts: 2142
|
Posted: Mon Apr 28, 2008 6:52 am Post subject: |
|
|
| 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 |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Mon Apr 28, 2008 7:15 am Post subject: |
|
|
just add an .h files with:
| Code: | #ifdef __cplusplus
extern "C" {
#endif
__declspec( dllexport ) void Function();
#ifdef __cplusplus
}
#endif |
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Mon Apr 28, 2008 11:23 am Post subject: |
|
|
| 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.
_________________
- Retired. |
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Mon Apr 28, 2008 11:45 am Post subject: |
|
|
| 1qaz wrote: | | Rot1 wrote: | just add an .h files with:
| Code: | #ifdef __cplusplus
extern "C" {
#endif
__declspec( dllexport ) void Function();
#ifdef __cplusplus
}
#endif |
|
huh
i got another error: "Attempted to read or write protected memory. This is often an indication
that other memory is corrupt" WTH is all of these errors ?!!? |
remove the .def file, and change void Function(); to the function you wanna export.
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Mon Apr 28, 2008 12:47 pm Post subject: |
|
|
Ok so you say it happens when you click a checkbox. Whats your checkbox code for when it's clicked?
_________________
- Retired. |
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Mon Apr 28, 2008 1:21 pm Post subject: |
|
|
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 |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Mon Apr 28, 2008 1:33 pm Post subject: |
|
|
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 |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Tue Apr 29, 2008 7:55 am Post subject: |
|
|
__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 |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Tue Apr 29, 2008 8:25 am Post subject: |
|
|
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 |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Tue Apr 29, 2008 8:30 am Post subject: |
|
|
| 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 |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Tue Apr 29, 2008 8:58 am Post subject: |
|
|
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 |
|
 |
|