----------------------------------------------------------------------
--- Knud van Eeden --- 20 September 2009 - 11:06 pm ------------------

BBCBASIC for Windows: DLL: Simple: Operation: Create: How to: How to create a simple DLL using Microsoft Visual Studio 2005, and use it in BBCBASIC for Windows?

===

Usually you get ready DLLs to use.

---

Optionally you want to create this DLLs yourself for use in BBCBASIC for Windows.
You can e.g. use Microsoft Visual Studio 2005 or the free 'Express' version for that.

---

In some cases you could decide to create a DLL yourself, then this could be possible
steps to follow (if you use Microsoft Visual Studio 2005).

===

The PDF file contains screenshots to further clarify.

===

Steps: Overview:

 1. -Run the program

      Visual Studio 2005

 2. -Create a new project

     1. -Select from menu option 'File'

     2. -Select from list 'New'

     3. -Project

 3. -Create a new DLL

     1. -In the left pane click on 'Visual C++'

     2. -Select from list 'Win32'

     3. -In the right pane click on 'Win32 Project'

     4. -Click button 'Next'

     5. -Enable radio button 'DLL

     6. -Click button 'Finish'

 4. -Source code and files are generated automatically

 5. -Optionally change the properties of your project

     1. -In the left pane click on the file from which you want
         to change the properties
         (the properties which you will see will depend on the
          file you have clicked on. E.g. the .cpp file has e.g. different
          properties to choose from than other files in the project)

     2. -Select from menu option 'Project'

     3. -Select from list 'Properties'

     4. -Change the involved properties

 6. -Create your functions which you want to export from your .DLL file

 7. -Put this function source code at the end of the .cpp file in your project

 8. -Optionally create a .DEF function

     (this file will allow you to add some extra information about the
      functions you want to export in your project. E.g. its names)

     1. -Select from menu option 'Project'

     2. -Select from list 'Add new item'

     3. -In the left pane click on 'Code'

     4. -In the right pane click on 'Module-Definition file (def)'

     5. -Type the .def filename

     6. -Click button 'Add'

     7. -This will create that .def file, and fill in the text

--- cut here: begin --------------------------------------------------
LIBRARY <your .def filename>
--- cut here: end ---------------------------------------------------- 8. -You will then manually have to add your function names in this file --- cut here: begin --------------------------------------------------
LIBRARY <your .def filename> EXPORTS <your function name 1> <your function name 2> <your function name 3> <your function name 4> <your function name 5> ... <your function name last>
--- cut here: end ---------------------------------------------------- 9. -Build your DLL file 1. -Optionally change the type from 'Debug' (that means you are still developing and debugging the DLL) to 'Release' (that means you think you can are finished debugging the .DLL) -If you keep it on the default 'Debug' (which is the default), file output will go to a directory called 'Debug' in your project directory -If you change it to 'Release), file output will go to a directory called 'Release' in your project directory -Thus if you used and 'Debug' and 'Create' then there will at the end exist 2 different directories (containing possibly similar files) in your project directory 2. -Select from menu option 'Build' 3. -Select from list 'Build Solution' 10. -If everything goes OK, and there are no errors, your .DLL file is created in your project directory 11. -Use your DLL file in BBCBASIC for Windows 1. -Copy DLL to where BBCBASIC for Windows can find it Usually copy this dll to e.g. 1. -the BBCBASIC for Windows lib directory (in which case you usually will put the @lib$ in front of the DLL filename) 2. -Another directory where BBCBASIC for Windows can find the DLL file when it searches for it E.g. <your Windows directory>\system32 2. -E.g. create the following BBCBASIC for Windows program: --- cut here: begin --------------------------------------------------
REM file$ = @lib$ + "<your DLL filename>.dll" : REM in this case it expects to find that file in the 'lib' directory file$ = "<your DLL filename>.dll" : REM in this case it expects to find that file in the path or e.g. the c:\windows\system32 directory REM this loads the DLL SYS "LoadLibrary", file$ TO dll% REM the loading failed, show some arbitrary error message indicating this IF ( dll% = 0 ) THEN ERROR 100,"Cannot load dll"
--- cut here: end ---------------------------------------------------- 2. -Run the program 3. -If you do not see an error message, that means the DLL is loaded in memory 12. -Then test e.g. the function you want to export and use in your BBCBASIC for Windows program 1. -E.g. create the following BBCBASIC for Windows program: --- cut here: begin --------------------------------------------------
PROC_ImportDLLs SYS _RetrieveTempFilename% END : : : DEF PROC_ImportDLLs LOCAL _%,_hdll% SYS "GetModuleHandle", "kernel32.dll" TO _hdll% SYS "GetProcAddress", _hdll%, "GetProcAddress" TO _% SYS "LoadLibrary", @lib$ + "MakeTempFilenameDLL2005.dll" TO _hdll% IF _hdll%=0 THEN PRINT "Warning: A required DLL 'MakeTempFilenameDLL2005.dll' could not be found." SYS _%, _hdll%, "RetrieveTempFilename" TO _RetrieveTempFilename% ENDPROC
--- cut here: end ---------------------------------------------------- 2. -Run the program 3. -That will show a screen output similar to the following: --- cut here: begin --------------------------------------------------
Address out of range >
--- cut here: end ---------------------------------------------------- 4. -But that result because of the export function source code you used (which generated an 'address out of range' for the BBCBASIC for Windows program) 13. -Tested successfully on Microsoft Windows XP Professional (service pack 3), running BBCBASIC for Windows v5.90b === Book: see also: === Diagram: see also: === File: see also: 01.pdf === File: version: control: see also: === Help: see also: === Image: see also: === Internet: see also: --- How to Create a Simple Win32 DLL Using Visual C++ 2005 http://www.kapilik.com/2007/09/17/how-to-create-a-simple-win32-dll-using-visual-c-2005/ --- Computer: Editor: Text: TSE: DLL: Link: Can you give an overview of links? http://goo.gl/KrBMn === Podcast: see also: === Record: see also: === Screencast: see also: === Table: see also: === Video: see also: === <version>1.0.0.0.2</version> ----------------------------------------------------------------------

Share |

This web page is created and maintained using the Semware TSE text editor