.dll Question Planet Modules

cristiapi

New member
Joined
May 26, 2014
Messages
222
Reaction score
0
Points
0
Location
Ancona
This is the base that I used for my CeBoMo (I have VS2012).

The header file:

Code:
#pragma once

#define _USE_MATH_DEFINES
#define ORBITER_MODULE
#include "OrbiterAPI.h" 
#include "CelbodyAPI.h" 

class DLLEXPORT CRISTIANO: public CELBODY2
{
public:
	CRISTIANO(OBJHANDLE hObj);
	~CRISTIANO();
	void clbkInit (FILEHANDLE cfg);
	int clbkEphemeris (double mjd, int req, double *ret);
	int clbkFastEphemeris (double simt, int req, double *ret);
	bool bEphemeris() const {  return true; }
};


the .cpp file (a bit non standard, but this way there are no linking errors):


Code:
#include "celbody.h"

DLLCLBK CELBODY *InitInstance (OBJHANDLE hBody) { return new CRISTIANO(hBody); }

DLLCLBK void ExitInstance (CELBODY *body) { delete (CRISTIANO*)body; }

void __cdecl dummy(void) {}


BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:

		break;

	case DLL_THREAD_ATTACH:

		break;

	case DLL_THREAD_DETACH:

		break;

	case DLL_PROCESS_DETACH:

		break;
	}
	return TRUE;
}


CRISTIANO::CRISTIANO(OBJHANDLE hObj): CELBODY2 (hObj) 
{
}

CRISTIANO::~CRISTIANO()
{
}

void CRISTIANO::clbkInit(FILEHANDLE cfg)
{
} 

int CRISTIANO::clbkEphemeris(double mjd, int req, double *ret) 
{

	// Calculate the body state

	// Change the flags as appropriate
	return EPHEM_TRUEPOS | EPHEM_TRUEVEL | EPHEM_PARENTBARY | EPHEM_BARYISTRUE;
}

int CRISTIANO::clbkFastEphemeris(double simt, int req, double *ret)
{
	return clbkEphemeris(oapiTime2MJD(simt), req, ret);
}

In the Linker -> Input -> Additional Dependencies page of VS add orbiter.lib.
 

cristiapi

New member
Joined
May 26, 2014
Messages
222
Reaction score
0
Points
0
Location
Ancona
What did you put in dllmain.cpp? I suspect that you should delete that module or that you should delete DllMain() entry point in CRISTIANO.cpp.

It seems that the IDE is showing an error for InitInstance(); does the project get compiled?

I don't use precompiled headers; I don't know whether it could be a problem.
 

cristiapi

New member
Joined
May 26, 2014
Messages
222
Reaction score
0
Points
0
Location
Ancona
If dllmain.cpp contains the function DllMain(), you could delete either that module or the function DllMain() (I'd prefer the latter).
 
Last edited:

cristiapi

New member
Joined
May 26, 2014
Messages
222
Reaction score
0
Points
0
Location
Ancona
I still see the module dllmain.cpp and the function dllmain().
dllmain() must be defined only once.

In the header file I see that "OrbiterAPI.h" and "CelbodyAPI.h" are not found. You need to add their path in
VC++ Directories -> Include Directories: <Orbiter_root>\Orbitersdk\include
and
VC++ Directories -> Library Directories: <Orbiter_root>\Orbitersdk\lib
 

cristiapi

New member
Joined
May 26, 2014
Messages
222
Reaction score
0
Points
0
Location
Ancona
In the "Debug" or "Release" folder, but you need to add the code to calculate the state of the body.
 

cristiapi

New member
Joined
May 26, 2014
Messages
222
Reaction score
0
Points
0
Location
Ancona
You should write the code in the function clbkEphemeris() or clbkFastEphemeris(). But I strongly suggest that you read the official documentation.

Do you know how to calculate the position and the velocity of the body to which the dll refers?
 
Top