|
-
Mar 28th, 2002, 04:50 PM
#1
Thread Starter
New Member
DLL talking to an EXE... possible!?!?
Hi,
I have an exe that sits on the web server an monitors activity of an application written in ASP. The ASP application allows users to upload files onto the server via an activeX component (dll)...
Is it possible for a message to say "A file has just been uploaded" in the exe after a user has uploaded a file via the dll? How do I get the 2 pieces to talk to each other? Or is there a way I can combine the two?
Thanks in advance,
-
Mar 28th, 2002, 06:11 PM
#2
You can create user-defined messages and use SendMessage from the dll code to the .EXE process.
eg. in the dll
Code:
Private Const WM_USER = &H400
Long hWnd ' window handle for the .EXE file
SendMessage, hWnd,strFileName,0&,0&,0&
in the .EXE file
Code:
Public Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const GWL_WNDPROC = (-4)
Public Const WM_PASTE = &H302
Public WinProcOld As Long
Public Function WinProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim i As Integer
Dim strText As String
If wMsg = WM_USER Then
' process the messagestring here
' wMsg is the file name
End If
WinProc = CallWindowProc(WinProcOld&, hwnd&, wMsg&, wParam&, lParam&)
End Function
Sub SubClassWnd(hwnd As Long)
WinProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WinProc)
End Sub
Sub UnSubclassWnd(hwnd As Long)
SetWindowLong hwnd, GWL_WNDPROC, WinProcOld&
End Sub
Call SubClassWnd at startup and UnSubCLassWnd at Form Unload - in the .EXE
-
Mar 29th, 2002, 09:48 AM
#3
Thread Starter
New Member
thanks for code:
hi jim,
thanks for the code!
im a bit new to VB, and definitely new to the whole sendmessage/window handle thing... if you could help me out by giving me some more specifics about how to implement this code, i would appreciate it. i have a few questions:
1. does the code you provided for the dll have to be written into the BAS module? do i also need to define the function "sendmessage" by typing the following:
"Public Declare Function SendMessage Lib "user32" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long"?
2. how does my dll know what the handle to the exe is? is "long hwnd" all i need to type?
3. in the exe code, there is a condition line "if wMsg = WM_USER" but the constant WM_USER was defined in the dll, not the exe. does this need to be defined in the exe as well?
Thanks again!
-
Mar 29th, 2002, 11:13 AM
#4
1. yes in a BAS module, in a public function. Yes, that is how to declare it.
2. There are about 5 different way to get the hWnd. the easiest is to use FindWindow. This requires that the .EXE has a window
and that you kinow the window title (upper right, in the topmost bar) and that only one process exists on that PC with that particlar title. Since I have no idea what your app is - this one finds the name of whatever you enter, then closes that process & window using PostMessage (almost the same as SendMessage)
Ignore the stuff about classes of windows - you use that when you aren't sure if you have the right window
Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Const SW_SHOWNORMAL = 1
Const WM_CLOSE = &H10
Const gcClassnameMSWord = "OpusApp"
Const gcClassnameMSExcel = "XLMAIN"
Const gcClassnameMSIExplorer = "IEFrame"
Const gcClassnameMSVBasic = "wndclass_desked_gsk"
Const gcClassnameNotePad = "Notepad"
Const gcClassnameMyVBApp = "ThunderForm"
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String
'Ask for a Window title
Ret = InputBox("Enter the exact window title:" + Chr$(13) + Chr$(10) + "Note: must be an exact match")
'Search the window
WinWnd = FindWindow(vbNullString, Ret)
If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
'Show the window
ShowWindow WinWnd, SW_SHOWNORMAL
'Create a buffer
lpClassName = Space(256)
'retrieve the class name
RetVal = GetClassName(WinWnd, lpClassName, 256)
'Show the classname
MsgBox "Classname: " + Left$(lpClassName, RetVal)
'Post a message to the window to close itself
PostMessage WinWnd, WM_CLOSE, 0&, 0&
End Sub
3. All constants have to be degfined on both ends
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
|