Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / October 2004

Tip: Looking for answers? Try searching our database.

resource-only dll

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bonj - 19 Oct 2004 21:54 GMT
when creating a resource-only dll, the only way I can get it to compile and
work correctly, is to make it a non-resource-only dll.
surely this can't be the way...?
basically, there is a load of resources, in a dll. The DLL is a managed
class library, but it has got an unmanaged function that accesses the
resources. FindResource only works on the HMODULE that is gained by casting
the HINSTANCE passed to DllMain into an HMODULE (I think they're the same
thing anyway.)
There is also a manged class to be accessed from a C# application, this bit
works fine. But it is just the /NOENTRY option that is baffling me.
The return value of GetModuleHandle, doesn't work - as in, it can't find the
resources with this handle.
Apart from the DLL resources, the only things in the DLL are some C code
just to access the resources, and the managed class.
How can I make it a resource-only managed DLL with C code in it, if
compiling it with /NOENTRY means that DllMain doens't get called? (which it
doesn't.)
Igor Tandetnik - 19 Oct 2004 22:01 GMT
> when creating a resource-only dll, the only way I can get it to
> compile and work correctly, is to make it a non-resource-only dll.
> surely this can't be the way...?
> basically, there is a load of resources, in a dll. The DLL is a
> managed class library, but it has got an unmanaged function that
> accesses the resources.

Then how is it a resource-only DLL? A resource-only DLL - surprise
here - only contains resources, but no code. Yours is not a resouce-only
DLL, obviously.

> How can I make it a resource-only managed DLL with C code in it

"Resource-only DLL with code in it" is an oxymoron.
Signature

With best wishes,
   Igor Tandetnik

"On two occasions, I have been asked [by members of Parliament], 'Pray,
Mr. Babbage, if you put into the machine wrong figures, will the right
answers come out?' I am not able to rightly apprehend the kind of
confusion of ideas that could provoke such a question." -- Charles
Babbage

Bonj - 19 Oct 2004 22:32 GMT
so it *must* have an entry point, in order to get an HMODULE?

>> when creating a resource-only dll, the only way I can get it to
>> compile and work correctly, is to make it a non-resource-only dll.
[quoted text clipped - 10 lines]
>
> "Resource-only DLL with code in it" is an oxymoron.
Bonj - 19 Oct 2004 22:39 GMT
No - hang on, it can be a resource-only DLL with code in it. That isn't
contradictory. Being a resource-only DLL, meaning that it has got the
'resource only DLL ' compiler option checked. Not that it hasn't got any
code in it. If you put the 'resource only DLL' option on (/NOENTRY) it still
compiles and works when it's got code in it. It's just it has no way (that I
know of...) of getting an HMODULE that can access the resources.... but my
reason for posting, perhaps I can get the HMODULE in the same way that a
'resource-only' DLL which truly hasn't got any code in it gets its
HMODULE....no?
The only reason I want to use the /NOENTRY is to get rid of a linker
warning, see
http://support.microsoft.com/default.aspx?scid=kb;en-us;814472

>> when creating a resource-only dll, the only way I can get it to
>> compile and work correctly, is to make it a non-resource-only dll.
[quoted text clipped - 10 lines]
>
> "Resource-only DLL with code in it" is an oxymoron.
Igor Tandetnik - 19 Oct 2004 23:05 GMT
> No - hang on, it can be a resource-only DLL with code in it.

It cannot, by definition. A resource-only DLL has _resources_ _only_ -
that's why it's called resource-only in the first place. If it has code
as well as resources, it is _not_ resource-only, because it has code in
additon to resources. I don't know how I could possibly state it any
clearer.

> That
> isn't contradictory. Being a resource-only DLL, meaning that it has
> got the 'resource only DLL ' compiler option checked.

This option only works properly when the DLL does not have any code in
it - in other words, when it is resource-only.

> Not that it
> hasn't got any code in it. If you put the 'resource only DLL' option
> on (/NOENTRY) it still compiles and works

If it works, why are you here asking questions? Apparently, it does not
work all that well.

Also, if you are OK with having code in it, why do you insist on
/NOENTRY? The point of /NOENTRY with a resource-only DLL is to make it
smaller, by having the linker throw away the code segment. But you
cannot throw away the code segment, since you have code in the DLL. So
what again is the point of the exercise?

> but my reason for posting, perhaps
> I can get the HMODULE in the same way that a 'resource-only' DLL
> which truly hasn't got any code in it gets its HMODULE....no?

A resource-only DLL that has no code does not get its own HMODULE -
there's no code in it to "get" anything. It's just a data file in a
certain format. The code (in some other EXE or DLL) that wishes to use
this data file obtains HMODULE by calling LoadLibraryEx with
LOAD_LIBRARY_AS_DATAFILE flag.

> The only reason I want to use the /NOENTRY is to get rid of a linker
> warning, see
> http://support.microsoft.com/default.aspx?scid=kb;en-us;814472

Ah, that's a different question. I don't quite see how a mixed DLL is
supposed to obtain its own HMODULE, considering that it's not allowed to
implement DllMain. You may want to start another thread with this
question.
Signature

With best wishes,
   Igor Tandetnik

"On two occasions, I have been asked [by members of Parliament], 'Pray,
Mr. Babbage, if you put into the machine wrong figures, will the right
answers come out?' I am not able to rightly apprehend the kind of
confusion of ideas that could provoke such a question." -- Charles
Babbage

Bonj - 20 Oct 2004 06:51 GMT
> If it works, why are you here asking questions? Apparently, it does not
> work all that well.

Define "apparently ... does not work all that well" ?

If I go one route, I have got the linker telling me my application might not
run correctly, yet  it does. If go another route, I have got you telling me
it might not run correctly, yet it does. It's also confusing how they don't
put up a message box saying 'Sorry, this DLL can't be resource only. The
wizard has detected some code.'
To be fair, I am more inclined to believe you, as you have got a sensible
argument whereas the linker hasn't. But it's still confusing.

> Also, if you are OK with having code in it, why do you insist on /NOENTRY?
> The point of /NOENTRY with a resource-only DLL is to make it smaller, by
[quoted text clipped - 11 lines]
> this data file obtains HMODULE by calling LoadLibraryEx with
> LOAD_LIBRARY_AS_DATAFILE flag.

So an *actual* resource only DLL is just basically a flat binary file?
Igor Tandetnik - 20 Oct 2004 14:55 GMT
>> If it works, why are you here asking questions? Apparently, it does
>> not work all that well.
>
> Define "apparently ... does not work all that well" ?

It seems to me, based on the very fact that you had to ask a question in
the first place, that you are not completely satisfied with the
performance of your setup. Is that a clear enough explanation?

> If I go one route, I have got the linker telling me my application
> might not run correctly, yet  it does. If go another route, I have
> got you telling me it might not run correctly, yet it does.

The linker warns about a different, completely unrelated issue. Not
about your resource setup, but about a problem in .NET CLR whereby mixed
mode DLLs may sometimes lock up upon loading unless DllMain is disabled.
The reason is that, if DllMain is not disabled, it may end up running
managed code, and managed code may deadlock when run under a loader
lock. The KB article you quote, as well as the whitepaper referred to by
the KB, go into this problem in great detail.

Again, this has nothing to do with your DLL containing or not containing
resources. Trying to make it a resource-only DLL is a wild goose chase -
forget about it. This is not your problem, your problems lie elsewhere.
That's why I suggest you start a new thread with a more specific
question - since a mixed mode DLL has to disable DllMain, how should it
obtain its own HMODULE?

> So an *actual* resource only DLL is just basically a flat binary file?

Basically, yes.
Signature

With best wishes,
   Igor Tandetnik

"On two occasions, I have been asked [by members of Parliament], 'Pray,
Mr. Babbage, if you put into the machine wrong figures, will the right
answers come out?' I am not able to rightly apprehend the kind of
confusion of ideas that could provoke such a question." -- Charles
Babbage

Mihai N. - 20 Oct 2004 07:06 GMT
> A resource-only DLL that has no code does not get its own HMODULE -
> there's no code in it to "get" anything. It's just a data file in a
> certain format. The code (in some other EXE or DLL) that wishes to use
> this data file obtains HMODULE by calling LoadLibraryEx with
> LOAD_LIBRARY_AS_DATAFILE flag.

It is a (not so well) known problem with this.

See here (search for LOAD_LIBRARY_AS_DATAFILE)
http://www.microsoft.com/msj/0499/multilangunicode/multilangunicode.aspx

Basically, on Windows 95 (9x ?) the "resource only dll" aproach does not work
properly. This is why I would recomand to use another popular name
"satellite DLL," and add a dummy DLLMain (as also recomended by the article).

Ok, this seems to be no problem if you don't support Windows 95.
But, really, why not be 100% compatible, when the price is so low?

And the article is a great read, regardless the dll question :-)

Signature

Mihai
-------------------------
Replace _year_ with _ to get the real email

Bonj - 20 Oct 2004 10:21 GMT
Ah! "Satellite DLL" could be what I am after... I'll take a look at the
article. I'm not planning on supporting Win95 anyway as it's virtually
extinct now and my application uses a .NET front end which won't run on Win95
anyway.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.