7 Replies - 4425 Views - Last Post: 29 December 2012 - 02:12 PM Rate Topic: -----

#1 scottas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 10-November 11

Trying to attach dll

Posted 26 December 2012 - 03:16 PM

I've read that dll's should be called automaticaly, when .exe file, placed in the same folder is called. So I made simple code ( to be sure that dll is attached ):

#include	"Windows.h"

BOOL WINAPI	DllMain ( HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpReserved )
{
	switch ( fdwReason )
	{
	case DLL_PROCESS_ATTACH:
		{
			MessageBox ( 0, L"test 123", L"test", MB_OK | MB_ICONQUESTION );
			break;
		}
	case DLL_PROCESS_DETACH:
		{
			break;
		}
	}
	return TRUE;
}

But I get no message. Any ideas?

Is This A Good Question/Topic? 0
  • +

Replies To: Trying to attach dll

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3650
  • View blog
  • Posts: 11,419
  • Joined: 05-May 12

Re: Trying to attach dll

Posted 26 December 2012 - 06:43 PM

You may have misread. The .exe will load the .dll in the same directory only if the .exe was written to dynamically link in that .dll. Just putting in a .dll that the .exe knows nothing about won't do anything for you (unless somebody wrote code in the executable to search for any sibling files).
Was This Post Helpful? 0
  • +
  • -

#3 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 615
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: Trying to attach dll

Posted 26 December 2012 - 11:32 PM

You need to load the DLL at runtime. You can use LoadLibrary to load it in to memory, and functions like GetProcAddress if you want to call the DLL's functions.

This post has been edited by Aphex19: 26 December 2012 - 11:32 PM

Was This Post Helpful? 1
  • +
  • -

#4 scottas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 10-November 11

Re: Trying to attach dll

Posted 27 December 2012 - 08:45 AM

So I need to make an exe, which will load my .dll with LoadLibrary. But its possible to make it without any other programs, just with dll itself, or not?
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3650
  • View blog
  • Posts: 11,419
  • Joined: 05-May 12

Re: Trying to attach dll

Posted 27 December 2012 - 10:00 AM

With just your DLL alone, no.

If you write some DLL injection code, embed that code within your DLL, and use another program to run your DLL injection code to inject your DLL into your target program, then you can get your DLL running within the context of the target program. But then again, it's not that target program loading your DLL on it's own volition. You are forcing your way into that program. In general, DIC won't teach you any DLL injection techniques and you'll have to go elsewhere to learn how to do that.

What exactly are you trying to do? It maybe possible that what you need can be done without loading your code into the other program's code space.
Was This Post Helpful? 0
  • +
  • -

#6 scottas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 10-November 11

Re: Trying to attach dll

Posted 27 December 2012 - 10:08 AM

There is such a program called pawno, which is a compiler for Pawn language. I can use only that version which is given, and I want to make counter for marked text in it, nothing much :D. Now it shows only row and column.
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3650
  • View blog
  • Posts: 11,419
  • Joined: 05-May 12

Re: Trying to attach dll

Posted 27 December 2012 - 02:28 PM

Seems like an awful lot of trouble to get into, if you could just paste the marked text into another text editor to get a character count.
Was This Post Helpful? 0
  • +
  • -

#8 scottas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 10-November 11

Re: Trying to attach dll

Posted 29 December 2012 - 02:12 PM

I know, its for comfortability only
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1