Results 1 to 4 of 4

Thread: creating DLL that imports OS DLL functions

  1. #1

    creating DLL that imports OS DLL functions

    Hello Charles,
    I'm still plugging along and trying different things with oxygen.

    Here I changed the chatter.dll to utilize the MessageBox Win32 function (instead of the build in print function)
     #basic
     
     #file `chatter.dll`
    
    'dim as long user32 = LoadLibrary "user32.dll"
    'bind user32 (
    '  MessageBox    MessageBoxA    : @16
    ')
    
    declare function MessageBox lib `user32.dll` alias `MessageBoxA` (byval as long,
                byval as string, byval as string, byval as long) as long  
    
    
     '-------------------------------------
     class greeting alias `greeting` export
     '=====================================
      method hello(n as string)
      method goodbye(n as string)
      /  
     end class
     
      
     methods of greeting
     
      method hello(n as string)
       print ` Hello ` n
      end method
    
      method goodbye(n as string)
       dim txt as string
       txt = ` Goodbye `
       'print ` Good bye ` n
       MessageBox(0, n, txt, 0)
      end method
         
      
     end methods 'of greeting
    
    But it crashes

    Here the code to use the chatter.dll
     #basic
     '------------------------------------------------
     class greeting lib `chatter.dll` alias `greeting`
     '================================================
       method hello(n as string) 
      method goodbye(n as string)
      /  
     end class
    
     
     dim g as greeting
     g.goodbye `moon`
     g.hello `earth`
     
     xit:
     terminate
    
    Is this a limitation of oxygen's alpha state?

    Thanks
    efgee

  2. #2

    Re: creating DLL that imports OS DLL functions


    Hi efgee,

    I think this problem is specific to class libraries. I was able to use MessageBox within normal DLL
    exported functions, but not classes. I am giving this area a thorough workout.

    Charles

  3. #3

    Re: creating DLL that imports OS DLL functions

    The solution was to declare the class library as extern. I have tweaked the syntax to remove unnecessary flags / directives. (link below).

    This pair should now work correctly. ThinBasic example in examples/OOP/ClassLibrary

    [code=thinbasic]
    '-------------
    'CLASS LIBRARY
    '=============

    #basic

    #file `chatter.dll`

    extern

    declare function MessageBox lib `user32.dll` alias `MessageBoxA` (byval as long,
    byval as string, byval as string, byval as long) as long


    '-------------------------------------
    class greeting export 'alias "greeting" export
    '=====================================
    method hello(n as string)
    method goodbye(n as string)
    /
    a as long
    end class


    methods of greeting

    method hello(n as string)
    print ` Hello ` n
    end method

    method goodbye(n as string)
    messagebox 0,n,"Goodbye",0
    end method


    end methods 'of greeting


    function foo (n as string) export
    messagebox 0,n,"ms",0
    end function

    end extern
    [/code]

    [code=thinbasic]
    #basic

    extern lib "chatter.dll"

    '------------------------------
    class greeting 'alias "greeting"
    '==============================
    method hello(n as string)
    method goodbye(n as string)
    /
    a as long
    end class

    declare function foo(n as string)

    end extern

    dim g as greeting

    g.goodbye `moon`
    g.hello `earth`

    foo "Hi"

    [/code]


    Latest Oxygen

    http://community.thinbasic.com/index.php?topic=2517


  4. #4

    Re: creating DLL that imports OS DLL functions

    Charles,
    works fine now.

    Thank you for your fast response
    efgee

Similar Threads

  1. Creating models
    By Petr Schreiber in forum TBGL General
    Replies: 42
    Last Post: 20-04-2007, 03:58

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •