C++ Question .dll or .lib?

Bj

Addon Developer
Addon Developer
Donator
Joined
Oct 16, 2007
Messages
1,886
Reaction score
11
Points
0
Location
USA-WA
Website
www.orbiter-forum.com
Quite simply, I want to hide a particular portion of the code from others, while still letting them integrate.

So I know a .dll is a dynamic library, while .lib is a static library.

However, the functions I need are dependent on the simulator state
(ie it uses opcPreStep)

Can I use a .lib style library, or do I need to use .dll?

In the case of required to use .dll, since I have exactly 2 functions that will be used by other addons, what in particular do I need to do to make them work as callbacks? Is it -DLLCLBk?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,588
Reaction score
2,312
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
If you have static data that should be saved between the calls, use a static library - in a DLL, there would be only one instance of such data stored for all processes that call the DLL, while in a static library, the data is stored for all compilation units of the same program/DLL.

DLLs are just special forms of executables, don't forget that.
 

MeDiCS

Donator
Donator
Joined
Sep 22, 2008
Messages
602
Reaction score
2
Points
0
It doesn't matter, but you can't implement opcPreStep (or any callback) directly. You can access all Orbiter API functions, and you can get the simulation state directly when either exported function is called (AFAIK, sim state can be correctly retrieved from any oapi callback).

---------- Post added at 07:50 PM ---------- Previous post was at 07:47 PM ----------

If you have static data that should be saved between the calls, use a static library - in a DLL, there would be only one instance of such data stored for all processes that call the DLL, while in a static library, the data is stored for all compilation units of the same program/DLL.

DLLs are just special forms of executables, don't forget that.
Really? I know that code is shared between DLL instances, but I'm fairly sure it's data section is unique for every instance.
 
Last edited:

Bj

Addon Developer
Addon Developer
Donator
Joined
Oct 16, 2007
Messages
1,886
Reaction score
11
Points
0
Location
USA-WA
Website
www.orbiter-forum.com
If you have static data that should be saved between the calls, use a static library - in a DLL, there would be only one instance of such data stored for all processes that call the DLL, while in a static library, the data is stored for all compilation units of the same program/DLL.

DLLs are just special forms of executables, don't forget that.

It doesn't matter, but you can't implement opcPreStep directly. You can access all Orbiter API functions from either, and you can get the simulation state directly when either exported function is called (AFAIK, sim state can be correctly retrieved from any oapi callback).

So since there should only be 1 user it could use a .lib, but as long as opcPreStep and opcCloseRenderViewport are actually called from the .dll using the .lib then it should be fine.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,588
Reaction score
2,312
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Really? I know that code is shared between DLL instances, and I'm fairly sure it's data section is unique for every instance.

You can select it, you can have shared and private data. But for private data, it makes only rarely sense to have DLLs in that context. DLLs with private data make more sense if you have a fixed interface and want to be able to have modular programs.
 

MeDiCS

Donator
Donator
Joined
Sep 22, 2008
Messages
602
Reaction score
2
Points
0
So since there should only be 1 user it could use a .lib, but as long as opcPreStep and opcCloseRenderViewport are actually called from the .dll using the .lib then it should be fine.
You could do like Dan's UMmu do for loading and saving UMmu data on the scenario. Instead of directly implementing clbkLoadStateEx and clbkSaveState, it requires you to call it from within those callbacks.

You can select it, you can have shared and private data. But for private data, it makes only rarely sense to have DLLs in that context. DLLs with private data make more sense if you have a fixed interface and want to be able to have modular programs.
True, it depends on what you want. Unless Bj expect multiple users and want to avoid bloat, he should go for static libraries.
 
Top