Results 1 to 24 of 24

Thread: Is there a function to return that code running in p-code inside IDE

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,225

    Is there a function to return that code running in p-code inside IDE

    I found a way to execute machine code, which assembled in run time, and from that I can call a module in VB6. But from IDE if the code run as p-code the module through the pointer can't run, and quick cause crash. So with a helper function I can return an error message such as "Compile and then run the program". I know how to found that the program run in IDE, but not if running as p-code. Calling modules from vb6 through addressof works in p-code, but not from the side of machine code. I check the +0x16 to return value of function address and didn't work (Trick had suggested this some time ago).

  2. #2
    Fanatic Member
    Join Date
    Jun 2015
    Posts
    848

    Re: Is there a function to return that code running in p-code inside IDE

    the ide always runs as pcode

    addressof returns the address of a small native stub to transition from native to pcode

    Code:
    mov     edx, offset Module1_PcodeFunc_0
    mov     ecx, offset ProcCallEngine
    jmp     ecx
    offset Module1_PcodeFunc_0 isnt actually the pcode itself its a structure that defines the pcode function

    Code:
    .text:004019C4 Module1_PcodeFunc_0 
    .text:004019C4                 dd offset Module1_ObjInfo; table
    .text:004019C4                 dw 14h                  ; argSz
    .text:004019C4                 dw 80h                  ; FrameSize
    .text:004019C4                 dw 84h                  ; ProcSize
    ....
    more
    add an int3 (byte CC) to your native code and step through in a native debugger to see whats wrong and where its crashing.

    I have a couple videos on it here. Part 3 shows pcode callbacks

    http://sandsprite.com/blogs/index.ph...=485&year=2020
    Last edited by dz32; Nov 13th, 2022 at 09:55 PM.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,225

    Re: Is there a function to return that code running in p-code inside IDE

    For debugging. I would like to include a debugger, but in the same dll, which means I have to make another process to run the debugger. I have no idea how to do this.

    About the addressof: Using start with complete compiling vb6 code from IDE there is no problem with call a sub through the retyrn value from addressof. Using start (without compiling) I have problem.

    So before I have to use a pcode callback I have to know if the code in IDE run compiled or as p-code. You say that "the ide always runs as pcode", but when the functions/subs are compiled the addressof return an address which we can call by machine code.



  4. #4
    Fanatic Member
    Join Date
    Jun 2015
    Posts
    848

    Re: Is there a function to return that code running in p-code inside IDE

    I am afraid I do not understand.

    You can determine if exe was compiled to pcode by looking at the bytes at offset returned by address of or by looking at pe file structure harder).

    To include your own Debugger in a dll is a huge project I would not recommend it. It’s best to debug using a standalone debugger such as ollydbg.

    In vb is it easy to determine if code is running in ide or compiled, in asm stub it will be harder, just pass asm stub a value.

    Maybe translator output will easier than direct English

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,225

    Re: Is there a function to return that code running in p-code inside IDE

    I don't want to found if exe is compiled to pcode. I want to now when a vb6 program run in IDE if it is run using full compiled code.

  6. #6
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    8,716

    Re: Is there a function to return that code running in p-code inside IDE

    Quote Originally Posted by georgekar View Post
    I want to now when a vb6 program run in IDE if it is run using full compiled code.
    I don't think any of us know what that means. Are you talking about the "Compile On Demand" option under settings? I suppose, when using subclassing (or other callbacks), that could cause some problems. But I don't think that's what you're talking about.

    Do you want to know when your code is executing your machine code vs the VB6 p-code? Actually, there's a third state: code is idling and not running any code (or is just down in the VB6 engine in a loop waiting on an event to be raised).

    If this is what you want, when will you be checking it? This is sort of a chicken-and-egg problem. If you're checking it in VB6 code, then there's no reason to check it because you're in VB6 code. If you're in your machine code, then what/how would you check (and report)? Are you trying to step through your machine code? The VB6 IDE isn't going to natively do that.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,225

    Re: Is there a function to return that code running in p-code inside IDE

    I have an activeX Dll, the M2000.dll which called from M2000.exe. The first (the dll) running in IDE (say it is a new version to test it). Before the m2000.exe be started, I had to run the code in ide (the dll), using F5 or Ctrl+F5. Using the Ctrl+F5 in IDE perform a compiling (internal) and then run the code (although compiled we can add/replace code, inside functions/subs). So let's say that all of these are run happily. We get the M2000 Interpreter alive (this is what we get from m2000.exe and m2000.dll) and we can run a program which at some point create separate binary code for execution (the M2000 isn't a compiled language, so I didn't say about the machine code of the program, but the machine code produced by the program, as a task for it). So the execution of the code happen when the IDE run the DLL which support the calling to machine code. If we have compiled the VB6 code before run it (the DLL) then the call to a module in the dll from machine code can be done. If we use p-code (non compiled code for dll) then we have crash: first call give a no call, and second time crash the execution, although the IDE not crash, but the exe file has to closed from Task Manager.

    This is the code (M2000 instructions) https://georgekarras.blogspot.com/20...00-part-1.html
    Running this with compiled dll (either in Ide or as file), through m2000.exe there is no problem. So my problem is to find a way when the M2000.dll run in IDE to check maybe with a poke from an addressOf for specific data, so then I can raise an error "Compile the dll to execute code", before the execution of machine code (prepared from user).

  8. #8
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,606

    Re: Is there a function to return that code running in p-code inside IDE

    What about making a public InIDE property or function for the DLL?

    Code:
    Public Function InIDE() As Boolean
        Static sValue As Long
        Dim iInIDE As Boolean
        
        If sValue = 0 Then
            Debug.Assert MakeTrue(iInIDE)
            If iInIDE Then
                sValue = 1
            Else
                sValue = 2
            End If
        End If
        InIDE = (sValue = 1)
    End Function
    
    Private Function MakeTrue(Value As Boolean) As Boolean
        MakeTrue = True
        Value = True
    End Function

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,225

    Re: Is there a function to return that code running in p-code inside IDE

    The dll knows that running in IDE (https://github.com/M2000Interpreter/Environment)
    The problem has to do with the development stage, if there is a solution, in vb6 to know that vbcode run as compiled or not (p-code). If I have the solution I know what to do before the execution of Machine Code (so the call back can't used).

  10. #10
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,606

    Re: Is there a function to return that code running in p-code inside IDE

    I don't think you explained the "problem". It seems to me like an X/Y problem.

    What do you actually need (concrete), aside from what you think you need?

    I suggest to forget about p-code/not p-code for a while and try to be clear on the situation (aside from p-code/not p-code, that's not the point).

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,225

    Re: Is there a function to return that code running in p-code inside IDE

    No that is the point: is any known method to find programmatically if a sub in Vb6 run as compiled form or p-code IN IDE???
    compiled form means we use Ctrl+F5, at least one, not compiled we use F5 (we didn't use compiled form) so it is p-code.

    I think I have to make an example.

  12. #12
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,493

    Re: Is there a function to return that code running in p-code inside IDE

    In the IDE everything is p-code
    No matter whether you press F5, Ctrl-F5 or run
    Ctrl-F5 -> Full compile -> means compile all the text to p-code, checking the syntax for all kind of errors. It's not compiled to an executable.
    Just F5 compiles to p-code on the fly, only the code which is to be executed

  13. #13
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    8,716

    Re: Is there a function to return that code running in p-code inside IDE

    Quote Originally Posted by georgekar View Post
    is any known method to find programmatically if a sub in Vb6 run as compiled form or p-code IN IDE???
    You see? That makes no sense. As stated above by dz32, ALL VB6 code is running as p-code when running in the IDE. There is no machine code (which is what I think you mean by "compiled" code).

    Now, if you're talking about detecting whether you're running in a thunk vs the p-code, what is it that's going to do this detecting? It's certainly not the program itself. So, are you writing a separate machine-code debugger (like ollydbg)? If that's the case, then either just use ollydbg, or we're at a TOTALLY different level, and this probably doesn't even belong in a VB6 forum.

    If you just wish to detect whether you're in the IDE (running) or if it's the compiled EXE that's running, there are MANY ways to do that: seen here, and here, and here, and I'm sure there are many others as well. These days, the one by The Trick is typically accepted, as it compiles into very fast code.
    Last edited by Elroy; Nov 15th, 2022 at 06:28 PM.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  14. #14
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,606

    Re: Is there a function to return that code running in p-code inside IDE

    It was also my guess: that in the IDE all is p-code, but since he seems to be so sure that there is a difference when running with full compile (Control+F5) or not (just F5 and having "compile on demand" configured)... so I thought he must know something that I don't.

    But... if everything is p-code in the IDE, then he just need to know if the code is compiled or not (running in the IDE).

    But, there is also the possibility that the code is compiled... to p-code... well, that's another issue. But I don't think he is asking about that.

  15. #15
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,606

    Re: Is there a function to return that code running in p-code inside IDE

    There are basically four situations:

    End program (host/client program) compiled or not compiled.
    Component compiled or not compiled.

    1) End program compiled + component compiled.
    2) End program in IDE + component compiled.
    3) End program in IDE + component in IDE.
    4) End program compiled + component in IDE.

    1) Normal end-user situation.
    2) Normal end program development situation.
    3) Normal component development situation.
    4) Unlikely to happen in practice, but technically possible, specially from:

    Name:  Sin título.png
Views: 80
Size:  14.6 KB

  16. #16
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    8,716

    Re: Is there a function to return that code running in p-code inside IDE

    Quote Originally Posted by georgekar View Post
    Calling modules from vb6 through addressof works in p-code, but not from the side of machine code.
    That must somehow be the key to what he's talking about. But what does "from side of machine code" mean???

    How is this machine code executed? If it's executed through the VB6 code (either IDE or compiled to EXE), AddressOf works absolutely fine. I've done that many times.

    Now, if this machine code is some other program attempting to execute another VB6 program, then that's something quite different (and tricky). I wouldn't know how to execute code within an IDE from an external program (well, other than developing a component or add-in, but I don't think that's what we're talking about).
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  17. #17
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,606

    Re: Is there a function to return that code running in p-code inside IDE

    @georgekar: could you make a small sample project (or project group) to demonstrate the problematic situation?
    I mean, the very minimal, no more. Not to use any third party program please.

  18. #18

    Thread Starter
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,225

    Re: Is there a function to return that code running in p-code inside IDE

    This code run ok but it isn't an activeX dll.

    Code:
    Private Declare Function VirtualAlloc Lib "kernel32" (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
    Private Declare Function VirtualFree Lib "kernel32" (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal dwFreeType As Long) As Long
    Private Declare Function VirtualLock Lib "kernel32" (ByVal lpAddress As Long, ByVal dwSize As Long) As Long
    Private Declare Function VirtualUnlock Lib "kernel32" (ByVal lpAddress As Long, ByVal dwSize As Long) As Long
    Private Declare Function VirtualProtect Lib "kernel32" (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flNewProtect As Long, lpflOldProtect As Long) As Long
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Private Declare Function GetLastError Lib "kernel32" () As Long
    Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
    Private Declare Function FlushInstructionCache Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, ByVal dwSize As Long) As Long
    Private Declare Function CallWindowProc _
     Lib "user32.dll" Alias "CallWindowProcW" ( _
     ByVal lpPrevWndFunc As Long, _
     ByVal hWnd As Long, _
     ByVal Msg As Long, _
     ByVal wParam As Long, _
     ByVal lParam As Long) As Long
    Private Declare Sub PutMem1 Lib "msvbvm60" (ByVal addr As Long, ByVal NewVal As Byte)
    Private Declare Sub PutMem4 Lib "msvbvm60" (ByVal addr As Long, ByVal NewVal As Long)
    
    
    
    
    Private Const MEM_COMMIT = &H1000&
    Private Const MEM_RESERVE = &H2000&
    Private Const PAGE_EXECUTE_READ = &H20&
    Private Const PAGE_READWRITE = &H4&
    Dim global1 As Long
    Sub Main()
        test
    End Sub
    Function addr(a As Long)
        addr = a
    End Function
    Sub test()
        Dim Ptr As Long, nbytes As Long, oldV As Long
        Dim i As Long, RetValue As Long, pc As Long, k As Long
        nbytes = 1024&
        Ptr = VirtualAlloc(ByVal 0&, nbytes, MEM_COMMIT + MEM_RESERVE, PAGE_READWRITE)
        pc = 0
        PutMem1 Ptr + pc, &H68 ' push
        PutMem4 Ptr + pc + 1, VarPtr(i): pc = pc + 5
        PutMem1 Ptr + pc, &HE8 ' Call CallBack
        PutMem4 Ptr + pc + 1, addr(AddressOf CallBack) - pc - 5 - Ptr: pc = pc + 5
        PutMem1 Ptr + pc, &HC3
            
        FlushInstructionCache GetCurrentProcess, Ptr, nbytes
        VirtualProtect Ptr, nbytes, PAGE_EXECUTE_READ, oldV ' PAGE_READWRITE
        VirtualLock Ptr, nbytes
        For k = 1 To 100000
            For i = 1 To 20
                RetValue = CallWindowProc(Ptr, 0&, 0&, 0&, 0&)
            Next i
        If k Mod 25 = 0 Then DoEvents Else Sleep 0
        Next k
        FlushInstructionCache GetCurrentProcess, ByVal Ptr, nbytes
        VirtualUnlock Ptr, nbytes
        VirtualProtect Ptr, nbytes, PAGE_READWRITE, oldV
        
        If Not VirtualFree(a, 0&, &H8000&) = 0 Then Debug.Print GetLastError(), "???"
    End Sub
    
    
    Sub CallBack(i As Long)
         i = i + 1
         ' Debug.Print "ok", i
    End Sub

  19. #19
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,606

    Re: Is there a function to return that code running in p-code inside IDE

    Quote Originally Posted by georgekar View Post
    This code run ok but it isn't an activeX dll.
    I know that there are language barriers, but could you try to explain better how to reproduce the situation of the problem? (use Google Translator if it could help, it translates quite well, or at least usually better than we do).

  20. #20

    Thread Starter
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,225

    Re: Is there a function to return that code running in p-code inside IDE

    I use the module who post above in activeX and was ok. But the problem exist (only for IDE). To reproduce the problem you have to download the dll source from here: https://github.com/M2000Interpreter/Environment
    First you have to change from Tools->Options->Edit Format-> Normal text->Font: Courier New Greek
    Then open mexe.vbp and make the m2000.exe
    So now you can open the M2000.vbp, start the activeX.dll and to run it start m2000.exe (all from the same folder)
    Now in M2000 console write Edit A press enter and you would see the editor, then copy code from here: https://georgekarras.blogspot.com/20...00-part-1.html
    Press Esc and write A press enter and you see that hangs.
    You can close the m2000.exe and you see that the dll in IDE wait to be used. So you stop run and run second time compiled (ctrl+F5). Repeat the example by running the m2000.exe. Edit A then paste the code press Esc, write A and press enter. Now the program run. (press a key when ask for it).
    Last edited by georgekar; Nov 15th, 2022 at 08:14 PM.

  21. #21
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,606

    Re: Is there a function to return that code running in p-code inside IDE

    Good luck (I'm not going to attempt to reproduce it, if it is not possible to generate the situation with a minimal code and no third party programs).

  22. #22

    Thread Starter
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,225

    Re: Is there a function to return that code running in p-code inside IDE

    Only those who can use debugger may help to find the reason of crash. The programme has no fault, the mysterious crash happen only in IDE before using ctrl+F5.

  23. #23
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,493

    Re: Is there a function to return that code running in p-code inside IDE

    Are there any user controls in your project?
    They can have code which behaves differently in the design time compared

  24. #24

    Thread Starter
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,225

    Re: Is there a function to return that code running in p-code inside IDE

    Yes, I have a user control on dll.

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