By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 827 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

Learner changing executable to library

P: n/a
My little app to scan World of Warcraft auction scans now works in that
it generates useful tables in CSV format that the user can do wahtever
they like with.

I created it as a console application. If I want to put a File
Selection GUI on it, the nicest way would be to change it to a library
rather than start again. I think in Windows this means a dll.

Is this possible? Its only 400 lines of code, a lot of which has
"Learner" stamped all over it but learning to make a library is my next
step.

If there is a URL to how this works and what UI hsould read, please let
me know.

Thanks.

Oct 2 '06 #1
Share this Question
Share on Google+
17 Replies


P: n/a
If there is a URL to how this works and that* I* should* read, please
let me know. Sorry - awful spelling - its Monday and late night last
night ;-)

Oct 2 '06 #2

P: n/a
pkirk25 said:
My little app to scan World of Warcraft auction scans now works in that
it generates useful tables in CSV format that the user can do wahtever
they like with.

I created it as a console application. If I want to put a File
Selection GUI on it, the nicest way would be to change it to a library
rather than start again. I think in Windows this means a dll.
Can be, but needn't be. You can do static libraries in Windows.

And if you do go the DLL route, it is possible to do so *without* hacking
your source code full of Microsoft-specific junk. (Anyone who tells you
different doesn't know what they're talking about.)
Is this possible? Its only 400 lines of code, a lot of which has
"Learner" stamped all over it but learning to make a library is my next
step.
I have a page which explores this subject (albeit rather briefly) on my Web
site:

http://www.cpax.org.uk/prg/portable/c/statlibs.php

It is, at least, a place to start.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 2 '06 #3

P: n/a
Can be, but needn't be. You can do static libraries in Windows.

And if you do go the DLL route, it is possible to do so *without* hacking
your source code full of Microsoft-specific junk. (Anyone who tells you
If the app is useful it will need to run on Mac as well as Windows.

If I read correctly, I rename main() to do_something() and make sure
the headers are in the library path and I'll be able to call
do_something() from the GUI app.

I will read up on how to do this from within the VC++ IDE.

Thanks fo ra very useful web page.

Oct 2 '06 #4

P: n/a
Can be, but needn't be. You can do static libraries in Windows.
>
And if you do go the DLL route, it is possible to do so *without* hacking
your source code full of Microsoft-specific junk. (Anyone who tells you
If the app is useful it will need to run on Mac as well as Windows.

If I read correctly, I rename main() to do_something() and make sure
the headers are in the library path and I'll be able to call
do_something() from the GUI app.

I will read up on how to do this from within the VC++ IDE.

Thanks for a very useful web page.

Oct 2 '06 #5

P: n/a
pkirk25 wrote:
My little app to scan World of Warcraft auction scans now works in that
it generates useful tables in CSV format that the user can do wahtever
they like with.

I created it as a console application. If I want to put a File
Selection GUI on it, the nicest way would be to change it to a library
rather than start again. I think in Windows this means a dll.

Is this possible? Its only 400 lines of code, a lot of which has
"Learner" stamped all over it but learning to make a library is my next
step.

If there is a URL to how this works and what UI hsould read, please let
me know.
The comp.lang.c part of your answer:
Make your source code structurally library-ready, i.e. plan which
interface you want to use: Does it come down to one function called
from main()? Do you want to pass in FILE pointers or FILE names?
.... Split your source files accordingly and provide headers containing
this interface.
Now, make a library (however this may work) from everything but the
file containing main().

<OT>
I just entered
how to create a dll with visual studio
in google and the first link did not seem too bad.
The DLL mechanism offers a kind of special linkage (C has only
extern, internal or no linkage), which lead to __declspec()
in function declarations.
You only have to adjust the "interface headers" accordingly.
If you want your source to be portable, I suggest using macros
to get rid of the need for three variants of the interface headers:
#ifdef WhateverYouNeedToFindOutItsWindowsIReallyDontKnowI tForSure
# ifdef MY_INTERFACE_EXPORT
# define PROVIDE_SPECIAL_LINKAGE __declspec(dllexport)
# else
# define PROVIDE_SPECIAL_LINKAGE __declspec(dllimport)
# endif
#else
# define PROVIDE_SPECIAL_LINKAGE
#endif
Then, you only need to #define MY_INTERFACE_EXPORT when building
the DLL and can reuse the interface headers.
Now, you just have to insert PROVIDE_SPECIAL_LINKAGE wherever needed.
</OT>
Note that I am not an expert in this area, so my advice may be
incorrect, incomplete, or not the best possible. This is better
asked in a newsgroup where developing under Windows is on-topic.
Do not forget to check for their FAQ.

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Oct 2 '06 #6

P: n/a
Michael Mair said:

<snip>
I just entered
how to create a dll with visual studio
in google and the first link did not seem too bad.
The DLL mechanism offers a kind of special linkage (C has only
extern, internal or no linkage), which lead to __declspec()
in function declarations.
You don't need any of that junk. You can sidestep it all by writing a little
..DEF file. Far cleaner, and doesn't pollute the C source.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 2 '06 #7

P: n/a
Richard Heathfield wrote:
You don't need any of that junk. You can sidestep it all by writing a little
.DEF file. Far cleaner, and doesn't pollute the C source.
Pretty sure this is a common method the Cygwin guys utilize as well.
Win32 is such a POS.
Oct 2 '06 #8

P: n/a
Richard Heathfield wrote:
Michael Mair said:
<snip>
>>I just entered
how to create a dll with visual studio
in google and the first link did not seem too bad.
The DLL mechanism offers a kind of special linkage (C has only
extern, internal or no linkage), which lead to __declspec()
in function declarations.

You don't need any of that junk. You can sidestep it all by writing a little
.DEF file. Far cleaner, and doesn't pollute the C source.
Which once more leads to the conclusion: Ask where its on-topic :-)

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Oct 2 '06 #9

P: n/a
Michael Mair said:
Richard Heathfield wrote:
>Michael Mair said:
<snip>
>>>I just entered
how to create a dll with visual studio
in google and the first link did not seem too bad.
The DLL mechanism offers a kind of special linkage (C has only
extern, internal or no linkage), which lead to __declspec()
in function declarations.

You don't need any of that junk. You can sidestep it all by writing a
little .DEF file. Far cleaner, and doesn't pollute the C source.

Which once more leads to the conclusion: Ask where its on-topic :-)
Actually, if he had done so, he'd probably have got the declspec answer, and
bye-bye portability.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 2 '06 #10

P: n/a
Richard Heathfield wrote:
Michael Mair said:
>>Richard Heathfield wrote:
>>>Michael Mair said:
<snip>

I just entered
how to create a dll with visual studio
in google and the first link did not seem too bad.
The DLL mechanism offers a kind of special linkage (C has only
extern, internal or no linkage), which lead to __declspec()
in function declarations.

You don't need any of that junk. You can sidestep it all by writing a
little .DEF file. Far cleaner, and doesn't pollute the C source.

Which once more leads to the conclusion: Ask where its on-topic :-)

Actually, if he had done so, he'd probably have got the declspec answer, and
bye-bye portability.
So, you say "ask in clc as you may get better answers even if your
request is OT"...

GD&R
Michael

P.S.: Well, I have never heard of .DEF files before, either.
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Oct 2 '06 #11

P: n/a
Michael Mair said:
Richard Heathfield wrote:
>Michael Mair said:
>>>Richard Heathfield wrote:
Michael Mair said:
<snip>

>I just entered
how to create a dll with visual studio
>in google and the first link did not seem too bad.
>The DLL mechanism offers a kind of special linkage (C has only
>extern, internal or no linkage), which lead to __declspec()
>in function declarations.

You don't need any of that junk. You can sidestep it all by writing a
little .DEF file. Far cleaner, and doesn't pollute the C source.

Which once more leads to the conclusion: Ask where its on-topic :-)

Actually, if he had done so, he'd probably have got the declspec answer,
and bye-bye portability.

So, you say "ask in clc as you may get better answers even if your
request is OT"...
Er... er... er... y... No! No, what I'm saying is that you should have asked
in clc if and only if you end up getting a better answer there than you
would have got anywhere else. :-)

(This has the advantage that the clc cabal[1] can decide retrospectively
whether to consider an article topical.)

P.S.: Well, I have never heard of .DEF files before, either.
You'll never be able to say that again...
[1] TINC.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 2 '06 #12

P: n/a
I have made the executable into a static lib jsut by changing the term
int main() to int read_source_lua and adding a header. Executable was
11kb. Even when VC optimizes for smallest size, the library is now
76kb.

So I go back to scratch and make sure that there are no pre-compiled
headers and stuff checked in by VC. Make new project with same source
files and it is same size.

Is this normal?

Oct 2 '06 #13

P: n/a
pkirk25 said:
I have made the executable into a static lib jsut by changing the term
int main() to int read_source_lua and adding a header. Executable was
11kb. Even when VC optimizes for smallest size, the library is now
76kb.
So what? What matters is not the size of the library, but the size of what
is taken out from the library. Think of your local lending library. It's
rather larger - in fact, very very very much larger - than the total size
of all the books it stores. Do you care, when you are walking home with the
latest Tom Clancy burning a hole in your carrier bag? Of course not. You
don't have to cart the library home with you, after all.
So I go back to scratch and make sure that there are no pre-compiled
headers and stuff checked in by VC. Make new project with same source
files and it is same size.

Is this normal?
Yes, it's housekeeping information and stuff like that. Don't worry about
it.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 2 '06 #14

P: n/a
nt

Oct 2 '06 #15

P: n/a
On 2 Oct 2006 00:27:44 -0700, in comp.lang.c , "pkirk25"
<pa*****@kirks.netwrote:
>
I created it as a console application. If I want to put a File
Selection GUI on it, the nicest way would be to change it to a library
rather than start again. I think in Windows this means a dll.
Nah, just create a GUI app with your favorite C GUI app builder
environment, and include the source files in it.
>Is this possible?
Undoubtedly, but you need to ask in a Windows or Linux or whatever
group to get details.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Oct 2 '06 #16

P: n/a
On Mon, 02 Oct 2006 08:16:15 +0000, in comp.lang.c , Richard
Heathfield <in*****@invalid.invalidwrote:
>Michael Mair said:

<snip>
>I just entered
how to create a dll with visual studio
in google and the first link did not seem too bad.
The DLL mechanism offers a kind of special linkage (C has only
extern, internal or no linkage), which lead to __declspec()
in function declarations.

You don't need any of that junk. You can sidestep it all by writing a little
.DEF file. Far cleaner, and doesn't pollute the C source.
You don't need that /either/ but further discussion is offtopic here
of course.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Oct 2 '06 #17

P: n/a
Mark McIntyre said:
On Mon, 02 Oct 2006 08:16:15 +0000, in comp.lang.c , Richard
Heathfield <in*****@invalid.invalidwrote:
>>
You don't need any of that junk. You can sidestep it all by writing a
little .DEF file. Far cleaner, and doesn't pollute the C source.

You don't need that /either/ but further discussion is offtopic here
of course.
And that's a shame, because you just managed to intrigue me.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 2 '06 #18

This discussion thread is closed

Replies have been disabled for this discussion.