Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 655
  • Last Modified:

API Refer...

Hi, im really muzzled when it comes down to this stuff so i would like to ask for your help?

Is it possible to make a program in vb6 which can be referenced externally?
(Example: MSN Messenger, Reference to it and you can control how messages are displayed etc with a bit of code)

Can i pass parameters to my prog to control it externally?
(Exmaple: Winamp, SendMessage (AMP_HANDLE, WM_COMMAND, Winampcommand, 0))

If so could you provide some links to documentation/source/tutorials whatever can help me.

Many Thanks.
0
JuleZzZ
Asked:
JuleZzZ
  • 5
  • 3
1 Solution
 
JuleZzZAuthor Commented:
Upto now i have subclassed my app so i can run checks on what commands are being passed to it.

Heres the check which i use...

If uMsg = WM_COMMAND And wParam = 999666 Then MsgBox "Works"

but what do i do if i want to return a value so i can report my apps status. Example..

(External Prog)
intret = sendmessagelong(hwnd,wm_command, 999666, 0&)
select case intret
case 1
   msgbox "Playing"
case 2
   msgbox "Stopped"
end select


Many Thanks.
0
 
JuleZzZAuthor Commented:
Upto now i have subclassed my app so i can run checks on what commands are being passed to it.

Heres the check which i use...

If uMsg = WM_COMMAND And wParam = 999666 Then MsgBox "Works"

but what do i do if i want to return a value so i can report my apps status. Example..

(External Prog)
intret = sendmessagelong(hwnd,wm_command, 999666, 0&)
select case intret
case 1
   msgbox "Playing"
case 2
   msgbox "Stopped"
end select


Many Thanks.
0
 
y2kswCommented:
You could pass a windows handle by the lParam from the caller. So the callee could send back a user message to it.

BTW. WM_USER + 1 would be fine for messages :-)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
JuleZzZAuthor Commented:
Cheers, but one problem

Private Sub Command1_Click()
    r = SendMessageLong(blah, WM_USER, 999666, Me.hwnd)
    MsgBox r
End Sub

always returns 0 although im using this in my subclassed program.

    If uMsg = WM_USER And wParam = 999666 Then
        Call SendMessage(lParam, WM_USER, mylstatus, 0&)
    End If

i think the program controlling the subclassed program would have to subclass itsself to check the messages but i would prefer it to get a return handle?
0
 
y2kswCommented:
MSDN: SendMessage Parameters

hwnd

Identifies the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.

uMsg

Specifies the message to be sent.

wParam

Specifies additional message-specific information.

lParam

Specifies additional message-specific information.

***Return Value***

The return value specifies the result of the message processing and depends on the message sent.

---

Therefore "r" could be anything and should not be evaluated from within VB.

Instead you should subclass the caller too, and after sending the message, wait for a reply on that subclassed procedure. Note that you may use PostMessage instead of SendMessage, which allowes to proceed and not to wait for a reply which could sensibly slow down your app (asyncronous).

So:

If uMsg = WM_USER And wParam = 999666 Then
    Call SendMessage(lParam, WM_USER, mylstatus, 0&)
End If

will work, as long as "lParam"  alias "Me.hWnd" is listening for that message too.
0
 
JuleZzZAuthor Commented:
Yea i understand that but how does functions such as shellexecute return a handle without the caller subclassing itself? there must be a way?? :(
0
 
y2kswCommented:
Well, ok, you might issue an event like WM_PAINT to the calling process. If this message is unlikely to happen, you may catch this with the Form_Paint Event and react on this. But this is not a good programming practice, because if your Form.AutoRedraw is on, then the Form_Paint Event will never fire. Or else you might have a control which receives a WM_CLICK event (such as a Command Button) out of sight, and inside the Command1_Click Event you will have your code. But all these examples are not standard and may give unpredictable results, while sending a specific message back and forth is standard and will run without troubles.

Note that quiet a lot of programs comunicate by sharing a temporary file or by using a named pipe (difficult to realize with VB), or by Callback Functions (Winamp).
0
 
JuleZzZAuthor Commented:
Nice one, Thanks For Your Help :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now