Using .Net classes

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
phishguy
Posts: 1201
Joined: May 05, 2006 16:12
Location: West Richland, Wa

Using .Net classes

Post by phishguy »

I was browsing the BCX forum and ran across this post.
http://basic-compiler.com/forum/index.p ... topic=35.0

So, it appeared as though it's possible to convert .Net classes to work with a COM interface. There was an example posted for PB and BCX. I converted for use with Freebasic.

Code: Select all

' Modified for Freebasic by phishguy

'----------------------------------------------------------------------------
'                  Calling .NET classes from BCX
'----------------------------------------------------------------------------
'First, install the latest .Net Framework from Microsoft then
'run C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regasm system.dll
'----------------------------------------------------------------------------
'http://www.jose.it-berater.org/smfforum/index.php?topic=3053.msg9447#msg9447
'----------------------------------------------------------------------------
#Define unicode
#include once "disphelper\disphelper.bi"


DIM  shared owc AS IDispatch Ptr 
DIM  vAddress as string
DIM  vFileName as string
dhInitialize(TRUE)
dhToggleExceptions(TRUE)
 
dhCreateObject("System.Net.WebClient",null,@owc)
 
vAddress = "http://www.bcxgurus.com/bcxlogo.jpg"
 
vFileName = CURDIR + "\bcxlogo.jpg"

dhcallmethod(owc,".Downloadfile (%s,%s)",vAddress,vFilename)

SAFE_RELEASE(owc)
dhUninitialize(TRUE)

sleep
 

 
joseywales72
Posts: 206
Joined: Aug 27, 2005 2:02
Location: Istanbul, Turkey

Post by joseywales72 »

I suppose it is not possible to use Mono this way. Disphelper is a Windows only library. It would be nice to design GUIs etc. with Mono on Linux.
I'll try when I'm on Windows though. Thank you.
AGS
Posts: 1284
Joined: Sep 25, 2007 0:26
Location: the Netherlands

Post by AGS »

joseywales72 wrote:I suppose it is not possible to use Mono this way. Disphelper is a Windows only library. It would be nice to design GUIs etc. with Mono on Linux.
I'll try when I'm on Windows though. Thank you.
Perhaps this will help a bit:
http://www.mono-project.com/Embedding_Mono

So what you do is embed the Mono interpreter and then:
- call Mono routines from FB;
- call FB routines from Mono.

You'll need some C header files to get the embedding done (I don't think FB comes with Mono header files).

Or you can try cilc.
cilc is the Mono CIL-to-C binding generator. It takes a CIL assembly as input and generates a directory of C sources which, when compiled, provide a C interface to the classes contained within that assembly by means of a shared object library.

Generated sources make use of the Mono embedding API. Thus a complete Mono development environment must be available on the development system and a complete Mono runtime environment must be available on target systems.
You'd need a C compiler to produce the library (not a problem on Linux). The routines inside the library should be callable from FreeBASIC.
Post Reply