No announcement yet.

Using C# DLLs in PBCC apps

  • Filter
  • Time
  • Show
Clear All
new posts

  • Using C# DLLs in PBCC apps


    I have plans to create a console version of a GUI application I am developing in C# 2005.NET. Obviously I want to write the console version in PowerBASIC Console Compiler. I use 4.03.

    Is it correct that DLLs produced by C# (which I believe - but I am not sure - are ActiveX DLLs, just like good old VB6 produced, but that require the .NET framework to load) can not (easily) be utilized by PowerBASIC Console Compiler 4.03 programs? I did several searches on this forum and came across some old posts claiming this is not possible, but most of those messages where written for old PBCC and VB versions.

    I don't feel much for rewriting the core-part of the application in a different language, so my only option would be to find a language that can produce wrappers around ActiveX DLLs then, wouldn't it?

    Thanks for your help!

    Best regards,


    [This message has been edited by Vincent van der Leun (edited August 27, 2007).]

  • #2
    i came across the following microsoft knowledge base article ("how to call a managed dll from native visual c++ code in visual or in visual studio 2005") at

    i will experiment with the powerbasic com browser to see if c# dlls are compatible with pbcc or not.
    if the info mr lance edmonds wrote in this 2002 topic is still valid, then i
    guess i am out of luck. i doubt c# generates com component that acts as automation server.


    [this message has been edited by vincent van der leun (edited august 27, 2007).]


    • #3
      You need to create a COM Callable Wrapper using the Assembly Registration
      Tool (Regasm.exe). See:

      SED Editor, TypeLib Browser, COM Wrappers.


      • #4
        Thanks for the link, José!

        I made some great progress and it looks very promising. There's much to find out, but that is part of the fun!

        I made the sample DLL mentioned in the MS Knowlegde Base article in C# and tried to open it in PowerBASIC COM Browser. Much to my relief, no error messages appeared.
        Eventually I added a Test() method to the ICalculator-interface and added the method to the "ManagedClass" (which implements this ICalculator interface).
        The Test() method loads and shows a simple modal form.

        I can't get the DLL to work in early binding mode yet (my preffered method), but using late binding it works like a charm though.

        For clarity I'll cut & paste the output of the PB COM Browser here:

        ' ------------------------------------------------------------
        ' Library File: C:\Documents and Settings\Vincent\Mijn documenten\Visual Studio 2005\Projects\sManagedDLL\sManagedDLL\bin\Debug\ManagedDLL.tlb
        ' ------------------------------------------------------------
        ' ProgID: sManagedDLL.Form1
        ' Interface Name: sManagedDLLForm1
        ' ProgID: sManagedDLL.ManagedClass
        ' Interface Name: sManagedDLLManagedClass
        ' Interface Prefix: sManagedDLL
        ' ------------------------------------------------------------

        $PROGID_sManagedDLLForm1 = "sManagedDLL.Form1"
        $PROGID_sManagedDLLManagedClass = "sManagedDLL.ManagedClass"

        Interface Dispatch sManagedDLLForm1
        'This is a restricted interface.
        End Interface

        Interface Dispatch sManagedDLLManagedClass
        'This is a restricted interface.
        End Interface

        Interface Dispatch sManagedDLLICalculator
        Member Call Test<&H60020000>()
        Member Call Add<&H60020001>(in Number1 As Long<&H00000000>, in Number2 As Long<&H00000001> ) As Long
        End Interface


        Using late binding mode, I can simply say the following in a PBCC app:


        DIM oTest AS DISPATCH
        LET oTest = NEW DISPATCH IN "sManagedDLL.ManagedClass"
        PRINT "Error: " + STR$(ERR)
        PRINT "IsObject: " + STR$(ISOBJECT(oTest))

        'Test the Test() method
        OBJECT CALL oTest.Test()

        'Test the Add(long1, long2) method
        lngValue1 = 1
        lngValue2 = 2
        varResult = 0
        OBJECT CALL oTest.Add(lngValue1, lngValue2) TO varResult
        PRINT "Error: " + STR$(ERR)
        PRINT "Result: " + STR$(VARIANT#(varResult))


        I'd rather use early binding though.
        The part I don't understand is the following: How can I tell PB in early binding mode that the "sManagedDLLManagedClass" class
        implements the sManagedDLLICalculator-interface? Or is this not possible because the sManagedDLLManagedClass is "restricted" (whatever that means...) according
        to the PB COM Browser, and can this DLL only be used in late binding mode because of that?

        When using:


        DIM OTest2 AS sManagedDLLManagedClass
        LET Otest2 = NEW sManagedDLLManagedClass IN $PROGID_sManagedDLLManagedClass
        OBJECT CALL oTest2.Test()


        The third line obviously does not work, as PB apparently does not know that sManagedDLLManagedClass implements the ICalculator interface and generates a compile-time error as expected.

        Someone any tips on how to fix this?
        I can definitely live with late binding, but I am curious whether I am missing something here.

        Many thanks again for any help!