Results 1 to 21 of 21

Thread: .NET_ForVB6.dll【COM-Wrapper Library With .netFrameWork】Like Rc6.dll

  1. #1

    Thread Starter
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    .NET_ForVB6.dll【COM-Wrapper Library With .netFrameWork】Like Rc6.dll

    How to create all VB. Net controls dynamically with VB6?
    It would be nice to be able to create controls, objects, and run code dynamically.

    Without installing the VB6 development environment, when I try to dynamically load the third-party control OCX in the compiled EXE, I also need to add a license.
    Maybe the VB6 IDE will automatically add the license to the EXE when editing components after adding components

    If you want to add treeview control to excl VBA, access vba form, you need to add the component Microsoft Windows Common Controls 6.0 (SP6), and you need to obtain a license.
    In theory, you have to pay to get the power to design in the IDE.
    Using a middleware method, although it is not as simple as dragging and dropping controls directly, it does not require authorization and does not require payment, which is very useful.
    ===============

    Yes, under normal circumstances, you have to purchase expensive VS2019 development tools, which may take up 10-50G of space after installation.
    In this way, even the control license is not needed. It can be perfect to use its functions without installing the .NET development environment. If you want to use multiple versions of .NET environment, you only need to compile into VBNetFramework2.dll, VBNetFramework4.dll.
    It can also be made into a control mode to load the control without registration. In the control, you can dynamically create .NET COM objects, you can also dynamically create all the controls of .NET, you can also dynamically edit and run, and you can also reflect on the controls on the form.

    But these are mainly for simple usage of some controls, which can satisfy most people's usage scenarios. If you need to write a large amount of VB.NET code project, you can write that part of the code as a separate DLL and then call VB6. You can also wrap a certain VB.NET control, such as DATAGRIDVIEW, and generate the control for VB6 use.
    =======================
    You can use an intermediate VB. Net control and com object.Of course, the best way is to get rid of the. Net intermediate DLL completely

    like this in vb6, vba:
    Code:
    Private Sub Form_Load()
    Dim S As String
    S = SHA512("55", False) & vbCrLf & vbCrLf & SHA512("55", True)
    MsgBox S
    Clipboard.Clear
    Clipboard.SetText S
    
    End Sub
    
    Public Function SHA512(sIn As String, Optional bB64 As Boolean = 0) As String
         
        Dim oT As Object, oSHA512 As Object
        Dim TextToHash() As Byte, bytes() As Byte
         
        Set oT = CreateObject("System.Text.UTF8Encoding")
        Set oSHA512 = CreateObject("System.Security.Cryptography.SHA512Managed")
         
        TextToHash = oT.GetBytes_4(sIn)
        bytes = oSHA512.ComputeHash_2((TextToHash))
         
        If bB64 = True Then
           SHA512 = ConvToBase64String(bytes)
        Else
           SHA512 = ConvToHexString(bytes)
        End If
         
        Set oT = Nothing
        Set oSHA512 = Nothing
         
    End Function
    Private Function ConvToBase64String(vIn As Variant) As Variant
     
        Dim oD As Object
           
        Set oD = CreateObject("MSXML2.DOMDocument")
          With oD
            .LoadXML "<root />"
            .DocumentElement.DataType = "bin.base64"
            .DocumentElement.nodeTypedValue = vIn
          End With
        ConvToBase64String = Replace(oD.DocumentElement.Text, vbLf, "")
         
        Set oD = Nothing
     
    End Function
    Private Function ConvToHexString(vIn As Variant) As Variant
     
        Dim oD As Object
           
        Set oD = CreateObject("MSXML2.DOMDocument")
           
          With oD
            .LoadXML "<root />"
            .DocumentElement.DataType = "bin.Hex"
            .DocumentElement.nodeTypedValue = vIn
          End With
        ConvToHexString = Replace(oD.DocumentElement.Text, vbLf, "")
         
        Set oD = Nothing
     
    End Function
    Last edited by xiaoyao; May 6th, 2021 at 10:35 PM.

  2. #2

    Thread Starter
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: How to create all VB. Net controls dynamically with VB6?

    Dim cpars As Object
    Set cpars = CreateObject("System.CodeDom.Compiler.CompilerParameters")
    'its err
    why This code is ok?
    Set oT = CreateObject("System.Text.UTF8Encoding")

  3. #3

    Thread Starter
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: How to create all VB. Net controls dynamically with VB6?

    Run vb.net Code by vbscript:
    Code:
     '
    Private Sub Command5_Click()
    'save as test.vbs
    'need check x86 or x64
    'x64 call 32bit com dll:
    'c:\windows\SysWOW64\cscript.exe test.VBS
    
    Dim OBJ2
    Set OBJ2 = CreateObject("VB_NetForVB6.NetClass1")
    Dim R
    R = OBJ2.RunCode("return System.Environment.Version")
    MsgBox "Vb.net Version is " & R
    End Sub
    VB.NET CODErun vb.net code from vb6)

    Code:
    Public Function Sum(ByVal a As IntPtr ,ByVal b As IntPtr) As IntPtr'Not support vbs, support VB6
    Return a+b
    End Function
    
    Public Function Sum2(ByVal a As Long ,ByVal b As Long) As Long'Support vbs, not VB6
    'CreateObject("VB_NetForVB6.NetClass1")
    Return a+b
    End Function
    
    public Function RunCode(Vb_NetCode As String ,optional RunOk As Boolean=false, optional HaveResult As Boolean=False) As Object
     Dim cpars As New System.CodeDom.Compiler.CompilerParameters
      
            'Compilation parameters, such as /optimize /removeintchecks, etc.
            cpars.CompilerOptions = "/optimize "
    
            cpars.GenerateInMemory = True'Compile in memory without outputting files
            cpars.GenerateExecutable = False'Do not output executable files
            cpars.IncludeDebugInformation = False'No debugging information is required
    
            'Import class library (import according to the needs of your own code)
            cpars.ReferencedAssemblies.Add("mscorlib.dll")
            cpars.ReferencedAssemblies.Add("System.dll")
            cpars.ReferencedAssemblies.Add("System.Data.dll")
            cpars.ReferencedAssemblies.Add("System.Deployment.dll")
            cpars.ReferencedAssemblies.Add("System.Drawing.dll")
            cpars.ReferencedAssemblies.Add("System.Windows.Forms.dll")
            cpars.ReferencedAssemblies.Add("System.Xml.dll")
            cpars.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll")
    
            'Compile parameters, set a global reference for the imported class library (otherwise you must use the full namespace name to call the function correctly)
            cpars.CompilerOptions &= "/imports:" & _
             "Microsoft.VisualBasic," & _
             "System," & _
             "System.Collections," & _
             "System.Collections.Generic," & _
             "System.Drawing," & _
             "System.Windows.Forms"
    
            'Set up the compiler
            'Dim vbc As New VBCodeProvider'Microsoft.VisualBasic.VBCodeProvider
            
            Dim vbc = System.CodeDom.Compiler.CodeDomProvider.CreateProvider("VisualBasic")
            'Dim vbc = CodeDomProvider.CreateProvider("VisualBasic")' equivalent method
    
            'A simple template class
            Dim codex As String = _
             "Public Class CompClass" & vbCrLf & _
             "Shared Function RunCode() As Object" & vbCrLf & _
             "'$" & vbCrLf & _
             "End Function" & vbCrLf & _
             "End Class"
    
            'Replace the code in the template class
            Dim code As String = codex.Replace("'$",Vb_NetCode)
    
    
            'Compile and return
            Dim resut As CompilerResults = vbc.CompileAssemblyFromSource(cpars, code)
    
            'If an error occurs
            If resut.Errors.Count> 0 Then Return resut.Errors(0).ToString
            'else
            RunOk=True
    
    
            'Try to call the code
            Dim asm As Assembly = resut.CompiledAssembly'Get assembly
    
            'Get the static method we wrote
            Dim mi As MethodInfo = asm.GetType("CompClass").GetMethod("RunCode")
    
            'Execute the code and get the return value
            Dim ret As Object = mi.Invoke(Nothing, Nothing)
    
            'Process the return value
            If ret Is Nothing Then
            Return ""
            else
            'return 3+4
            HaveResult=True
            'MsgBox(ret.ToString)
            Return ret
            End If
    End Function
    Code:
    'VB6 TEST CODE:
    Dim R As String
    'Text1.Text = "return 33+44"
    R = VbNet.RunCode(Text1.Text)
    MsgBox "R2=" & R
    
    Text1.Text = "return System.Environment.Version"
    R = VbNet.RunCode(Text1.Text)
    MsgBox "Vb.net Version is " & R
    'Vb.net Version is 4.0.30319.42000
    Last edited by xiaoyao; May 6th, 2021 at 05:26 AM.

  4. #4

    Thread Starter
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: How to create all VB. Net controls dynamically with VB6?

    call vb.net sum(11,22) from vb6,result is 33

    Code:
    Dim V1 As Long
    Dim V2 As Long
    Dim V3 As Long
    V1 = 5
    V2 = 6
    V3 = VbNet.Sum(V1, V2)
    MsgBox " test Sum:" & V1 & "+" & V2 & "=" & V3 & vbCrLf _
     & "Sum(ByVal a As IntPtr  ,ByVal b As IntPtr ) As IntPtr "

  5. #5

    Thread Starter
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: How to create all VB. Net controls dynamically with VB6?

    Code:
    'VBS CODE:
    DIM V4
    V4 = OBJ2.Sum3(10,20)'Return the object of VB.NET
    MSGBOX V4
    'msgbox ("AA" & v4)'The string cannot be merged with the object returned by VB.NET in vbs
    
    dim v5
    v5=obj2.VbsAddStr("10+20=",v4)
    msgbox v5
    Code:
    'vb.net com dll code:
    	Public Function VbsAddStr(ByVal a As Object   ,ByVal b As Object ) As Object  
    		'MsgBox ("vb.net函数(VbsAddStr)被调用")
    		Return (a.ToString & b.ToString )
    	End Function

  6. #6
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,183

    Re: How to create all VB. Net controls dynamically with VB6?

    Blah!

  7. #7

    Thread Starter
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: How to create all VB. Net controls dynamically with VB6?

    Many people don't understand why I do this. I just want to upgrade VB6 directly to VB7 or VB.net Framework(without Install vs2019)
    Mainly use VB6 to develop, but steal some VB.NET controls to use. In this way, almost 100 .NET controls can be added. Then put some VB.NET functions and class libraries to VB6.
    Last edited by xiaoyao; May 6th, 2021 at 10:26 PM.

  8. #8
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    4,533

    Re: How to create all VB. Net controls dynamically with VB6?

    Why not use VB2019????

  9. #9
    Fanatic Member TTn's Avatar
    Join Date
    Jul 2004
    Posts
    620

    Re: How to create all VB. Net controls dynamically with VB6?

    Quote Originally Posted by xiaoyao View Post
    Many people don't understand why I do this. I just want to upgrade VB6 directly to VB7 or VB2019. Mainly use VB6 to develop, but steal some VB.NET controls to use. In this way, almost 100 .NET controls can be added. Then put some VB.NET functions and class libraries to VB6.
    You are correct. Thank you very much for this sample. It helped me be able to complete my project now. xiaoyao, please try to shorten your sentences in Chinese. The translator is having troubles.
    The Microsoft Interop Forms Toolkit has similar features.

  10. #10

    Thread Starter
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: How to create all VB. Net controls dynamically with VB6?

    Quote Originally Posted by TTn View Post
    You are correct. Thank you very much for this sample. It helped me be able to complete my project now. xiaoyao, please try to shorten your sentences in Chinese. The translator is having troubles.
    The Microsoft Interop Forms Toolkit has similar features.
    As long as it's someone who's actually tested. I am very happy to post a comment, Even if it criticizes me。

    Thank you very much for your recognition of my technology, in fact, you only used a little bit.
    Often many people are attacking viciously.What am I going to do with VB6 if I want to install vs2019?

    This solution is how to use the features of the .net framework without installing Microsoft's development tool, vs2019.

    I can just steal their controls.I use their latest style of UI elements.I can also sneak in some of their class libraries.

    Net intermediate plug-in into a DLL, some functions can be packaged to VB6 use.

    I can even make an exe directly with. Net as the main program.Com DLL development with VB6 for VB.NET use.80% to 99% of code is developed in VB6
    Last edited by xiaoyao; May 6th, 2021 at 10:28 PM.

  11. #11
    Fanatic Member TTn's Avatar
    Join Date
    Jul 2004
    Posts
    620

    Re: How to create all VB. Net controls dynamically with VB6?

    Quote Originally Posted by xiaoyao View Post
    As long as it's someone who's actually tested. I am very happy to post a comment, even if I think this method is not good enough to criticize it.

    Thank you very much for your recognition of my technology, in fact, you only used a little bit.
    Often many people are attacking viciously.What am I going to do with VB6 if I want to install vs2019?

    This solution is how to use the features of the .net framework without installing Microsoft's development tool, vs2019.

    I can just steal their controls.I use their latest style of UI elements.I can also sneak in some of their class libraries.

    Net intermediate plug-in into a DLL, some functions can be packaged to VB6 use.

    I can even make an exe directly with. Net as the main program.Com DLL development with VB6 for VB.NET use.80% to 99% of code is developed in VB6
    Yes, I agree with that solution. The goal is to use VB6 without additional installation of a bloated NET IDE. You are not stealing. You are interoperating. Use the word interop, not steal.
    The only thing you have left to do is expose these as objects and events in the VB6 IDE. For simple example: Instead of calling runcode, you would type in the class namespace, ie System.IO.File.Exists("C:\filename.txt"), just like in the VB.NET code editor.
    The ultimate goal is that you can copy/paste code into the VB6 IDE. The VB6 IDE should recognize the VB.NET namespaces.

  12. #12

    Thread Starter
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: How to create all VB. Net controls dynamically with VB6?

    Quote Originally Posted by TTn View Post
    Yes, I agree with that solution. The goal is to use VB6 without additional installation of a bloated NET IDE. You are not stealing. You are interoperating. Use the word interop, not steal.
    The only thing you have left to do is expose these as objects and events in the VB6 IDE. For simple example: Instead of calling runcode, you would type in the class namespace, ie System.IO.File.Exists("C:\filename.txt"), just like in the VB.NET code editor.
    The ultimate goal is that you can copy/paste code into the VB6 IDE. The VB6 IDE should recognize the VB.NET namespaces.
    It's rare to meet a soulmate, only those who need this usage will understand how interesting and smart this idea is. Some people also need him, but he simply can't understand the articles written by others.

    As long as some people think that this method is very clever, I succeeded, and I didn't waste my hard work. Sometimes even if it's just a creative idea, without doing any research, without writing a single code, just like Newton, thinking that the earth is round and has gravity, that's enough.

    A good idea is creativity and invention. Although it is not as great as Edisonís invention of the light bulb, in fact, a software project consists of a collection of many large and small creative ideas to have IOS system, labview and other great ideas. Many of the works are advanced, and it is difficult for other competitors to surpass for decades.

  13. #13

    Thread Starter
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: How to create all VB. Net controls dynamically with VB6?

    Without installing the VB6 development environment, when I try to dynamically load the third-party control OCX in the compiled EXE, I also need to add a license.
    Maybe the VB6 IDE will automatically add the license to the EXE when editing components after adding components

    If you want to add treeview control to excl VBA, access vba form, you need to add the component Microsoft Windows Common Controls 6.0 (SP6), and you need to obtain a license.
    In theory, you have to pay to get the power to design in the IDE.
    Using a middleware method, although it is not as simple as dragging and dropping controls directly, it does not require authorization and does not require payment, which is very useful.
    ===============

    Yes, under normal circumstances, you have to purchase expensive VS2019 development tools, which may take up 10-50G of space after installation.
    In this way, even the control license is not needed. It can be perfect to use its functions without installing the .NET development environment. If you want to use multiple versions of .NET environment, you only need to compile into VBNetFramework2.dll, VBNetFramework4.dll.
    It can also be made into a control mode to load the control without registration. In the control, you can dynamically create .NET COM objects, you can also dynamically create all the controls of .NET, you can also dynamically edit and run, and you can also reflect on the controls on the form.

    But these are mainly for simple usage of some controls, which can satisfy most people's usage scenarios. If you need to write a large amount of VB.NET code project, you can write that part of the code as a separate DLL and then call VB6. You can also wrap a certain VB.NET control, such as DATAGRIDVIEW, and generate the control for VB6 use.
    Last edited by xiaoyao; May 6th, 2021 at 10:34 PM.

  14. #14

    Thread Starter
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: How to create all VB. Net controls dynamically with VB6?

    In fact, I did not install VS2019, I only have SharpDevelop 4.4 (the latest version 4.5 cannot visually design VB.NET forms, but C# can)
    SharpDevelop does not have .net to create activex.dll, Activex Control (OCX) project templates, I don't know why.
    Later I found a previously created VB.NET activex.dll project, modified some functions, let him produce similar functions of the control.
    Later, I found a template on the Internet that can directly create .NET Activex Control, but the finished control can't get the focus in VB6. When switching between the textbox control of VB6 and the text box control of .NET, you need to double-click to enter the .NET control.
    I have to study this question to see if I made a mistake.
    SharpDevelop V5.1.0.5216 is only 13MB, and it takes up 48MB to complete the installation. I like the software that takes up very little hard disk space.

  15. #15

    Thread Starter
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: .NET_ForVB6.dll【COM-Wrapper Library With .netFrameWork】Like Rc6.dll

    SharpDevelop 5.1 VB.NET visual form designer function is invalid, and the function of C# and .NET code conversion is gone.
    SharpDevelop has not been updated for 6 years. Is it so difficult to open source? It shouldn't be difficult to add some functions or make some BUG improvements every month?

  16. #16

    Thread Starter
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: .NET_ForVB6.dll【COM-Wrapper Library With .netFrameWork】Like Rc6.dll

    Using the .NET mini visual form designer, you can use VB6 to write a simple IDE for developing .NET projects, and the code can be dynamically compiled and run.

    .NET visual form designer, only 50 lines of code!!!-VBForums
    https://www.vbforums.com/showthread....%26%2365281%3B
    Attached Images Attached Images  

  17. #17
    Fanatic Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    931

    Re: How to create all VB. Net controls dynamically with VB6?

    Quote Originally Posted by Magic Ink View Post
    Blah!
    This is NOT BLAH - This is good, xiaoyiao! Very interesting.

  18. #18
    Fanatic Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    931

    Re: How to create all VB. Net controls dynamically with VB6?

    Quote Originally Posted by Arnoutdv View Post
    Why not use VB2019????
    Well, because :
    a. it looks like it extends a lot of the power intrinsic to .NET methods, to VB6, which is a boon to VB6ers
    b. it seems to show (forgive me if I am wrong) a potential method of creating .NET compatibility for someone considering future migration from VB6 to VB.NET.
    c. see all the many other reasons why a VB6er might not want to use .FRED just because it is .FRED.
    d. it also shows what xiaoyiao is capable of with a fair wind behind him and a decent translation tool in hand.
    e. useful to others - see TTn's response
    f. shows what MS could have offered as a sop to VB6ers back in the day had they chosen to do so.

  19. #19
    Fanatic Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    931

    Re: .NET_ForVB6.dll【COM-Wrapper Library With .netFrameWork】Like Rc6.dll

    xiaoyiao, I am attempting to summarise what I believe are your thoughts here:

    Are you suggesting :

    1. That it would be possible to use sharp develop (an open source editor?) to create an IDE ?
    2. Or are you simply just showing what can be done with this method of calling VB.NET methods using your approach detailed above?

  20. #20

    Thread Starter
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: .NET_ForVB6.dll【COM-Wrapper Library With .netFrameWork】Like Rc6.dll

    Quote Originally Posted by yereverluvinuncleber View Post
    xiaoyiao, I am attempting to summarise what I believe are your thoughts here:

    Are you suggesting :

    1. That it would be possible to use sharp develop (an open source editor?) to create an IDE ?
    2. Or are you simply just showing what can be done with this method of calling VB.NET methods using your approach detailed above?
    1. Complete: 50 lines can visualize the controls of the form
    2. Completion: dynamic editing, dynamic running function
    3. Under development: create multiple controls dynamically (design the layout position and size according to the visual form)

    In fact, I just want to make a simple VB.net version form + source code editor (control form) for VB6, which can generate EXE or execute code directly in memory
    Just like VBA, in fact, it does not run independently, it is equivalent to a control (you need to pay to obtain Microsoft authorization)

    it's hard to do : use sharp develop (an open source editor?) to create an IDE

    i only want to use .net controls,and .net function list

    I don't want to use VS2019 development tools, but I also want to use some .NET FRAMEWORk form special effects, exquisite controls, and hundreds of thousands of libraries in it, all secretly used by VB6.
    It is like using VB.NET as a DATAGRID control or a VBSCRIPT object to control it.
    Let .NET be one of our components, one module, and nothing more
    Last edited by xiaoyao; May 7th, 2021 at 05:33 AM.

  21. #21

    Thread Starter
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: .NET_ForVB6.dll【COM-Wrapper Library With .netFrameWork】Like Rc6.dll

    This is a very simple but very powerful visual form design "tool", but you can change the source code to a function of my .NET component package designed for VB6, .NET_vb6.FormDesigner(), save the configuration after designing As a JSON file. For example, the content of the list is similar, 4 buttons, 2 text boxes, background color, font size, etc.
    In fact, it is equivalent to the form file of VB6 (Form1.frm)
    Design another function: NET_vb6.LoadFrmFromJson(jsonfile, PutVbCode, RunOnMemory, CompilePath)
    In this way, you can directly create a form and add code, run it directly, or generate an EXE file.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width