Irrlicht.dll with Delphi

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
scorpeti
Posts: 5
Joined: Thu Aug 07, 2014 7:09 am

Irrlicht.dll with Delphi

Post by scorpeti »

Hi everyone!

I would like to share my experience with one problem and ask for suggestions if you have any. Everything is on Windows 7 platform.

1. step:
1.a) I downloaded Irrlicht 1.8.1 and built a release DLL with Visual Studio 2010 without any changes (C++ of course).
1.b) I created a C interface called Visualization DLL that uses Irrlicht as a graphical interface. It gets some basic parameters, like "create a truck" and it uses Irrlicht functions to load and handle the model of the truck. I did this in the same Visual Studio 2010.
1.c) I created a C# application called TestApp EXE that loads Visualization DLL. It calls the functions like "create a truck" and works just perfectly. No problem at all, same Visual Studio 2010 as before. I had some nice lights and models at the end.

BUT

2. step:
2.a) I made the exact same steps like in 1.a) and 1.b): built Irrlicht and Visualization DLL without any difference
2.b) I copied the exported DLL-s and media files to an other project called SDK. This project is written in Delphi using RAD Studio 2007. It has an interface to load external DLL plugins, methods exported and imported in C. SDK already has many plugins right now, they have no problem at all. I would like to add Visualization DLL to this SDK project as a new plugin, using C functions again. But it fails.

I already checked a lot of things, here are my experiences:

c1) The SDK application stops at initializing with access violation error in ntdll.dll at >ntdll.dll!77c115de(). It doesn't even reach DLLMain() function in Visualization.dll, it doesn't even show a single bit of SDK's interface and of course it can't even reach the point when the program calls the first function in Visualization.dll.
c2) If I remove the Irrlicht dependent functions in Visualization.dll and rebuild it, the SDK project works perfectly using the remaining functions in Visualization.dll.
c3) The maximum size of stack in SDK project settings is set to 0x1000000 (=16777216). This is the absolute maximum, RAD Studio doesn't let me make this value any larger. I guess it shouldn't be a problem, but I wrote it anyway.
c4) I tried compiling Irrlicht as a DLL or Static lib, exactly the same results with both.
c5) Calling conventions are set to cdecl or stdcall on both sides, no matter, it has the same error.
c6) I am pretty sure there is no problem in SDK project, because it is a really huge project with lots of other plugnis (no other graphical engine), every one of the works perfectly, all of them written in C++ with C interface.

Conclusion:
If I use one compiler for C++ --> C --> C# application, Irrlicht works absolute perfectly, if I use two compilers for C++ --> C --> Delphi application, Irrlicht fails to be initialized (including the DLL fails, not the createDeviceEx() function!).


If you have any ide why breaks ntdll.dll with an access violation, or why Delphi fails while C# works perfectly without any problem, please help me. If you need more information, I am happy to share.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Irrlicht.dll with Delphi

Post by mongoose7 »

Are you mixing debug/non-debug applications and DLLs?
I don't think you can determine if DllMain was called as I believe it is called by the loader.
Are you using DEF files or exporting functions in code?
scorpeti
Posts: 5
Joined: Thu Aug 07, 2014 7:09 am

Re: Irrlicht.dll with Delphi

Post by scorpeti »

I am not mixing debug/non-debug applications and DLL-s.
I put a breakpoint to DLLMain() function's first line. When the file is loaded without a problem, DLLMain() is called and the application stopst at the breakpoint. When it loads unsuccesfully, the acces violation occurs in ntdll.dll before the program would reach that breakpoint.
I use a DEF file, I already checked the DLL export settings multiple times with dependency walker. It works in C#, and in Delphi when Irrlicht is not there.

Some new information:
c7) The access violation doesn't appear when I delete the createDeviceEx(..) call from my code. This function is called by one object and in one place only. When I comment it and build, it works perfectly, when I uncomment it, same access violation occurs as I mentioned before.

EDIT:

After c7), I deleted the content of createDeviceEx() in Irrlicht.cpp source code, leaving only a return 0; line. There was still the same access violation. That means when the Delphi application loads the Visualization DLL and the Visualization calls a createDeviceEx(..) function anywhere in the code from Irrlicht.dll, it has an access violation before loading the DLLs, even if the newly built Irrlicht and Visualization is in the same solution in Visual Studio 2010. Maybe you would say my problem is not Irrlicht specific because it's not dependent on Irrlicht's actual codes, but every other non-irrlicht plugins work well in the Delphi program.

Maybe the problem is in these C++ calls (copied from irrlicht.dll using dependency walker):
?IdentityMaterial@video@irr@@3VSMaterial@12@A
?IdentityMatrix@core@irr@@3V?$CMatrix4@M@12@B
?LOCALE_DECIMAL_POINTS@core@irr@@3V?$string@DV?$irrAllocator@D@core@irr@@@12@A
?createIrrXMLReader@io@irr@@YAPAV?$IIrrXMLReader@DVIXMLBase@io@irr@@@12@PAU_iobuf@@@Z
?createIrrXMLReader@io@irr@@YAPAV?$IIrrXMLReader@DVIXMLBase@io@irr@@@12@PAVIFileReadCallBack@12@_N@Z
?createIrrXMLReader@io@irr@@YAPAV?$IIrrXMLReader@DVIXMLBase@io@irr@@@12@PBD@Z
?createIrrXMLReaderUTF16@io@irr@@YAPAV?$IIrrXMLReader@U?$xmlChar@G@io@irr@@VIXMLBase@23@@12@PAU_iobuf@@@Z
?createIrrXMLReaderUTF16@io@irr@@YAPAV?$IIrrXMLReader@U?$xmlChar@G@io@irr@@VIXMLBase@23@@12@PAVIFileReadCallBack@12@_N@Z
?createIrrXMLReaderUTF16@io@irr@@YAPAV?$IIrrXMLReader@U?$xmlChar@G@io@irr@@VIXMLBase@23@@12@PBD@Z
?createIrrXMLReaderUTF32@io@irr@@YAPAV?$IIrrXMLReader@U?$xmlChar@I@io@irr@@VIXMLBase@23@@12@PAU_iobuf@@@Z
?createIrrXMLReaderUTF32@io@irr@@YAPAV?$IIrrXMLReader@U?$xmlChar@I@io@irr@@VIXMLBase@23@@12@PAVIFileReadCallBack@12@_N@Z
?createIrrXMLReaderUTF32@io@irr@@YAPAV?$IIrrXMLReader@U?$xmlChar@I@io@irr@@VIXMLBase@23@@12@PBD@Z

Every other plugins contain external C functions, but not C++. However for some reason Irrlicht.dll contains C++ external call functions. CreateDevice, CreateDeviceEx and png_... functions are all external C functions.

Can you tell me please what those functions do I copied before and where can I delete them from the external call list?
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Irrlicht.dll with Delphi

Post by mongoose7 »

Removing the call to createDeviceEx just means that the DLL is not loaded. So your problem is not to do with the functions, but with the loading of the DLL. Is there room in the address space for the DLL?
The functions you mention are in Irrlicht.cpp and irrXML.cpp. They may implement a C interface?? Yes, Irrlicht contains C++ functions - it's a C++ library. If you are looking for a C library, this is not it.
Post Reply