Delphi .lib for Using in c++

Abdulatif AL ABDOU
Abdulatif AL ABDOU used Ask the Experts™
on
Hi;
I am trying to generate .lib in Delphi (Embarcadero XE3). for using it in c++ program

I made a package project; and successfully, i could generate the .lib and the hpp headers... but, when i edit the .hpp, i found that it includes all files needed but has no fonctions...
namespace Spicecorelib
{
//-- type declarations -------------------------------------------------------
//-- var, const, procedure ---------------------------------------------------
}      /* namespace Spicecorelib */

** What should i do to make functions exported, i have tried with ( cdecl, stdcall, export)....

thanks for your answers in advance
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Geert GOracle dba
Top Expert 2009

Commented:
there is a section "exports"
where you list what functions can be used from outside the dll

http://docwiki.embarcadero.com/RADStudio/Rio/en/Writing_Dynamically_Loaded_Libraries

a .lib ?
you create a .dll to use between different languages

Author

Commented:
What really i need is the use ( or the generate) of (.lib) not dll, i know how to generate and use .dll...

Is it possible from your point of view?

if found a tutorial but it was not helpful for me, because i do nearly the same!

Here it is: https://www.arbinada.com/en/node/1555

My problem is that my functions are not exported in the hpp files as wanted!

I really need to solve this issue! Thank you in advance for all answers and suggestions
>> it includes all files needed
Sorry I don't have Delphi experience. But was wondering if these files you refer to are header files, and if so, have you looked at all the included header files?
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Author

Commented:
Thanks for your answer; Yes i looked at all included header, i found that some files (classes) are exported correctly; on the other hand, there are files are not exported; i tried to see the differences between those correctly exported and the others but i did not found any difference... I have no experience on Delphi; Juste I know how the code is organized and i can make some modifications not more than that. I try to generate (.lib) to use it in C++QT.

I tried with the (dll); i could export the code in dll; i could charge the dll in C++QT; but when i call the wanted function; program exit without any message. It even not throw an exception!

So i am trying with (.lib)....
It is strange that you get function api's in other headers but not in all of them. So I am taking a wild guess as to how this could happen:
I learned that Delphi has conditional compilations just like C/C++.
http://docwiki.embarcadero.com/RADStudio/Rio/en/Conditional_compilation_(Delphi)
If the missing functions are conditionally not included, then that could be a reason for the missing functions.

Author

Commented:
Thank you phoffric, i will see this! at least i have an idea to work on...
In your other question, you refer to a 21 year old question:
https://www.experts-exchange.com/questions/10020543/Delphi-and-static-libraries.html
I don't know whether information from an old question is applicable to your environment.

One interesting item from this link is:
"Delphi 1 supports only pascal (the default) and cdecl, Delphi 2 - pascal, cdecl, stdcall, and register.
Functions written in C are usually cdecl."

More information here: https://stackoverflow.com/questions/3404372/stdcall-and-cdecl
"Both ways should work. In fact, this happens quite frequently at least in code that interacts with the Windows API, because __cdecl is the default for C and C++ programs according to the Visual C++ compiler and the WinAPI functions use the __stdcall convention."
Re: your DLL issue: Possibly you have a mismatch in calling convention you are using in your C++ environment.

I looked around, and guess that you followed instructions similar on this page:
http://docwiki.embarcadero.com/RADStudio/Rio/en/Output_-_C/C%2B%2B

You could try simpler work-arounds. On this link are options:

- Generate .hpp file.
- C/C++ Output file generation
  -> Generate C++ .objs, headers
   - Generates a header file (.hpp) and an object file (.obj)    ‑JPH

Author

Commented:
You are may be right; i had to try all different call convention. in fact, when i searched for the solution i found
https://www.experts-exchange.com/questions/10020543/Delphi-and-static-libraries.html

Which talk about using c++ lib in Delphi, I need the inverse i.e: Use Delphi in C++. Thanks a lot for your help; i will test that one more times and will back to tell you if that works...
Geert GOracle dba
Top Expert 2009

Commented:
my apologies, i didn't see .lib and .dll as separate things
delphi doesn't create .lib files

see this old q on stack:
https://stackoverflow.com/questions/2827649/is-it-possible-to-get-a-delphi-project-to-create-a-lib-file-as-the-output-of-the

Author

Commented:
Thank you Geert G for your answer; Indeed i use Embarcadero for generating .lib, and i have already generated it! I don't know if it was generated correctly!

In the other hand, i am trying to use the DLL but even thing not work; i have generated the DLL, it is charged with C++QT but when i call the function the program exit with code 250477278
Wish I knew Delphi to be better able to help you. But I wanted to make sure that you know the below information that I looked into.
>> code 250477278
- is a Structured Exception Handler associated with error code 0x250477278 (i.e., its equivalent hex value)
- my searches on this code seem to be related more to python usage of Delphi DLL rather than C++. But if you search on either the decimal or hex value of this code, maybe the python (or also some script issues) might help.
https://stackoverflow.com/questions/21231386/what-does-exit-code-250477278-of-a-delphi-application-mean

Other references:
https://stackoverflow.com/questions/6994230/structured-exception-handler-and-delphi
http://edn.embarcadero.com/article/30115


That decimal value is, in hex, 0EEDFADE. That is the SEH code for a native Delphi exception. So, it would seem that your program is throwing a native Delphi exception that is not being handled. And it is doing so before the Delphi RTL exception handling mechanism is in place to deal with it.

It's impossible for us to say what in your code is causing this to happen, since we don't have the code. What you need to do is some debugging. You first of all need to identify the exception and work out where and why it is being raised. I would start by adding madExcept (or similar) to the project and collect some more information about this exception.
https://stackoverflow.com/questions/21231386/what-does-exit-code-250477278-of-a-delphi-application-mean

Have you tried to generate just one header and object file as noted earlier as a possible work-around to help diagnose the problem of getting no functions identified in the header?

Author

Commented:
Hello phoffric, thank you for your answer, it was helpful;

I found the source of the problem (By Installing madExcept ), indeed my delphi program use devexpress components; in the ribbon component, the skins are not charged; when the program try to use the first skin, it will search for it in a list which is empty!

I know now the source of the problem but i did not find yes how to solve it.

Author

Commented:
Now I think that the problem comes from la dll (gdiplus); there is a line in the code for exit the charging of the Skins when the program does not find the dll (GdiPlus)... My delphi program on windows 7... my c++ program on window 10
Nice to hear that you could narrow down the problem with madExcept. I know that working with mixed Technologies on multiple platforms can pose a challenge especially when you were not the author of these programs. Perhaps the following link can help you with the dll:


https://www.google.com/amp/s/windowsreport.com/windows-10-error-gdiplus-dll/%3famp
The skins not loading may be due to initialization sections not being called for the DLL's included units.  When you load a DLL statically, there seems to be an issue with Delphi where these do not all get called.  See;
https://stackoverflow.com/questions/4618650/delphi-unit-initialization-not-always-called
or
https://groups.google.com/forum/#!topic/borland.public.delphi.language.delphi.general/X3PUMUbU2Nw

If the controls you are using happen to rely on the initialization sections, this will throw them out of sync.  Try loading your DLL statically, to see if the problem persists.

Also, I am interested in why you feel you need a lib instead of a dll.  Can you enlighten us as to why it makes a difference?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial