API Question InitModule never called [fixed]

DesideriusPapp

New member
Joined
May 23, 2009
Messages
21
Reaction score
0
Points
0
Hi all,

I'm still vying with my first .dll addon. My problem is with InitModule and ExitModule. I gather from the API Guide and Reference that the presence of #define ORBITER_MODULE at the head of my main .cpp file should cause the .dll to call both.

My point is, it doesn't - I guess due to something I'm doing wrong. I've got an header file in which I

Code:
#include"orbitersdk.h"
Then in the main .cpp file I have the following:

Code:
#include"Strelka.h"
#include<stdio.h>
#include<math.h>
 
#define ORBITER_MODULE
It compiles all right and it works, but InitModule and ExitModule are never called. I see in the code samples that #define ORBITER_MODULE is at the top of the file, i.e.: above the #include lines, but if I move it I get the following error:

1>------ Build started: Project: Strelka, Configuration: Release Win32 ------
1>Compiling...
1>Strelka.cpp
1>Linking...
1> Creating library ..\..\..\Orbiter\Modules\Strelka.lib and object ..\..\..\Orbiter\Modules\Strelka.exp
1>Orbitersdk.lib(Orbitersdk.obj) : error LNK2005: _DllMain@12 already defined in MSVCRT.lib(dllmain.obj)
1>..\..\..\Orbiter\Modules\Strelka.dll : fatal error LNK1169: one or more multiply defined symbols found
1>Build log was saved at "file://d:\Strelka Design Project\Strelka\Strelka\Release\BuildLog.htm"
1>Strelka - 2 error(s), 0 warning(s)

Anyone is so kind and patient as to give me a clue of what I'm getting wrong this time?

Thank you!
 
Last edited:
Ignore MSVCRT.lib in the linker settings. Strange that you get such a error then, I usually only see other linker errors with this library - orbiter uses a different version of it inside it's libraries, that is why you get trouble, despite not being needed at all.
 
Thank you Urwumpe, but if I ignore MSVCRT.LIB, I get the following

PHP:
1>------ Build started: Project: Strelka, Configuration: Release Win32 ------
1>Compiling...
1>Strelka.cpp
1>Linking...
1> Creating library ..\..\..\Orbiter\Modules\Strelka.lib and object ..\..\..\Orbiter\Modules\Strelka.exp
1>Strelka.obj : error LNK2001: unresolved external symbol __purecall
1>Strelka.obj : error LNK2001: unresolved external symbol "public: virtual char const * __thiscall std::exception::what(void)const " (?what@exception@std@@UBEPBDXZ)
1>MSVCMRT.lib(locale0_implib.obj) : error LNK2001: unresolved external symbol "public: virtual char const * __thiscall std::exception::what(void)const " (?what@exception@std@@UBEPBDXZ)
1>Strelka.obj : error LNK2001: unresolved external symbol "public: virtual char const * __thiscall std::exception::what(void)const " (?what@exception@std@@$$FUBEPBDXZ)
1>Strelka.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall std::exception::~exception(void)" (??1exception@std@@$$FUAE@XZ)
1>MSVCMRT.lib(locale0_implib.obj) : error LNK2001: unresolved external symbol "public: virtual __thiscall std::exception::~exception(void)" (??1exception@std@@$$FUAE@XZ)
1>Strelka.obj : error LNK2001: unresolved external symbol "public: __thiscall std::exception::exception(class std::exception const &)" (??0exception@std@@$$FQAE@ABV01@@Z)
1>MSVCMRT.lib(locale0_implib.obj) : error LNK2001: unresolved external symbol "public: __thiscall std::exception::exception(class std::exception const &)" (??0exception@std@@$$FQAE@ABV01@@Z)
1>Strelka.obj : error LNK2001: unresolved external symbol "extern "C" unsigned int __cdecl strlen(char const *)" (?strlen@@$$J0YAIPBD@Z)
1>Strelka.obj : error LNK2001: unresolved external symbol "void __cdecl operator delete[](void *)" (??_V@$$FYAXPAX@Z)
1>MSVCMRT.lib(locale0_implib.obj) : error LNK2001: unresolved external symbol "void __cdecl operator delete[](void *)" (??_V@$$FYAXPAX@Z)
1>Strelka.obj : error LNK2001: unresolved external symbol "extern "C" int __cdecl _purecall(void)" (?_purecall@@$$J0YAHXZ)
1>Strelka.obj : error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" (??3@$$FYAXPAX@Z)
1>MSVCMRT.lib(locale0_implib.obj) : error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" (??3@$$FYAXPAX@Z)
1>Strelka.obj : error LNK2001: unresolved external symbol "const type_info::`vftable'" (??_7type_info@@6B@)
1>MSVCMRT.lib(locale0_implib.obj) : error LNK2001: unresolved external symbol "const type_info::`vftable'" (??_7type_info@@6B@)
1>Strelka.obj : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int)" (??2@$$FYAPAXI@Z)
1>MSVCMRT.lib(locale0_implib.obj) : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int)" (??2@$$FYAPAXI@Z)
1>LINK : error LNK2001: unresolved external symbol __DllMainCRTStartup@12
1>MSVCMRT.lib(mstartup.obj) : error LNK2001: unresolved external symbol __forceCRTManifestRTM
1>MSVCMRT.lib(mstartup.obj) : error LNK2001: unresolved external symbol ___native_dllmain_reason
1>MSVCMRT.lib(mstartup.obj) : error LNK2001: unresolved external symbol ___native_vcclrit_reason
1>MSVCMRT.lib(mstartup.obj) : error LNK2001: unresolved external symbol ___xc_z
1>MSVCMRT.lib(mstartup.obj) : error LNK2001: unresolved external symbol ___xc_a
1>MSVCMRT.lib(mstartup.obj) : error LNK2001: unresolved external symbol ___xi_z
1>MSVCMRT.lib(mstartup.obj) : error LNK2001: unresolved external symbol ___xi_a
1>MSVCMRT.lib(mstartup.obj) : error LNK2001: unresolved external symbol ___native_startup_state
1>MSVCMRT.lib(mstartup.obj) : error LNK2001: unresolved external symbol "extern "C" void __cdecl _cexit(void)" (?_cexit@@$$J0YAXXZ)
1>MSVCMRT.lib(mstartup.obj) : error LNK2001: unresolved external symbol "extern "C" void __cdecl _amsg_exit(int)" (?_amsg_exit@@$$J0YAXH@Z)
1>MSVCMRT.lib(mstartup.obj) : error LNK2001: unresolved external symbol "extern "C" void __cdecl __security_init_cookie(void)" (?__security_init_cookie@@$$J0YAXXZ)
1>MSVCMRT.lib(mstartup.obj) : error LNK2001: unresolved external symbol ___native_startup_lock
1>MSVCMRT.lib(mehvecdtr.obj) : error LNK2001: unresolved external symbol "void __cdecl terminate(void)" (?terminate@@$$FYAXXZ)
1>MSVCMRT.lib(locale0_implib.obj) : error LNK2001: unresolved external symbol "extern "C" void __cdecl abort(void)" (?abort@@$$J0YAXXZ)
1>MSVCMRT.lib(msilexit.obj) : error LNK2001: unresolved external symbol "extern "C" void * __cdecl _encode_pointer(void *)" (?_encode_pointer@@$$J0YAPAXPAX@Z)
1>MSVCMRT.lib(msilexit.obj) : error LNK2001: unresolved external symbol "extern "C" void * __cdecl _decode_pointer(void *)" (?_decode_pointer@@$$J0YAPAXPAX@Z)
1>MSVCMRT.lib(msilexit.obj) : error LNK2001: unresolved external symbol "extern "C" void * __cdecl _encoded_null(void)" (?_encoded_null@@$$J0YAPAXXZ)
1>MSVCMRT.lib(managdeh.obj) : error LNK2001: unresolved external symbol "extern "C" int __cdecl __FrameUnwindFilter(struct _EXCEPTION_POINTERS *)" (?__FrameUnwindFilter@@$$J0YAHPAU_EXCEPTION_POINTERS@@@Z)
1>..\..\..\Orbiter\Modules\Strelka.dll : fatal error LNK1120: 30 unresolved externals
1>Build log was saved at "file://d:\Strelka Design Project\Strelka\Strelka\Release\BuildLog.htm"
1>Strelka - 38 error(s), 0 warning(s)

and at that point, where I put #define ORBITER_MODULE is indifferent...
 
My compiler settings have been working so far and should be as per the compiler tutorial... It wasn't until I tried assigning the handle to the module into InitModule that I came across the fact that that function is not called at all. Anyways thank you for the hint, I'll try and dig deeper into this.
 
Which compiler tutorial?
 
Last edited by a moderator:
Hi. Can you please compile/test the following piece of code? I have tested this on my system, and InitModule is being called.

Code:
#define STRICT
#define ORBITER_MODULE

#include <orbitersdk.h>

unsigned int val = 0;

DLLCLBK void InitModule(HMODULE hModule)
{
    val = 1;
}

DLLCLBK void opcPreStep(double simt, double simdt, double mjd)
{
    sprintf(oapiDebugString(), "%d", val);
}
If you are using Visual C++ 2008 express edition, this small video tutorial goes through creating a new project step-by step:
(skip to 2:50 for relevant information)

If InitModule is being called, 1 should be printed on the bottom left hand corner of the screen, otherwise 0 will be printed.
 
ORBITER_MODULE must be defined before Orbitersdk.h is included, otherwise the Orbitersdk.lib static library will not be linked into your module. Orbitersdk.lib includes, among other things, a dllMain for your module that registers the module when Orbiter loads it.

EDIT:
Managed code is for people who can't understand what their own programs do.
While it may be true that managed code can help protect such people from the damage they could cause, it does not follow that the corollary is true.
 
Hi all - thanks for your responses. In order:

Urwumpe: I was referring to the wiki compiler setup tutorial.

Computerex: I followed your tutorial instructions and tried compiling the sample code, and I get the same error as with my .dll. However, I note that I do not ignore msvcrt.lib, otherwise I get a lot more errors (reported a few posts earlier). Apart from that, my setup is what the tutorial shows.

Tblaxland: defining ORBITER_MODULE before including Orbitersdk.h would mean removing it from the .cpp file into the header file - and that seems not the way the sample code does it. Anyway I tried and the bottom line seems that I get the same error

1>Orbitersdk.lib(Orbitersdk.obj) : error LNK2005: _DllMain@12 already defined in MSVCRT.lib(dllmain.obj)
1>..\..\..\Orbiter\Modules\Strelka.dll : fatal error LNK1169: one or more multiply defined symbols found

whenever #define ORBITER_MODULE is placed before any #include directive.
 
Have you combined the ignoring of msvcrt with tblaxland's suggestion?
 
Yes. Still no success - in that case, the compiler tells me that dllmain is already defined in MSVCRTD.lib. Ingnoring this library only worsens things.
 
As I use the professional version of VC 2008, I am not sure if you have the same settings available, but lets try it:

Select Project properties (ALT+F7).
Select Configuration properties and there the child item "General"
Go to category "Project Defaults" in the list of options on the right.
Configuration Type: "Dynamic Library (.dll)
Use of MFC: Use Standard Windows Libraries (might work though with different options, did not try combining Orbiter add-ons and MFC yet)
Use of ATL: Not using ATL
Character Set: Select what suits you best, Orbiter is using only ANSI strings though.
Common Language Runtime support: No Common Language Runtime support (this is likely what causes the problem).
Whole program optimization: No optimization for debugging, all fun that you need for release.
 
You know, I might be overstepping the mark here a bit, but I use VC++ 2008 Express, too, and have had this type of error. Apart from what is mentioned above by Urwumpe, I got the same sort of thing under these circumstances;

Not having as additional dependancies; orbiter.lib and orbitersdk.lib (as well as kernel32, gdi32 and user32 libs).

Not having set my additional dependencies library directories;
(orbitersdk\lib\ and Microsoft SDK\v6.0\lib)

and maybe even the need to ignore msvcirt.lib.

Also a note (especially when using text functions and strings in the dll) the character set to multi byte character set.

Maybe something here might be it? I don't know, otherwise...
 
SOLVED!!

Again thank you all for your prompt response. This is indeed one of the most helpful communities I've been through...

Anyways, Urwumpe got it - I checked the config and the problem seemed to lie in the Common Language Runtime Support. I set it to No Common [etc.] and InitModule is correctly called, with #define ORBITER_MODULE at the top of the .cpp file.

Keith, I also checked following your indications - and the the additional dependancies, additional directories and ignore libraries are already set in my project as you say (I don't ignore MSVCRT.lib but I do ignore MSVCIRT.lib - don't know if this is going to pop up later as a problem) - and charachter is set to MultiByte - already had to face that issue when I tried having labels on VC MFD's...

Thanks again all, and ON to complete the .dll...
 
Back
Top