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.
JuleZzZAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JuleZzZAuthor Commented:
Nice one, Thanks For Your Help :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.