BBC BASIC for Windows
General >> General Board >> Creating D3DX8BBC.DLL for BBCBASIC for Windows
http://bb4w.conforums.com/index.cgi?board=general&action=display&num=1253045396

Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by knudvaneeden 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
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by admin 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.
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by knudvaneeden 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
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by Michael Hutton 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
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by admin 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.
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by knudvaneeden on Sep 17th, 2009, 11:02am

Well, I am not everyday creating DLLs, better say never smiley
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

Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by knudvaneeden 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.

Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by admin 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.
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by knudvaneeden 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
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by knudvaneeden 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
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by Michael Hutton 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
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by knudvaneeden 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
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by knudvaneeden on Sep 20th, 2009, 04:38am

For some reason the exported functions are still in C++ format.
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by JonR 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.

Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by Michael Hutton 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
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by knudvaneeden on Sep 20th, 2009, 12:34pm

on Sep 20th, 2009, 09:59am, JonR wrote:
Of course it seems that you'll have to fix the function names issue before DLL Import tool can produce sensible code.


I first tried the newest DLL importer, that correctly exported no functions names at all (because the name is thus still in C++ format). Then I tried an older version, which worked somehow, but truncated the result. But it fortunately allowed me also to suddenly see that it still was in C++ format (instead of the usual format)).

Also tried Borland impdef.exe, and Microsoft Visual Studio dumpbin.exe, but never saw the wanted output format of the function names appearing, though it shows still all that it just exports the function names at least (though in the 'strange' format thus).

I tried all kind of things (e.g. adding 'WINAPI', adding of removing 'EXPORT' versus '__declspec(dllexport)', ...
But maybe some setting later in the files overwrites somehow the initial settings, I might have to single step debug through it some time.

As a next step, I will now go carefully go through the steps in e.g. that URL tutorial and see what that gives.

Thanks,

with friendly greetings,
Knud van Eeden
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by knudvaneeden on Sep 20th, 2009, 12:52pm

on Sep 20th, 2009, 12:30pm, Michael Hutton wrote:
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.


Yes, I will also try that further, did already some trials creating .def file earlier.

http://msdn.microsoft.com/en-us/library/d91k01sh(VS.80).aspx

The problem at this moment is to find out how to tell Visual Studio 2005 in the GUI settings where to find this .def file, and the format to use.

I tried earlier to put the .def file (with the same name as the project, and extension thus .def) in the same directory as the .h files to include, compiled, then checked the function names (after e.g. exchanging @6 and @8 (which should be the order numbers of that function in the DLL, that is the sixth and the eighth)). That exchanging seemed to work at the first quick glance, at least exchanging the order. But the function names were still in that C++ like format.

I will check further (also) along this path.

Thanks,

with friendly greetings,
Knud van Eeden
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by JonR on Sep 20th, 2009, 12:55pm

Is your compilable source code available? Preferably the whole project.
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by knudvaneeden on Sep 20th, 2009, 2:07pm

on Sep 20th, 2009, 12:55pm, JonR wrote:
Is your compilable source code available? Preferably the whole project.


Sure, see http://www.knudvaneeden.com/tinyurl.php?urlKey=url000345

with friendly greetings,
Knud van Eeden
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by knudvaneeden on Sep 20th, 2009, 3:08pm

on Sep 20th, 2009, 12:30pm, Michael Hutton wrote:
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.


Maybe create a Wiki about how you created the DLLs (generalizing, ..., simple steps 1, 2, 3, ...), so that that information is conserved and reusable for other projects? That would be great. Otherwise show it here maybe? (e.g. in a separate thread).

Thanks,

with friendly greetings,
Knud van Eeden


Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by knudvaneeden on Sep 20th, 2009, 10:13pm

on Sep 20th, 2009, 3:08pm, knudvaneeden wrote:
...simple steps...


Here e.g.g about creating a simple DLL (as a spin-off of doing further testing about how to create D3DX8BBC.dll)

http://www.knudvaneeden.com/tinyurl.php?urlKey=url000350

with friendly greetings,
Knud van Eeden

Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by Michael Hutton on Sep 20th, 2009, 11:51pm

Knud,

I must admit I don't really feel qualified yet. I expanded in the PerlinDLL by loading in the solution file to VC++E and then typing in a new function and adding a few lines of code which "look right". I built it and it worked, albeit resulting in a file about 7x larger! I do not think that I should be writing any "how to" guides yet!!

I will have a deeper look at the DirectDXD3 dll now I *think* I understand a little bit more about what is going on, but please don't expect anything from this end very soon.

Michael
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by admin on Sep 21st, 2009, 11:42am

Quote:
looking at the ASM output the code seems *very* inefficient

The key word there is "seems"; have you actually compared the timings? I don't know about Visual C, but gcc, with the maximum level of optimisation, can sometimes generate code which outperforms 'naive' hand-written assembler, the reason being that it understands the CPU's internal architecture better.

Don't be too quick to judge the code the compiler generates on the basis of what it looks like to you!

Quote:
It is interesting to see the way the compiler will translate c = (r << 16) || (g <<8) || b and compare to c = (r << 16) + (g <<8) + b

But this is a meaningless comparison. The first is using Boolean logic and the second is using arithmetic.

Surely, to make any kind of sensible comparison the first should be:

Code:
c = (r << 16) | (g <<8) | b 

that is, single | (bitwise OR) rather then double || (Boolean OR) operators. With that change I would be surprised if the code was radically different from the addition example.

If you're at a stage of learning C that you still confuse | and || you've got a very long way to go!

Richard.
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by admin on Nov 30th, 2009, 08:25am

If you want something doing, do it yourself! I installed Visual Studio 2008 Express on my Vista machine and, despite never having used it before, within a few hours I'd successfully built a complete D3DX8BBC.DLL. I was surprised how easy it was, especially considering some of the earlier comments made in this thread. I had no problems with 'name decoration', and did not need to create a .def file.

One thing I made a particular point of doing was to keep the source file as d3dx8bbc.c rather than renaming it as .cpp so whether that helped I don't know.

I've uploaded the hopefully functional, but largely untested, version of D3DX8BBC.DLL here:

http://groups.yahoo.com/group/bb4w/files/Libraries/D3DX8BBC.dll

This exports 199 functions in total, including those implemented in C++ (which were the ones I couldn't incorporate using GCC). It should be functionally equivalent to Microsoft's D3DX8D.DLL but is slightly smaller (not being a Debug version) and - most importantly - should be entirely legitimate to distribute.

It has had virtually no testing, so I would welcome reports of any problems such as missing functions or incorrect behaviour.

Richard.

Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by admin on Dec 1st, 2009, 10:05pm

As a test of the DLL I've written this program:

http://groups.yahoo.com/group/bb4w/files/Graphics/tumblingteapot.bbc

It requires the DLL to have been downloaded to your LIB folder:

http://groups.yahoo.com/group/bb4w/files/Libraries/D3DX8BBC.dll

Those 3D graphics enthusiasts who have been stymied by the absence of D3DX support (at least, 'legal' D3DX support) can now make progress.

Richard.
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by admin on Dec 4th, 2009, 5:21pm

D3DX8BBC.DLL has a dependency on the C run-time library MSVCR90.DLL. Unfortunately, unlike MSVCRT.DLL (which is present on every Windows system from Win98 onwards), some PCs appear not to have MSVCR90.DLL installed.

Therefore I've uploaded a new version of D3DX8BBC.DLL without the dependency (although it increases the file size somewhat):

http://groups.yahoo.com/group/bb4w/files/Libraries/D3DX8BBC.dll

I've also updated the Tumbling Teapot executable to use this new version:

http://groups.yahoo.com/group/bb4w/files/Graphics/tumblingteapot.exe

Richard.
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by Michael Hutton on Jan 13th, 2010, 11:52am

Quote:
It has had virtually no testing, so I would welcome reports of any problems such as missing functions or incorrect behaviour.


I couldn't seem to find the D3DXCreateText function in the dll. Is this only with the DirectX9 version ? (I am currently downloading the "old" DirectX8 SDK to check).

Michael
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by Michael Hutton on Jan 13th, 2010, 12:22pm

Doh. They are there as

D3DXCreateTextA - ANSI version

and
D3DXCreateTextW - UNICODE version

Should have thought of that before..

Michael
Re: Creating D3DX8BBC.DLL for BBCBASIC for Windows
Post by Michael Hutton on Jan 28th, 2010, 12:40pm

I noticed that

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

is missing from the temp folder... Can we have it back?!

Michael