Page 1 of 2
Use .NET Classes with PureBasic (COMmate & Disphelper)
Posted: Mon Nov 23, 2009 9:52 pm
by fsw
After seing on the internet that others have successfully connected their programming language with .NET I thought I give it a shot with PureBasic and translated an example...
Using the DispHelper lib (works fine):
Code: Select all
dhToggleExceptions(#True)
Procedure DownLoadWebImage(szURL.s, szFileName.s)
Protected objHTTP.l
objHTTP = dhCreateObject("System.Net.WebClient")
If objHTTP
dhCallMethod(objHTTP,".Downloadfile (%s,%s)",@szURL, @szFileName)
dhReleaseObject(objHTTP)
ProcedureReturn #True
EndIf
EndProcedure
If DownLoadWebImage("http://www.purebasic.fr/english/styles/subsilverPlus/imageset/purebasic_logo.png", "h:\purebasic_logo.png")
MessageRequester("Info", ".NET component called successfully.")
Else
MessageRequester("Error", ".NET component called unsuccessfully!")
EndIf
EDIT:
see srod's code to get it to work with COMmate.
thanks srod
Now there is no one stopping you to use some of the .NET classes to get the job done.
Take care...
fsw
Re: Use .NET Classes with PureBasic
Posted: Mon Nov 23, 2009 11:11 pm
by srod
Code: Select all
IncludePath "..\"
XIncludeFile "COMatePLUS.pbi"
Procedure DownLoadWebImage(szURL.s, szFileName.s)
Define.COMateObject objHTTP
objHTTP = Comate_CreateObject("System.Net.WebClient")
If objHTTP
objHTTP\Invoke("Downloadfile('" + szURL + "', '" + szFileName + "')")
objHTTP\Release()
ProcedureReturn #True
EndIf
EndProcedure
If DownLoadWebImage("http://www.purebasic.fr/english/styles/subsilverPlus/imageset/purebasic_logo.png", "h:\purebasic_logo.png")
MessageRequester("Info", ".NET component called successfully.")
Else
MessageRequester("Error", ".NET component called unsuccessfully!")
EndIf
Re: Use .NET Classes with PureBasic
Posted: Mon Nov 23, 2009 11:56 pm
by Kiffi
srod wrote:Code: Select all
objHTTP = Comate_CreateObject("System.Net.WebClient")
doesn't work for me.
COMate_GetLastErrorDescription wrote:Invalid progID/CLSID. Check your spelling of the programmatic identifier. Also check that the component / ActiveX control has been registered.
I would be surprised if it were that simple.
Greetings ... Kiffi
Re: Use .NET Classes with PureBasic
Posted: Tue Nov 24, 2009 12:36 am
by fsw
Kiffi wrote:srod wrote:Code: Select all
objHTTP = Comate_CreateObject("System.Net.WebClient")
doesn't work for me.
COMate_GetLastErrorDescription wrote:Invalid progID/CLSID. Check your spelling of the programmatic identifier. Also check that the component / ActiveX control has been registered.
I would be surprised if it were that simple.
Greetings ... Kiffi
maybe you have to register the dll first.
The command line is:
regasm System.dll
regasm should reside in your .net directory (2.0 dir on my system, even if 3.5 is installed)
Hope this gets you going.
Re: Use .NET Classes with PureBasic
Posted: Tue Nov 24, 2009 1:43 am
by Kiffi
fsw wrote:Hope this gets you going.

It works!
I never thought, that it is
so easy to call a function out of a dotnet-assembly.
I've always assumed that this is not possible because dotnet-DLLs have no COM-Interfaces.
Thanks a lot for your hint & Greetings ... Kiffi
Re: Use .NET Classes with PureBasic (COMmate & Disphelper)
Posted: Tue Nov 24, 2009 8:50 am
by srod
@fsw, did the COMate code work okay? I can't test as I cannot locate the system.dll assembly even though IE8 tells me I have .Net 2, 3 and 3.5 installed; none of which I have actually installed myself!

Re: Use .NET Classes with PureBasic (COMmate & Disphelper)
Posted: Tue Nov 24, 2009 8:59 am
by LuckyLuke
@srod : COMate code is okay.
Location of System.dll : C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
Re: Use .NET Classes with PureBasic (COMmate & Disphelper)
Posted: Tue Nov 24, 2009 9:27 am
by srod
LuckyLuke wrote:@srod : COMate code is okay.
Location of System.dll : C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
Got it. Thanks.

Re: Use .NET Classes with PureBasic (COMmate & Disphelper)
Posted: Tue Nov 24, 2009 1:43 pm
by Rings
very nice
Re: Use .NET Classes with PureBasic (COMmate & Disphelper)
Posted: Tue Nov 24, 2009 2:55 pm
by SFSxOI
Oooooo...ahhhhh...I can't wait to try this. Thank you very much

Re: Use .NET Classes with PureBasic (COMmate & Disphelper)
Posted: Tue Nov 24, 2009 5:34 pm
by Kiffi
Code: Select all
Define.COMateObject oForm
oForm = COMate_CreateObject("System.Windows.Forms.Form")
If oForm
oForm\SetProperty("Text = 'I am a .Net-Window!'")
oForm\Invoke("ShowDialog()")
oForm\Release()
Else
Debug "?"
Debug COMate_GetLastErrorDescription()
EndIf
Unfortunately i find no solution for adding controls (button, etc.) to the form.controls-collection
Greetings ... Kiffi
Re: Use .NET Classes with PureBasic (COMmate & Disphelper)
Posted: Tue Nov 24, 2009 5:57 pm
by fsw
Kiffi wrote:
Unfortunately i find no solution for adding controls (button, etc.) to the form.controls-collection
Greetings ... Kiffi
There seems to be a limitation in regards of classes that can (or cannot) be used by non .NET languages.
Apparently there are some static classes that cannot be accessed that easily (if ever...).

Re: Use .NET Classes with PureBasic (COMmate & Disphelper)
Posted: Tue Nov 24, 2009 5:59 pm
by fsw
srod wrote:LuckyLuke wrote:@srod : COMate code is okay.
Location of System.dll : C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
Got it. Thanks.

Yes srod,
worked like a charm.
Don't know how far this can be pushed though...
Thanks
Re: Use .NET Classes with PureBasic (COMmate & Disphelper)
Posted: Tue Nov 24, 2009 6:18 pm
by fsw
srod wrote:... I can't test as I cannot locate the system.dll assembly even though IE8 tells me I have .Net 2, 3 and 3.5 installed; none of which I have actually installed myself!

On my machine (running WindowsXPsp3) there are 2 located at:
c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\
and
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\
fsw
Re: Use .NET Classes with PureBasic (COMmate & Disphelper)
Posted: Tue Nov 24, 2009 10:39 pm
by luis
Interesting, nice work !
Thank you
