Author |
Topic: Creating D3DX8BBC.DLL for BBCBASIC for Windows (Read 2376 times) |
|
knudvaneeden
Developer
member is offline


Posts: 32
|
 |
Creating D3DX8BBC.DLL for BBCBASIC for Windows
« Thread started on: Sep 15th, 2009, 8:09pm » |
|
If Richard (again) would like to inform about the steps of how to create this D3DX8BBC.DLL, I (or somebody else (also)) could try to create it.
As a first step, I started Microsoft Visual Studio 2005, and tried to create a (MFC) DLL. That took about 1 minute to have a .dll file created on disk (using a wizard).
So doing a more involved DLL job (=creating this D3DX8BBC.DLL) might (maybe) doable soon, given that enough how to instructions are to be received.
Note: I looked earlier into it using Microsoft Visual C++ Express, Borland C++ Builder or Borland command line compiler, Richard tried gcc. But (full) Microsoft Visual Studio (2005, 2008, ...) might be the way to go. This because the DLL to be created is a bit special and has to be conform certain specifications. Microsoft Visual Studio seems to be the most simple, compatible tool for this specific job, as far as I know.
with friendly greetings, Knud van Eeden
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
« Reply #1 on: Sep 15th, 2009, 9:23pm » |
|
Quote:If Richard (again) would like to inform about the steps of how to create this D3DX8BBC.DLL, I (or somebody else (also)) could try to create it. |
|
I explained this before, but nobody seemed to be interested (then) in taking it forward.
As you know, there is already in existence a D3DX8BBC.DLL, which I created and announced on the group almost exactly one year ago:
http://groups.yahoo.com/group/bb4w/files/%22Temp%20Folder%22/d3dx8bbc.dll
The problem is that it exports only the D3DX functions implemented in plain C, not those implemented in C++, the reason being that gcc, which was used to build it, cannot link with Microsoft C++ libraries.
To overcome this problem would require the DLL to be built using MS Visual Studio rather than gcc. If you want to attempt that I would suggest you do it in two steps: firstly to reproduce the (limited) functionality of the existing DLL and secondly to add the missing functionality. Trying to do it in one step would almost certainly end in tears!
For the first step you would need to take the existing source file: http://groups.yahoo.com/group/bb4w/files/%22Temp%20Folder%22/d3dx8bbc.c (stupid Conforums can't understand a .c file extension!) and carry out the necessary edits to make it compatible with VS. That would then need to be built and tested to confirm correct functionality.
The second, more difficult, step would be to uncomment the section I had to disable - and add the code I never got around to writing - to provide the full functionality.
Incidentally I couldn't find any way, using gcc, of exporting the original function names, which is why I ended up adding a BBC suffix to every one. Ideally it would be better not to need this suffix, so maybe VS would allow you to do that.
Richard.
|
|
Logged
|
|
|
|
knudvaneeden
Developer
member is offline


Posts: 32
|
 |
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
« Reply #2 on: Sep 16th, 2009, 11:25pm » |
|
First steps, but still quite a few errors.
http://www.knudvaneeden.com/tinyurl.php?urlKey=url000345
Now Richard succeeded in creating it using gcc, but then with C libraries.
Therefor it would be (very) helpful if you could describe (or repeat) the steps (e.g. the .h include files which you added, and where).
Because this steps worked, and should be about the same for linking the C++ libraries.
Thanks
|
|
Logged
|
|
|
|
Michael Hutton
Developer
member is offline


Gender: 
Posts: 248
|
 |
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
« Reply #3 on: Sep 17th, 2009, 02:21am » |
|
Knud,
Thanks for showing us the basic steps. This is something I have been keen to try and do for a while. I am playing a large amount of 'catch up' though at the moment. So I will be following with interest.
Michael
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
« Reply #4 on: Sep 17th, 2009, 08:48am » |
|
Quote:Therefor it would be (very) helpful if you could describe (or repeat) the steps |
|
Here is the make file:
Code:c:\mingw\bin\gcc -O2 -c d3dx8bbc.c -o d3dx8bbc.o
c:\mingw\bin\gcc -fexceptions d3dx8bbc.o d3dx8.lib \MinGW\lib\libmsvcrt.a \MinGW\lib\libuuid.a -shared -DBUILD_DLL -Wl,-s -o d3dx8bbc.dll I noticed MFC mentioned in the VS screenshots. Try to disable that if you possibly can, since we don't want to end up with BB4W requiring MFC!!
I would also check that the DLL you create isn't significantly bigger than the one I made using gcc; in particular disable any debugging information such as embedded symbols (remember that we're trying to replace D3DX8D.DLL - the debug version - with something smaller and faster).
Quote:(e.g. the .h include files which you added, and where). |
|
All the included (.h) files are standard ones from Microsoft, to be found in the relevant SDK(s).
I wouldn't have expected you to ask that question if you have the degree of knowledge and understanding that you will undoubtedly need. This is no task for a novice!
Richard.
|
|
Logged
|
|
|
|
knudvaneeden
Developer
member is offline


Posts: 32
|
 |
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
« Reply #5 on: Sep 17th, 2009, 11:02am » |
|
Well, I am not everyday creating DLLs, better say never  and working with C++ extremely seldom. So this is all relatively new here also (I usually solve a problem very quickly using BBCBASIC for Windows (as it is one of the simplest systems, and simplicity is what I like and prefer), or I use Semware TSE)).
So I approach this DLL creation with general problem solving methods (comparison methods, elimination methods, trial and error, pattern recognition, ...), and see how far I get. Thus not really guarantees that it will succeed, and I also can not spend full time (better said very short time) to investigate fully all differences and possibilities, or it must be in a weekend when I probably have more time.
Of course if anybody else (e.g. (very) experienced) wants to jump in or take over all the better, or of course we can work together then if wanted, similar to the open source idea.
If necessary I will currently ask for directions or hints, to avoid spending too much time investigating all different roads to the end goal. Better ask too much sometimes than spending too much extra time.
Regarding the question about the .h file, first compilation (as shown in the screenshots) gave 108 errors. All involving the file d3dx8math.inl. This hinted at maybe (manually) #include the file 'd3dx8math.h' (where the Visual Studio compiler did not complain or hinted about). After I included it that reduced the total amount of errors to 9. So therefor the question about where to add the .h files.
1. I think in the weekend I will try first compiling using Ming gcc and your make file. So when succeeding I can see a working result.
2. Then work from there and repeat similar steps using Visual Studio, so that I can compare and check with the working project in gcc.
Thanks for mentioning further not to use MFC (=Microsoft Foundations Classes) DLLs here.
Thanks,
with friendly greetings, Knud van Eeden
|
|
Logged
|
|
|
|
knudvaneeden
Developer
member is offline


Posts: 32
|
 |
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
« Reply #6 on: Sep 17th, 2009, 11:31am » |
|
Note: There seems currently to be only MFC DLL as an option (at least in the wizard templates) in Microsoft Visual Studio 2005.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
« Reply #7 on: Sep 17th, 2009, 12:57pm » |
|
Quote:There seems currently to be only MFC DLL as an option |
|
Hopefully it won't actually need to link to any MFC code. After all, there shouldn't need to be any code included in addition to that in the D3DX libraries. The exercise we're involved in is simply to export those routines so they can be dynamically linked rather than statically linked.
As I recollect, one of the main issues I had (other than the C++ library incompatibility) was related to exception handling, and I had to incorporate a kludge (at the very beginning of the C file) to allow gcc to compile/link without error. You'll almost certainly need to delete that code and replace it with whatever VS needs (I have no idea what that might be).
Richard.
|
|
Logged
|
|
|
|
knudvaneeden
Developer
member is offline


Posts: 32
|
 |
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
« Reply #8 on: Sep 20th, 2009, 12:38am » |
|
OK, I managed to at least compile to D3Dx8BBC.dll without errors. Now possibly working from there.
See the steps done in the PDF, and the dll for download http://www.knudvaneeden.com/tinyurl.php?urlKey=url000345
Please check if it (very maybe) is of any use yet.
Thanks.
with friendly greetings Knud van Eeden
|
|
Logged
|
|
|
|
knudvaneeden
Developer
member is offline


Posts: 32
|
 |
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
« Reply #9 on: Sep 20th, 2009, 01:24am » |
|
I double checked the dll file by comparing it with a valid dll file (as I e.g. could not export any function from it using a DLL export program like Borland impdef.exe).
The file looks very much like it is corrupt. Which is rather serious I think, that it compiles without errors, but the result is corrupt.
If I can not reduce this corruption problem to some settings in Microsoft Visual Studio 2005, then it might be that I will upgrade to Microsoft Visual Studio 2008 , and try again...
with friendly greetings, Knud van Eeden
|
|
Logged
|
|
|
|
Michael Hutton
Developer
member is offline


Gender: 
Posts: 248
|
 |
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
« Reply #10 on: Sep 20th, 2009, 01:33am » |
|
Hi Knud,
I just tried it in one of my old programs but it does seem to be corrupted in some way.
Code:
file$=@lib$+"d3dx8bbc.dll"
SYS "LoadLibrary", file$ TO D3DX%
IF D3DX%=0 THEN ERROR 100,"No D3DX support."
Oh, so nearly! Well done for trying. It will be a good thing when we know how to do this.
Just reading through your pdf today.
Michael
|
|
Logged
|
|
|
|
knudvaneeden
Developer
member is offline


Posts: 32
|
 |
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
« Reply #11 on: Sep 20th, 2009, 03:14am » |
|
OK, now created successfully a D3DX8BBC.dll which exports functions.
The necessary step was to choose 'Win32 appication', then 'DLL' when creating a new project (this instead of MFC DLL).
The further steps were about the same (that is paste .c program at the end, and #include "d3dx8math.h", further link the d3dx8.lib in the project).
with friendly greetings, Knud van Eeden
|
|
Logged
|
|
|
|
knudvaneeden
Developer
member is offline


Posts: 32
|
 |
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
« Reply #12 on: Sep 20th, 2009, 04:38am » |
|
For some reason the exported functions are still in C++ format.
|
|
Logged
|
|
|
|
JonR
New Member
member is offline


Posts: 24
|
 |
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
« Reply #13 on: Sep 20th, 2009, 09:59am » |
|
What is qute bizzare is that the exported functons have names like 'struct D3DXCOLOR * __cdecl D3DXColorAddBBC(struct D3DXCOLOR *,struct D3DXCOLOR const *,struct D3DXCOLOR const *)' instead of simply 'D3DXColorAddBBC' or indeed the preferable (to me) 'D3DXColorAdd'.
There's a quick and dirty guide to creating Win32 DLLs with C+ 2005 that might be worth taking a look through: http://www.kapilik.com/2007/09/17/how-to-create-a-simple-win32-dll-using-visual-c-2005/
I notice that you seem to be having some difficulty using the DLL function import tool. Using the latest verson on my site you can specify the DLL as the input file; there is no need to manually use Nir Sofer's DLL Export Viewer unless you want to only export certain functions.
If you do use the DLL Export Viewer you must save the selected funtions list as a 'Tab delimited text file', failure to do so will cause the DLL Importer to generate garbage code as you discovered.
Of course it seems that you'll have to fix the function names issue before DLL Import tool can produce sensible code.
|
« Last Edit: Sep 20th, 2009, 10:06am by JonR » |
Logged
|
|
|
|
Michael Hutton
Developer
member is offline


Gender: 
Posts: 248
|
 |
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
« Reply #14 on: Sep 20th, 2009, 12:30pm » |
|
I *think* the problem is Visual Studio itself which, I was reading today, will decorate the function names. One of the ways around this, apparently, is to create an "export.def' file to tell the compiler the function names.
On a related note I have now been able to create a new PerlinDLL which includes a new "GeneratePerlinTexture3d" function which will create a 2d texture based on a third (float) z parameter. Now you can scroll through 3 dimensions to create clouds etc. I'll upload to the group. The only thing I haven't figured out is why my dll is 499kb long whereas the original is 70kb. I have only added a few functions, so I don't know what my problem is. I must be adding something somewhere.
On another aside, looking at the ASM output the code seems *very* inefficient (ahem! :-X), although very 'safe' with lots of stack maniputlations which a dedicated embedded BB4W ASM routine probably wouldn't need. It is interesting to see the way the compiler will translate
Code:
c = (r << 16) || (g <<8) || b
and compare to: Code:
c = (r << 16) + (g <<8) + b
where r g abd b are ints the first being seemingly indeciferable and the second using the expected add eax,[ebp+x]. I haven't got the output handy as I did this earlier on today.
Michael
|
|
Logged
|
|
|
|
|