Orbiter-Forum  

Go Back   Orbiter-Forum > Orbiter Space Flight Simulator > Orbiter SDK
Register Blogs Orbinauts List Social Groups FAQ Projects Mark Forums Read

Orbiter SDK Orbiter software developers post your questions and answers about the SDK, the API interface, LUA, meshing, etc.

Reply
 
Thread Tools
Old 08-06-2015, 10:24 AM   #1
cristiapi
Orbinaut
 
cristiapi's Avatar
Default How to load an Orbiter module from a standalone program

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?
cristiapi is offline   Reply With Quote
Old 08-06-2015, 02:56 PM   #2
meson800
Donator
 
meson800's Avatar

Default

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.
meson800 is offline   Reply With Quote
Thanked by:
Old 08-06-2015, 05:15 PM   #3
cristiapi
Orbinaut
 
cristiapi's Avatar
Default

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?
cristiapi is offline   Reply With Quote
Old 08-07-2015, 12:49 AM   #4
meson800
Donator
 
meson800's Avatar

Default

Did you load VSOP87 separately, or let Earth.dll load it?
meson800 is offline   Reply With Quote
Old 08-07-2015, 10:56 AM   #5
cristiapi
Orbinaut
 
cristiapi's Avatar
Default

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).
cristiapi is offline   Reply With Quote
Old 08-07-2015, 01:54 PM   #6
meson800
Donator
 
meson800's Avatar

Default

Quote:
Originally Posted by cristiapi View Post
 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.
meson800 is offline   Reply With Quote
Old 08-07-2015, 03:00 PM   #7
cristiapi
Orbinaut
 
cristiapi's Avatar
Default

Using SetDllDirectory() I no longer get the module not found error and I don't need to load vsop87.dll (thank you ), 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).
cristiapi is offline   Reply With Quote
Old 08-07-2015, 04:39 PM   #8
meson800
Donator
 
meson800's Avatar

Default

Quote:
Originally Posted by cristiapi View Post
 but I still get the access violation error.
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?

Quote:
Originally Posted by cristiapi View Post
 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.
meson800 is offline   Reply With Quote
Old 08-07-2015, 07:10 PM   #9
cristiapi
Orbinaut
 
cristiapi's Avatar
Default

Quote:
Originally Posted by meson800 View Post
  I'm not sure what could cause that. To be clear,
Code:
LoadLibrary("Celbody\\Earth.dll")
returns NULL, and GetLastError() returns 998?
Yes.

Quote:
Originally Posted by meson800 View Post
 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;
}
Quote:
Originally Posted by meson800 View Post
 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).
cristiapi is offline   Reply With Quote
Reply

  Orbiter-Forum > Orbiter Space Flight Simulator > Orbiter SDK


Thread Tools

Posting Rules
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Jump


All times are GMT. The time now is 07:11 AM.

Quick Links Need Help?


About Us | Rules & Guidelines | TOS Policy | Privacy Policy

Orbiter-Forum is hosted at Orbithangar.com
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 2007 - 2017, Orbiter-Forum.com. All rights reserved.