Disphelper is a COM helper library that can be used in plain C. No MFC or ATL is required. It allows you to call COM objects with an easy printf style syntax.
Website: http://disphelper.sourceforge.net/
Platforms supported: Win32, Linux (using WINE)
Headers to include: disphelper/disphelper.bi
Header version: from 2005
Example
'' HTTP GET example, using MSXML2
#define UNICODE
#include "disphelper/disphelper.bi"
DISPATCH_OBJ(objHTTP)
dhInitialize(TRUE)
dhToggleExceptions(TRUE)
dhCreateObject("MSXML2.XMLHTTP.4.0", NULL, @objHTTP)
dhCallMethod(objHTTP, ".Open(%s, %s, %b)", "GET", "http://sourceforge.net", FALSE)
dhCallMethod(objHTTP, ".Send")
Dim As ZString Ptr szResponse
dhGetValue("%s", @szResponse, objHTTP, ".ResponseText")
Print "Response: "; *szResponse
dhFreeString(szResponse)
SAFE_RELEASE(objHTTP)
dhUninitialize(TRUE)
'' IExplorer example
#define UNICODE
#include "disphelper/disphelper.bi"
Sub navigate(ByRef url As String)
DISPATCH_OBJ(ieApp)
dhInitialize(TRUE)
dhToggleExceptions(TRUE)
dhCreateObject("InternetExplorer.Application", NULL, @ieApp)
dhPutValue(ieApp, "Visible = %b", TRUE)
dhCallMethod(ieApp, ".Navigate(%s)", url)
SAFE_RELEASE(ieApp)
dhUninitialize(TRUE)
End Sub
navigate("www.freebasic.net")
'' VB Script example
#define UNICODE
#include "disphelper/disphelper.bi"
'' This function runs a script using the MSScriptControl.
'' Optionally returns a result.
Sub RunScript _
( _
ByVal result_identifier As LPWSTR, _
ByVal result As LPVOID, _
ByVal script As LPWSTR, _
ByVal language As LPWSTR _
)
DISPATCH_OBJ(control)
If (SUCCEEDED(dhCreateObject("MSScriptControl.ScriptControl", NULL, @control))) Then
If (SUCCEEDED(dhPutValue(control, ".Language = %T", language))) Then
dhPutValue(control, ".AllowUI = %b", TRUE)
dhPutValue(control, ".UseSafeSubset = %b", FALSE)
If (result) Then
dhGetValue(result_identifier, result, control, ".Eval(%T)", script)
Else
dhCallMethod(control, ".Eval(%T)", script)
End If
End If
End If
SAFE_RELEASE(control)
End Sub
dhInitialize(TRUE)
dhToggleExceptions(TRUE)
'' VBScript sample
RunScript(NULL, NULL, !"MsgBox(\"This Is a VBScript test.\" & vbcrlf & \"It worked!\",64 Or 3)", "VBScript")
'' JScript sample
Dim As Integer result
RunScript("%d", @result, "Math.round(Math.pow(5, 2) * Math.PI)", "JScript")
Print "Result ="; result
Print "Press any key to exit..."
Sleep
dhUninitialize(TRUE)