Results 1 to 27 of 27

Thread: [VB6] - Trick Advanced Tools.

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,671

    [VB6] - Trick Advanced Tools.

    Hello everyone!
    I present to you a small project - Add-in that allows to some extent alleviate debugging some programs as well expand compilation possibilities. All the source codes are in the attachment.
    This Add-in has the following features:
    1. Fixes the bug with Not Not Array statement that causes error "Expression too complex" if you'll work with float numbers;
    2. Allows to utilize the automatic conditional constants depending on run mode (IDE/EXE) look like in C++ (NDEBUG);
    3. Allows to disable integer overflow checking in IDE;
    4. Allows to disable floating point result checking in IDE;
    5. Allows to disable array bounds checking in IDE;
    6. Provides the compilation/linking events (both in IDE and EXE), i.e. you can run the commands before/after this events. By using this events you can do many useful things (encryption, replace OBJ files, static linking, etc.)


    How does it work?



    For fixing Not Not bug and disabling checking it uses the module of replacing of the opcodes handlers (P_Code) to ours. Firstly it finds the table of the opcodes by the signature in the ENGINE section of VBA6.dll module. There are two opcodes types - single-byte and double-bytes. Teh single-byte opcodes is less that 0xFB. It uses the length dissasembler by Ms-Rem that i ported to VB6. Besides it finds the subroutine that redirectes performing to the next opcode as well the subroutine that handles the errors. Since now it is very easy to get an access violation error i kept some checking. For example, access to uninitialized array causes the memory violation error - it handles that error. Because of there isn't an official documentation about VB6 opcodes (i've not found it) i did all the investigations, therefore some opcodes can raise error. In this case you can write them - i'll add handlers.
    For others features it uses splicing of the following functions:
    1. TipCompileProject;
    2. TipCompileProjectFull;
    3. TipMakeExe2;
    4. TipFinishExe2.
    TipSetConstantValues/TipGetConstantValues functions are used in order to set/get the conditional compilation arguments. The events is just calling of ShellExecuteEx function. There are events before/after project compilation (IDE/EXE) and linking. This project was weakly testing therefore it can contain bugs.
    Regading,
    Кривоус Анатолий (The trick)
    Attached Files Attached Files

  2. #2
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: [VB6] - Trick Advanced Tools.

    typo? thinking it should be a *
    modDisasm.bas
    Code:
    line 63:        retOpcode = Opcode Or (cPtrData & &H100&)

  3. #3
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: [VB6] - Trick Advanced Tools.

    Quote Originally Posted by DEXWERX View Post
    typo? thinking it should be a *
    modDisasm.bas
    Code:
    line 63:        retOpcode = Opcode Or (cPtrData & &H100&)
    I would think possibly "And" if the code is meant to clear the bits in a bit field (but leave bit 9 unaltered) before Or'ing the Opcode into the return value.
    retOpcode = Opcode Or (cPtrData And &H100&)

    I didn't look at the actual code though to get a sense of the context, but & is the binary operand "And" in C and C++ (and possibly other languages I'm not familiar with).

  4. #4
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    673

    Re: [VB6] - Trick Advanced Tools.

    sometimes can you complete tool for vb addin about png? i see the video you upload to youtube!

  5. #5
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: [VB6] - Trick Advanced Tools.

    Quote Originally Posted by passel View Post
    I would think possibly "And" if the code is meant to clear the bits in a bit field (but leave bit 9 unaltered) before Or'ing the Opcode into the return value.
    retOpcode = Opcode Or (cPtrData And &H100&)

    I didn't look at the actual code though to get a sense of the context, but & is the binary operand "And" in C and C++ (and possibly other languages I'm not familiar with).
    you would think that yes - That was my first assumption. I should have posted more context of the code. It's supposed to be combining 2 1 byte opcodes, to a single 2 byte opcode. So it's definitely supposed to be a *

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Feb 2015
    Posts
    2,671

    Re: [VB6] - Trick Advanced Tools.

    Quote Originally Posted by DEXWERX View Post
    typo? thinking it should be a *
    modDisasm.bas
    Code:
    line 63:        retOpcode = Opcode Or (cPtrData & &H100&)
    ̶Y̶e̶s̶.̶ ̶T̶h̶a̶n̶k̶ ̶y̶o̶u̶!̶ ̶I̶'̶v̶e̶ ̶f̶i̶x̶e̶d̶ ̶i̶t̶.̶ ̶I̶t̶ ̶s̶h̶o̶u̶l̶d̶ ̶b̶e̶:̶ ̶
    Code:
     ̶r̶e̶t̶O̶p̶c̶o̶d̶e̶ ̶=̶ ̶O̶p̶c̶o̶d̶e̶ ̶O̶r̶ ̶(̶c̶P̶t̶r̶D̶a̶t̶a̶ ̶A̶n̶d̶ ̶&̶H̶1̶0̶0̶&̶)̶
    Quote Originally Posted by passel View Post
    I would think possibly "And" if the code is meant to clear the bits in a bit field (but leave bit 9 unaltered) before Or'ing the Opcode into the return value.
    retOpcode = Opcode Or (cPtrData And &H100&)

    I didn't look at the actual code though to get a sense of the context, but & is the binary operand "And" in C and C++ (and possibly other languages I'm not familiar with).
    ̶Y̶o̶u̶ ̶a̶r̶e̶ ̶r̶i̶g̶h̶t̶!̶
    Quote Originally Posted by xxdoc123 View Post
    sometimes can you complete tool for vb addin about png? i see the video you upload to youtube!
    Yes, i'm working on it. It nicely works in IDE, i'm working on adding this feature to EXE. In the compiled form it's just an OBJ module that is linked to main exe and starts before main executable code will be launched.

    EDITED:
    DEXWERX, you are right. I was inattentive. It should be * 0x100 because this is 2-bytes opcode. http://read.pudn.com/downloads158/so.../LDasm.c__.htm

  7. #7
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: [VB6] - Trick Advanced Tools.

    @Trick - it should be * not &

    a) You're combining 2 1 byte Opcodes according to the comments. ie: w = b1 Or (b2 * &H100&)
    b) cPtrData is Byte. If you And any Byte with &H100 - it becomes 0



    edit: Thanks for posting this!
    Last edited by DEXWERX; Sep 29th, 2016 at 09:07 AM.

  8. #8
    Lively Member
    Join Date
    Oct 2010
    Posts
    75

    Re: [VB6] - Trick Advanced Tools.

    Hi,

    I am still getting Run-time error "Expression too complex". How to fix that?

  9. #9

  10. #10
    Lively Member
    Join Date
    Oct 2010
    Posts
    75

    Re: [VB6] - Trick Advanced Tools.

    Quote Originally Posted by The trick View Post
    Kunical , hi. Please show the code that causes the error. Thank.
    Hellow the trick,

    Here is the code

    Code:
     ' --For themed style, we are not able to draw borders
          ' --after drawing the caption. i mean the whole button is painted at once.
          If m_ButtonStyle = eWindowsTheme Then
             If .Left < 4 Then .Left = 4
             If .Right > ScaleWidth - 4 Then .Right = ScaleWidth - 4
             If .Top < 4 Then .Top = 4
             If .Bottom > ScaleHeight - 4 Then .Bottom = ScaleHeight - 4
          End If
       End With
    This is from Jcbutton user control.

  11. #11
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,373

    Re: [VB6] - Trick Advanced Tools.

    This Addin is great! Especially the events to intercept in the linking process to replace .obj files.

    Compiling the source to dll works and is properly registered.
    However, any further attempt with regsvr32 (register or unregister) fails with the error "LoadLibrary("TrickAdvancedTools.dll") failed - The specified module could not be found"
    So that makes it a pain to ship the dll to another computer.

    I tested to replace all the typelib functions, consts etc. into the project as normal declarations and it solved the issue and I see no difference in the functionality.

    Attached is the modified source. I hope that is OK by the trick? If not, please let me know I will remove it.
    Attached Files Attached Files

  12. #12
    Lively Member
    Join Date
    Aug 2008
    Location
    Denmark
    Posts
    85

    Re: [VB6] - Trick Advanced Tools.

    First, Thanks for the many great contributions to The Trick and Krool!
    I agree it's a great Addin but when it's loaded i experience an issue in many projects that is using sub classing while using Krools mod. TrickAdvancedTools_NoTypeLib.zip

    run-time error '16'
    Expression too complex

    E.g. pvSafeOffset32() in [vb6]Common Dialog Class (Yet Another One) by LaVolpe
    http://www.vbforums.com/showthread.p...t-Another-One)

    This happen when the Addin is loaded (even when no settings are active)
    As soon as the Addin is unloaded the code work again without the runtime error

  13. #13
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,373

    Re: [VB6] - Trick Advanced Tools.

    Quote Originally Posted by DracullSoft View Post
    First, Thanks for the many great contributions to The Trick and Krool!
    I agree it's a great Addin but when it's loaded i experience an issue in many projects that is using sub classing while using Krools mod. TrickAdvancedTools_NoTypeLib.zip

    run-time error '16'
    Expression too complex

    E.g. pvSafeOffset32() in [vb6]Common Dialog Class (Yet Another One) by LaVolpe
    http://www.vbforums.com/showthread.p...t-Another-One)

    This happen when the Addin is loaded (even when no settings are active)
    As soon as the Addin is unloaded the code work again without the runtime error
    It must be something with the modCheckingOptions
    If I comment them out in the conAddIn designer and re-compile then it works without that error.
    But then of course you loose some functionality.

  14. #14

  15. #15
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    323

    Re: [VB6] - Trick Advanced Tools.

    dear the trick, how can we hack vba6.dll functions to do more jobs

    take TipCreateStdModule as example
    1.how can we do our job after StdModule created
    2.can we choose whether to execute our own TipCreateStdModule_user or the original TipCreateStdModule?

  16. #16

  17. #17
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    323

    Re: [VB6] - Trick Advanced Tools.

    Quote Originally Posted by The trick View Post
    loquat,
    Seems we already have this event:
    thanks The trick, i found the Member you gived very useful
    but i'm still interest in how to do this with hooking or subclassing
    because with these technics, we can hack every exe or dll
    can you share something to make it?
    hook before function or after function

  18. #18
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: [VB6] - Trick Advanced Tools.

    Is there a way to compile each form, module, class into a * .obj file and not delete it unless the code file is modified. If a project has 20 code files and only one function is modified, only one obj file needs to be generated. The goal is to quickly compile. If you can, you can compile in memory without generating temporary files, and use the principle of reading and writing hook (link.exe, c2.exe) files.
    Now I am developing some plugins for the freebasic IDE, and I also want to use the function of memory compilation and incremental compilation. Now there is a visualFreebasic5 ide tool developed by a Chinese that is very powerful. I hope that fans of vb will participate in the plug-in development, just like the development of addin (activex dll) for vb6.
    And "b4a" Android development tool also uses visual basic code.

  19. #19
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    323

    Re: [VB6] - Trick Advanced Tools.

    it seems in my vb6, this addin can not working
    but the cut down version from krool, link is here, is working for me.
    do not know why.

  20. #20

  21. #21
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    323

    Re: [VB6] - Trick Advanced Tools.

    have a new idea.
    for IDE, the toolbar items and the menubar items are always missing
    so i need to click: View-> Tools -> Customize, and select MenuBar Standard Edit, to click Reset button to reset them to normal.
    maybe you can add BeforePrjClose event, so we can do that before project close.

  22. #22
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    323

    Re: [VB6] - Trick Advanced Tools.

    can we call tipgetconstvalues by declare
    not using hook?

  23. #23

  24. #24
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    323

    Re: [VB6] - Trick Advanced Tools.

    Quote Originally Posted by The trick View Post
    I think yes. Only the code can be changed if you change conditiaonal variables.
    i do not understand how to get hnativeproject

  25. #25

  26. #26
    Hyperactive Member
    Join Date
    Jan 2015
    Posts
    323

    Re: [VB6] - Trick Advanced Tools.

    work done:
    Code:
    Private Declare Sub EbGetExecutingProj Lib "vba6" (ByRef lpPrjObj As IUnknown)
    Private Declare Function TipGetConstantValues Lib "vba6" (ByVal hProj As Long, ByVal v As Long) As Long
    Private Declare Function TipSetConstantValues Lib "vba6" (ByVal hProj As Long, ByVal v As Any) As Long
    
    Private Declare Function EbSetMode Lib "vba6" (ByVal Mode As Long) As Long
    
    Sub Main()
        Dim objProj As IUnknown
        EbGetExecutingProj objProj
        
        Dim str As String
        TipGetConstantValues ObjPtr(objProj), VarPtr(str)  'Unicode
        Debug.Print str
        
        'EbSetMode 2
        TipSetConstantValues ObjPtr(objProj), StrPtr("loquat = 1")
        'EbSetMode 1
    End Sub
    Last edited by loquat; Nov 2nd, 2022 at 08:58 AM.

  27. #27

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