Template for Basic DLL

J

Jeff Gaines

I use C# for most of my apps but occasionally have to write a DLL
using C++, e.g. for global callbacks.

They are very simple and basic Dll's usually just using standard
Windows libraries, in fact they don't need C++, basic C would be fine.

Is it possible to set up a 'template' for such a basic Dll? None of
the MS templates seems to be suitable, they are too complex for these
simple needs and I spend hours changing the settings to get what I
want.

Now that I have set up a couple of projects with the appropriate
settings I would like to use them as a base for similar future
projects. Copying them into a new folder works after a fashion, until
I discovered that a lot of the original links had been copied and I
was making changes to one file while the compiler was happily building
a set of files in another folder :))

Any guidance would be appreciated.
 
W

William DePalo [MVP VC++ ]

Jeff Gaines said:
Is it possible to set up a 'template' for such a basic Dll? None of
the MS templates seems to be suitable, they are too complex for these
simple needs and I spend hours changing the settings to get what I
want.

Well, I'm not sure what you are spending "hours" changing :) because there
isn't much to a minimal DLL:

BOOL WINAPI DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID pv)
{
return TRUE;
}

Once you have that skeleton, you just add the functions that you want to
export:

int WINAPI foo(int bar)
{
return 42 * bar;
}

WINAPI is not strictly necessary for C++ callers above, but it is
traditional and may be required to accomodate the likes of VB.

If you want to export a function by unmangled/undecorated name then a module
definition file comes in handy:

LIBRARY MYDLL

EXPORTS

foo

And if you spend too much time undoing the work of the wizard, you can
always choose "Empty project" and write the boilerplate yourself.

Regards,
Will
 
J

Jeff Gaines

Well, I'm not sure what you are spending "hours" changing :) because there
isn't much to a minimal DLL:

BOOL WINAPI DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID pv)
{
return TRUE;
}

Once you have that skeleton, you just add the functions that you want to
export:

int WINAPI foo(int bar)
{
return 42 * bar;
}

WINAPI is not strictly necessary for C++ callers above, but it is
traditional and may be required to accomodate the likes of VB.

If you want to export a function by unmangled/undecorated name then a module
definition file comes in handy:

LIBRARY MYDLL

EXPORTS

foo

And if you spend too much time undoing the work of the wizard, you can
always choose "Empty project" and write the boilerplate yourself.

Regards,
Will

Will

OK, perhaps I was exaggerating slightly!
However, having got the settings as I wanted them I was keen to try
and find a way to save them.
I'll have a go with an 'Empty Project' and see how I get on.
VC is way too sophisticated for these needs, I find it easier to use
LCC for simple C DLL's but I was trying to stick to one tool.
Thanks for your response :))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top