.dll Question How to load an Orbiter module from a standalone program

cristiapi

New member
Joined
May 26, 2014
Messages
222
Reaction score
0
Points
0
Location
Ancona
When I want to use an Orbiter DLL written by me from a standalone program, I don't have any problem, but when I try to use an Orbiter DLL which comes with the standard distribution (celbody or atmospheric DLL), I get the error code #126 (module not found) for LoadLibrary.

Please, could somebody help me?
 

meson800

Addon Developer
Addon Developer
Donator
Joined
Aug 6, 2011
Messages
405
Reaction score
2
Points
18
Open the DLL in question with Dependency Walker and see what it depends on.

IMHO DLL loading is "stupid", the other DLLs might be failing to load their dependencies, even if they are in the same directory. You might have to set the search path directly with something like SetDLLDirectory.
 

cristiapi

New member
Joined
May 26, 2014
Messages
222
Reaction score
0
Points
0
Location
Ancona
With Dependency Walker I saw that Earth.dll depends also on VSOP87.dll. But now (after loading VSOP87.dll) I get the error code #998 (access violation).
Do you know how that could happen?
 

meson800

Addon Developer
Addon Developer
Donator
Joined
Aug 6, 2011
Messages
405
Reaction score
2
Points
18
Did you load VSOP87 separately, or let Earth.dll load it?
 

cristiapi

New member
Joined
May 26, 2014
Messages
222
Reaction score
0
Points
0
Location
Ancona
I use LoadLibraryA from my program to load orbiter.exe, VSOP87.dll and earth.dll (in that order).

Since I wrote a (standalone) trajectory planning tool, I'm trying to find a generic way to load the celbody dll and the atmospheric model dll ("generic" in the sense that the method should be good to load any celbody and atmospheric dll that Orbiter can load).
 

meson800

Addon Developer
Addon Developer
Donator
Joined
Aug 6, 2011
Messages
405
Reaction score
2
Points
18
I use LoadLibraryA from my program to load orbiter.exe, VSOP87.dll and earth.dll (in that order).

Since I wrote a (standalone) trajectory planning tool, I'm trying to find a generic way to load the celbody dll and the atmospheric model dll ("generic" in the sense that the method should be good to load any celbody and atmospheric dll that Orbiter can load).

I think you just have to set the DLL path, and then just let Earth.dll load VSOP87.dll by itself. I think if you load VSOP, then Earth will try to load it, but its already loaded, which might lead to the access error.

As VSOP is in ORBITER_ROOT/Modules, afaik you would set the DLL directory to that, then load Earth.dll from that path.
Code:
SetDLLDirectory(".//Modules");
LoadLibrary("Celbody/Earth.dll");
The above is untested, I'm not sure if you can use relative paths that way. But the idea is the same. Set the DLL directory to ORBITER_ROOT/Modules, then load Earth.dll from the new DLL search path inside Modules.

That way, when Earth.dll calls
Code:
LoadLibrary("VSOP87.dll")
it finds VSOP, because the DLL search directory is just set to modules.
 

cristiapi

New member
Joined
May 26, 2014
Messages
222
Reaction score
0
Points
0
Location
Ancona
Using SetDllDirectory() I no longer get the module not found error and I don't need to load vsop87.dll (thank you :thumbup:), but I still get the access violation error.

I see that vsop87.dll depends on msvcr80.dll. I put that dll in the same dir of vsop87, but I get a runtime error (R6034).
 

meson800

Addon Developer
Addon Developer
Donator
Joined
Aug 6, 2011
Messages
405
Reaction score
2
Points
18
but I still get the access violation error.
:uhh: I'm not sure what could cause that. To be clear,
Code:
LoadLibrary("Celbody\\Earth.dll")
returns NULL, and GetLastError() returns 998?

Can you post the DLL-loading code?

I see that vsop87.dll depends on msvcr80.dll. I put that dll in the same dir of vsop87, but I get a runtime error (R6034).
That's not usually the solution. MSVCR80.dll should be in your PATH variable automatically, which is always searched.
 

cristiapi

New member
Joined
May 26, 2014
Messages
222
Reaction score
0
Points
0
Location
Ancona
:uhh: I'm not sure what could cause that. To be clear,
Code:
LoadLibrary("Celbody\\Earth.dll")
returns NULL, and GetLastError() returns 998?

Yes.

Can you post the DLL-loading code?

Code:
HINSTANCE hinstLib = LoadLibraryA("P:\\Simul\\Orbiter 100830\\orbiter.exe");
if(hinstLib == NULL) {
	int gle= GetLastError();
	wxMessageBox(wxString::Format("ERROR. LoadLibraryA #1. GetLastError= %d", gle), TITLE, wxICON_STOP);
	return;
}

SetDllDirectoryA("P:\\Simul\\Orbiter100830 BASE\\Modules");

HINSTANCE hinstLib2 = LoadLibraryA("P:\\Simul\\orbiter100830 BASE\\Modules\\Celbody\\earth.dll");
if(hinstLib2 == NULL) {
	int gle= GetLastError();
	wxMessageBox(wxString::Format("ERROR. LoadLibraryA #2. GetLastError= %d", gle), TITLE, wxICON_STOP);
	return;
}

That's not usually the solution. MSVCR80.dll should be in your PATH variable automatically, which is always searched.

You're right, but I installed VC2005 redistributable and if I do

Code:
HINSTANCE hinst = LoadLibraryA("msvcr80.dll");
if(hinst == NULL) {
	int gle= GetLastError();
	wxMessageBox(wxString::Format("ERROR. LoadLibrary. GetLastError= %d", gle), TITLE, wxICON_STOP);
	return;
}
I get the "module not found" error, while LoadLibraryA("msvcr110.dll") is fine (I'm using VS Express 2012).
 
Top