Results 1 to 40 of 98

Thread: Check if Application is Running Without Timer

Hybrid View

  1. #1
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Check if Application is Running Without Timer

    After reading a bit more, I've decided that the DllMain function is probably not going to work in VB.

    When you create a dll from C, the default entrypoint is the _DllMainCRTStartup function. This function initializes the C runtime libraries and then calls the DllMain function.

    I noticed that the linker parameters for the VB dll included an entry /ENTRY:__vbaS, which means that this is the VB version of _DllMainCRTStartup. Unfortunately, it probably does not make a call to any DllMain that may exist. Even if it did, our DllMain function was probably renamed when it was compiled in the object code.

    I think that the best bet is to pass the instance handle to the sethook function and see if that works.

  2. #2
    Lively Member CodeBlock's Avatar
    Join Date
    May 2005
    Location
    The_Universe.Milky_Way. Solar_System.Inner_Ring. The_Earth.Asia. India.TN. Chennai. Home_Sweet_Home
    Posts
    85

    Lightbulb Re: Check if Application is Running Without Timer

    Quote Originally Posted by moeur
    When you create a dll from C, the default entrypoint is the _DllMainCRTStartup function. This function initializes the C runtime libraries and then calls the DllMain function.

    I noticed that the linker parameters for the VB dll included an entry /ENTRY:__vbaS, which means that this is the VB version of _DllMainCRTStartup. Unfortunately, it probably does not make a call to any DllMain that may exist. Even if it did, our DllMain function was probably renamed when it was compiled in the object code.
    You were almost there moeur, but u gave up at the last moment.. Whereas i continued researching and found the click!

    Did u ever doubted to change this param just to see what could happen?
    Code:
    /ENTRY:__vbaS
    Code:
    /ENTRY:DLLMain
    One More Trick is to create your project as Standard EXE and File -> Make 'MyDLL.dll'

    I am not joking lol... but its not over yet.. You need your customized DLL to check all these... The LINKER will prompt you if u have a .DEF under your project dir, whether it shd modify the parameters and send or just compile it as usual (giving you both the options).

    If you choose Yes (the first option) 3 modifications occur in the parameters:

    · Number 1: Change the /ENTRY switch to point to DLLMain
    VB Code:
    1. CmdLine = Replace(CmdLine, "/ENTRY:__vbaS", "/ENTRY:DLLMain")

    · Number 2: Change the Base Address to 0x10000000 using the /BASE switch
    VB Code:
    1. CmdLine = Replace(CmdLine, "/BASE:0x400000", "/BASE:0x10000000")


    Here is final fantasy:
    · Number 3: Specify that we need a DLL file and not an EXE and also include the /DEF switched with the corresponding .DEF file
    VB Code:
    1. CmdLine = CmdLine & " /DLL /DEF:""" & sDEFfile & """"

    I am so excited that it works now.. And finally a breakthrough in the world of programming that we Visual Basic programmers can too create a pure Win32DLL

    HTH
    Neo

  3. #3
    Lively Member CodeBlock's Avatar
    Join Date
    May 2005
    Location
    The_Universe.Milky_Way. Solar_System.Inner_Ring. The_Earth.Asia. India.TN. Chennai. Home_Sweet_Home
    Posts
    85

    Thumbs up Re: Check if Application is Running Without Timer

    A basic Win32DLL code with just one EXPORT method GethInstance


    VB Code:
    1. Public hInstance As Long ' One of the useful infos we get from DllEntry point
    2.  
    3. Public Const DLL_PROCESS_DETACH = 0
    4. Public Const DLL_PROCESS_ATTACH = 1
    5. Public Const DLL_THREAD_ATTACH = 2
    6. Public Const DLL_THREAD_DETACH = 3
    7.  
    8. Public Function DLLMain(ByVal hInst As Long, ByVal fdwReason As Long, lpvReserved As Long) As Long
    9.    Select Case fdwReason
    10.       Case DLL_PROCESS_DETACH
    11.          ' No per-process cleanup needed
    12.       Case DLL_PROCESS_ATTACH
    13.          ' No per-process initialization needed
    14.       Case DLL_THREAD_ATTACH
    15.          ' No per-thread initialization needed
    16.       Case DLL_THREAD_DETACH
    17.          ' No per-thread cleanup needed
    18.    End Select
    19.  
    20.    hInstance = hInst  ' This is the App.Instance Call
    21.    DLLMain = 1        ' Return 1 on success
    22. End Function
    23.  
    24. Sub Main()
    25.     'This is a dummy, so the IDE doesn't complain that
    26.     'there is no Sub Main.
    27. End Sub
    28.  
    29. Public Function GethInstance() As Long
    30.     GethInstance = hInstance ' This is a pointer to
    31. End Function

    Now Create a Standard Exe Project
    VB Code:
    1. Private Declare Function GethInstance Lib "MyDLL.dll" () As Long
    2.  
    3. Private Sub Form_Load()
    4.     MsgBox GethInstance()
    5. End Sub

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