|
-
Jul 18th, 2005, 05:31 PM
#1
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.
-
Jul 19th, 2005, 12:49 AM
#2
Lively Member
Re: Check if Application is Running Without Timer
 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?
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:
CmdLine = Replace(CmdLine, "/ENTRY:__vbaS", "/ENTRY:DLLMain")
· Number 2: Change the Base Address to 0x10000000 using the /BASE switch
VB Code:
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:
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
-
Jul 19th, 2005, 01:19 AM
#3
Lively Member
Re: Check if Application is Running Without Timer
A basic Win32DLL code with just one EXPORT method GethInstance
VB Code:
Public hInstance As Long ' One of the useful infos we get from DllEntry point
Public Const DLL_PROCESS_DETACH = 0
Public Const DLL_PROCESS_ATTACH = 1
Public Const DLL_THREAD_ATTACH = 2
Public Const DLL_THREAD_DETACH = 3
Public Function DLLMain(ByVal hInst As Long, ByVal fdwReason As Long, lpvReserved As Long) As Long
Select Case fdwReason
Case DLL_PROCESS_DETACH
' No per-process cleanup needed
Case DLL_PROCESS_ATTACH
' No per-process initialization needed
Case DLL_THREAD_ATTACH
' No per-thread initialization needed
Case DLL_THREAD_DETACH
' No per-thread cleanup needed
End Select
hInstance = hInst ' This is the App.Instance Call
DLLMain = 1 ' Return 1 on success
End Function
Sub Main()
'This is a dummy, so the IDE doesn't complain that
'there is no Sub Main.
End Sub
Public Function GethInstance() As Long
GethInstance = hInstance ' This is a pointer to
End Function
Now Create a Standard Exe Project
VB Code:
Private Declare Function GethInstance Lib "MyDLL.dll" () As Long
Private Sub Form_Load()
MsgBox GethInstance()
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|