PDA

View Full Version : creating DLL that imports OS DLL functions



efgee
06-09-2010, 05:20
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 :unguee:

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

Charles Pegge
06-09-2010, 12:03
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

Charles Pegge
06-09-2010, 18:54
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



'-------------
'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




#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"




Latest Oxygen

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

efgee
06-09-2010, 21:12
Charles,
works fine now.

Thank you for your fast response
efgee