forcable fail dll load?

Windows specific forum
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

forcable fail dll load?

Post by jassing »

From within a dll

during "attach process" -- under certain conditions, I want the dll to "fail to load" -- is there a way to do that?

EDIT:
it appears if I raise an error in AttachProcess() this causes the dll to not load...
Is this the best approach?
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: forcable fail dll load?

Post by Shield »

It might be enough just to return false in AttachProcess...at least that's how you'd do it in the native WinAPI DllMain function...
Check this out, it might help: http://msdn.microsoft.com/en-us/windows ... 87379.aspx
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: forcable fail dll load?

Post by jassing »

Shield wrote:It might be enough just to return false in AttachProcess...at least that's how you'd do it in the native WinAPI DllMain function...
Check this out, it might help: http://msdn.microsoft.com/en-us/windows ... 87379.aspx
I thought that might be -- but a function w/o a specific "procedurereturn" does return 0/false

So by default, attachprocess procedure returns false.
Thorium
Addict
Addict
Posts: 1308
Joined: Sat Aug 15, 2009 6:59 pm

Re: forcable fail dll load?

Post by Thorium »

You could try using DllMain instead of AttachProcess and DetachProcess.
It has a return value that indicates if it was successfull.

http://msdn.microsoft.com/en-us/library ... 82583.aspx
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: forcable fail dll load?

Post by Kwai chang caine »

I don't know if i have good understand the question :oops:
But there are a long time FREAK give to me this little jewel 8)
I use it for not give acces of my DLL if the key of the EXE is not good :D

Code: Select all

 !ADD esp, 8     ; remove Instance variable and return address from stack 
 !MOV eax, 0     ; set returnvalue to 0 
 !RET 12         ; return from DllEntryPoint 
ImageThe happiness is a road...
Not a destination
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: forcable fail dll load?

Post by jassing »

Kwaï chang caïne wrote:I don't know if i have good understand the question :oops:
But there are a long time FREAK give to me this little jewel 8)
I use it for not give acces of my DLL if the key of the EXE is not good :D

Code: Select all

 !ADD esp, 8     ; remove Instance variable and return address from stack 
 !MOV eax, 0     ; set returnvalue to 0 
 !RET 12         ; return from DllEntryPoint 
Thanks -- I was looking for a "proper way" -- but it seems there are many ways. Personally, I like the simple

Code: Select all

RaiseError(#ERROR_DLL_INIT_FAILED)
Error returned to calling program is meaningful...
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5502
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: forcable fail dll load?

Post by Kwai chang caine »

Cool i never see this function :shock: :oops:
Thanks jassing 8)
ImageThe happiness is a road...
Not a destination
Post Reply