On 2011-11-12 22:20, R.Wieser wrote:
>> Because it seemed silly to me that someone would object
>> to a solution just because it had two files in it, considering
>> that any solution to your original problem would already
>> feature two files (the executable being loaded and the one
>> doing the loading) so what's one more?
>
> Nope, wrong. Sorry. My hybrid EXE/DLL is aimed at a program already on
> the computer. A possibility you did not think of.
>
This post is rather long. You may want to skip to the end if you don't feel
like reading, most of it won't help you out but the end bit will.
If you're still here, great! All assumptions are now spelled out in full.
Only *now* do I know why none of my answers are useful to you.
The problem is that you wanted me to answer only your original question, in
full detail ("why doesn't calling loading executables and calling exported
functions from other executables work?"), with authoritative references and
everything. That's not what I did because it's not how I usually approach
problems. If I think something isn't practical I'll start cooking up
possible alternatives, not spend time working out exactly *why* the original
approach won't work and if, by more effort, it can be made to work. I'm not
saying that's not interesting, by the way, or that you shouldn't do it, just
that it didn't seem like a good use of *my* time to *me*.
There is probably no way you could have formulated your original request to
avoid pointless suggestions from me other than by working out all solutions
in advance and spelling them out with reasons why they're no good in your
original post, so I'm sorry about that.
If it were me, I'd simply drop the "it must be a one-file copy requirement"
because I don't see the users needing to copy two files as opposed to just
one to be a big problem. For a download, I'd offer one .ZIP to extract (or a
setup, since .ZIPs require the user to first do the "unblock" dance, which
is not as friendly -- setups just give a one-time warning you can click
through).
Your mileage may vary, but to me the original problem isn't worth the effort
-- I'd bail out at the first sign of trouble, because this is an
optimization and not something that allows people to do something truly new,
which I prefer spending time on. Again, your mileage may vary.
>> You *did* read the link I provided, right?
>
> Nope, as I'm not using/targetting "Vista onwards" it does not apply to me.
> I should have thanked you for the offering though.
>
It contains pre-Vista info about why calling functions from .EXEs doesn't work.
This is also the first time you inform us that you're not running Vista (not
targetting Vista is another matter, that's certainly interesting but not
immediately relevant), so we can take ASLR off the table as a candidate for
problems.
You can evaluate stuff I said and conclude it's not good/doesn't apply to
you by telling me why not. You can also ignore stuff I said up-front because
it seemed obvious to you it didn't answer your question. I can't tell the
difference if you don't say anything.
You don't need to thank me for anything, especially if it's not useful to
you, but if you want me to be relevant, give feedback. Keep the thoughts
flowing -- I wouldn't be spending time answering you if I wasn't interested
in seeing your problem solved, one way or another.
>> Even pre-Vista, imports aren't resolved because the loader
>> doesn't bother.
>
> Do you have any info to substanciate that ?
>
Besides the link I posted? No. I'm assuming random people on the Internet
who cared more than I do (because they really wanted it to work) know more
about it. That's the extent to which I'm willing to spend my free time.
If you want to substantiate it, fire up WinDbg and check the import table.
Better yet, you reported a crash. Fire up WinDbg and figure out what the
crash is. I'm definitely too lazy to do this just so I can be authoritative
on Usenet -- I don't think this scenario is interesting enough. Sorry about
that, but you get what you pay for.
> And by the way : if you want to talk about links, did you read the MS link I
> provided in my first post ? I don't know about you, but I can't find what
> you are saying anywhere in there.
>
This is the MSDN we're talking about. In some spots, the MSDN is an
excellent and complete source of info. Those spots are unfortunately not
numerous. In this case, the MSDN is far from complete.
It *does* document what LoadLibraryEx() does when faced with an executable
(
http://msdn.microsoft.com/library/windows/desktop/ms684179), and we can
*assume* (again, I haven't fired up WinDbg to see if LoadLibrary() defers to
LoadLibraryEx(), but I'll be damned if it doesn't) that LoadLibrary() has
the same "problems": if you pass an executable module, it will act as if
DONT_RESOLVE_DLL_REFERENCES was specified, and that in turn says that "the
system does not load additional executable modules that are referenced by
the specified module".
From that we can infer that at least some modules will not have their
imports resolved because they're not loaded. I suppose modules like KERNEL32
*might* be resolved correctly because they're already loaded/implicitly
loaded, but it might also very well be that no resolving is done, and ASLR
then makes sure that no function can be called correctly -- even odds,
should be checked, as there is no documentation and at least one person
reported problems consistent with this theory (you) I haven't looked further.
This is all speculation, albeit reasonable speculation. You can get down to
the bottom of things if you want to.
> And another thing: why can I expose functions in an EXE (like as in a DLL)
> when the OS does not allow me to use them ? Already thought about that ?
>
Sure. DLLs and EXEs are the same file format. The loader doesn't treat them
the same, but it makes no sense for other tools to treat them differently.
That's extra work.
I have no difficulty imagining nobody at Microsoft bothered to implement an
error mode for the linker where it goes "you know, on an NT platform, you
will have almost no chance of calling these functions correctly, so I'll do
the right thing and give an error that you shouldn't export these functions
from an .EXE" (for all I know this worked on Windows 3.1 or even Windows 95
-- I don't think so, but I don't know).
It's not that the OS doesn't allow you to use them -- it's that it goes to
no trouble to *enable* you to use them. As a programmer you can probably
appreciate not putting in effort to make things work you don't support,
unless people encourage you to. I don't think MS has been encouraged by
anyone to make this scenario (which you have to admit is rather unusual)
working reliably.
>> Well in this case, the how and why is not too interesting, all
>> you need to remember is that it doesn't work -- problem solved.
>
> I'm sorry, but I seem to have trouble with the "just believe me" kind of
> answers. Those tend to fade from my memory within a few days.
> Fact-supported information seems to work a lot better for me.
>
If you want more information on how to use WinDbg to get it, just give a holler.
If you want authoritative info, this is not the right place to get it. You
can open a support ticket with MS, or use the officially sanctioned forums
by MS (those are at
http://www.microsoft.com/communities/forums/default.mspx
-- this NG has officially been decommissioned by MS, even though there are
still people here).
--
J.