thanks to CommonTater and to timovjl for timely responses. still some issues.
to CommonTater:
"Compile the DLL as a separate project."
the .dll and the .exe are 2 separate projects.
"Write a header with your DLL's exports in it and include it in your main project."
i declared my function as an extern in the main project. for the purposes of this test, that should be the same thing, no?
"Tell the linker to link with the library."
i believe i have already done that. as i indicated, i had told the linker to use my .lib in the project options. and, as i indicated, the verbose output from the build shows that the .lib is being searched.
"Use LoadLibrary() to make sure the DLL is in memory..."
isn't LoadLibrary() a runtime call? unresolved external is link time. i don't get beyond link time.
thanks for mickey.zip. i appreciate your comment about polluting the pelles c directories. your mm.dll doesn't seem to have used the wizard. it looks quite different from what the wizard generates.
no .def, no .lib. as i ask below in this post: is the .dll wizard not actually supposed to be used for building a .dll?
--------------------------------------------------------------------------------------------------------------------------------
to timovjl:
thanks for all the examples - lots of work for you - but i want to continue to do what i always do: link with a .lib and have a corresponding .dll somewhere convenient.
if i have done something that prevents that - and judging by your suggestions, what i have done is seriously wrong - then i want to undo that and do it right.
you say:
"Because you change function name to undecorated form, you should use dynamic linking with LoadLibrary or tell linker what altername name is. "
ok, 3 things:
1) i realize LoadLibrary() is an option, and i have used it in other projects where the .dll was 3rd party, but i didn't have the unresolved external errors.
and as just stated, i would like to be able to add a .lib to the linker options and build normally.
2) you say i changed the function name to "undecorated form". what i did was change "SampleFunction()" to "getTotal()" in the dllmain.c and .h. i then changed "_SampleFunction@8" to "_getTotal@8" in the .def. isn't that still "decorated"? what's not decorated here?
and
3) have i not told the linker what the alternate name is? didn't i tell the linker what the alternate name was by linking with the .lib, which has the alternate decorated name? this is what i'm not following.
your second example looks just like what i already see in my dllmain.c and .def.
what you have in your example .def file:
LIBRARY TestDllNew.dll
EXPORTS
"MyExportFunction" = _getTotal@8
what i have in my .def file
my .def file:
LIBRARY "mydll"
EXPORTS
; TODO: Add your exports here!
"MyExportFunction"=_getTotal@8
why is your .def right and mine wrong? this is what i don't get.
i'm guessing i could just build the sample .dll from the wizard as is and link to my test project, and it would work fine, but that doesn't help me see
how to build .dll's. i can't have a .dll that only does 1 thing. and i can't name all my library functions "SampleFunction()" because that's the only
name that works.
so, yes, i changed the function name in the files generated by the wizard, but i believe i kept the decoration, and the .dll builds without error.
that should count for something, no? what do i do if i don't want SampleFunction()? are we saying i can't use the wizard because it's only meant
to build and export SampleFunction() and nothing else?
i would like to fire up the .dll wizard, add a bunch of functions, save and build a .dll and have a .lib file with the exports and add it to the linker options, just like i do with every other project that i build. is this doable? if so, what do i do differently? i've seen an example for vc++. it doesn't look terribly different from what the pelles c dll wizard generates. is there something i have to do with the pelles c wizard that i'm missing?
using the .dll wizard to build mydll.dll, and having a function called getTotal(), what do i have to do beyond declaring the function and coding it? let's say for argument's sake that i declare it in mydll.h and put the code in maindll.c i'll just ignore SampleFunction() and leave it be. is there a missing step in this scenario? how did my .dll build without an error if i made an error?
thanks again and sorry to ramble on.
-go