IT-Consultant: José Roca (PBWIN 10+/PBCC 6+) (Archive only) > COM Programming
Calling .NET classes from PowerBASIC
José Roca:
Well. Apparently you can create dual interfaces adding another attribute to all your public classes:
--- Code: ---VB.NET: <ClassInterface(ClassInterfaceType.AutoDual)>
C#: [ClassInterface(ClassInterfaceType.AutoDual)]
--- End code ---
Petr Schreiber:
José Roca Rocs again!
Good tip, it works perfectly now.
I can even see ( and use ) methods it inherits from System.Object, such as ToString().
Just have to not forget using ACODE$ for converting string values :)
Thank you,
Petr
José Roca:
Here is the link for the .NET Framework 4:
http://msdn.microsoft.com/en-us/library/tzat5yw6.aspx
--- Quote ---Just have to not forget using ACODE$ for converting string values
--- End quote ---
This, of course, no longer applies to PBWIN 10 / PBCC 6, that have native unicode support.
Mike Doty:
Automatically register system.dll
Thank you! Opens up so many possibilities.
--- Code: ---#DIM ALL
REM #INCLUDE "win32api.inc" 'for shellexecute
#INCLUDE "shellapi.inc" 'for shellexecute
'http://www.jose.it-berater.org/smfforum/index.php?topic=3053.0
' ########################################################################################
' The following example creates an instance of the "System.Net.WebClient" class to
' download a picture from an URI and save it to a file.
' ########################################################################################
FUNCTION Regasm AS LONG 'only need this code once
LOCAL sDllPath AS STRING
sDllPath = "C:\Windows\Microsoft.NET\Framework\v2.0.50727\"
IF ISFILE(sDllPath + "system.dll") THEN
SHELL sDLLPath + "regasm.exe system.dll
FUNCTION = 1 'success
ELSE
? "system.dll not found"
END IF
END FUNCTION
FUNCTION PBMAIN () AS LONG
IF RegAsm = 0 THEN EXIT FUNCTION
LOCAL zFileName AS STRINGZ * 256
LOCAL owc AS DISPATCH
LOCAL vAddress AS VARIANT
LOCAL vFileName AS VARIANT
owc = NEWCOM "System.Net.WebClient"
IF ISOBJECT(owc) THEN
TRY
vAddress = "http://www.jose.it-berater.org/webpages_images/h_2.jpg"
vFileName = EXE.PATH$ & "h_2.jpg"
OBJECT CALL owc.DownloadFile(vAddress, vFileName)
owc = NOTHING
'display using default viewer
zFileName = EXE.PATH$ & "h_2.jpg"
ShellExecute (%NULL, "OPEN", zFileName, BYVAL %NULL, CURDIR$, %SW_SHOWNORMAL)
CATCH
IF OBJRESULT = &H80020009 THEN
MSGBOX "Error &H" & HEX$(IDISPINFO.CODE) & $CRLF & IDISPINFO.DESC$
ELSE
MSGBOX "Error &H" & HEX$(OBJRESULT)
END IF
END TRY
ELSE
? "ISOBJECT FAILED"
END IF
END FUNCTION'
--- End code ---
Navigation
[0] Message Index
[*] Previous page
Go to full version