Bay Six Software Forum Index Bay Six Software
Beyond the Basics
 
 FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help Communicating between 2 instances

 
Post new topic   Reply to topic    Bay Six Software Forum Index -> General Discussions
View previous topic :: View next topic  
Author Message
RogerT
New Member


Joined: 04 May 2014
Posts: 4

PostPosted: Jul 1st, 2014, 3:55am    Post subject: Help Communicating between 2 instances Reply with quote

I need to find a way for my the second instance of my program to communicate with the first instance. I've already got the files associated and the program will open and load the file when I click on the file.

I need the second instance to tell the first instance to load the next file when clicked. I'm using hmutex to do this. I have tried using hmutex and SendMessage to do this but keep getting access denied from SendMessage.

As a last resort I tried to use hmutex and DestroyWindow to shut down the first instance and load the second one and get access denied from DestroyWindow. After that I researched that I couldn't do this.

I just need to find a way to find a way load the next file clicked instead of having a popup stating that my application is already loaded.

Any suggestion?

Thanks, Roger
Back to top
View user's profile Send private message
Brent
Site Admin


Joined: 01 Jul 2005
Posts: 797

PostPosted: Jul 1st, 2014, 8:37pm    Post subject: Re: Help Communicating between 2 instances Reply with quote

Hi Roger,

I wrote and tested this, so hopefully it does what you want.
Code:
' One Instance of an App Using Mutex and IPC
' By Brent D. Thorn 7/2014
' PUBLIC DOMAIN

title$ = "My LB App"
Struct copydata, dwData As ULong, cbData As ULong, lpData As Ptr

CallDLL #kernel32, "CreateMutexA", _NULL As ULong, 1 As Long, "MyLBAppMutex2014" As Ptr, hMutex As ULong
CallDLL #kernel32, "GetLastError", dwErr As ULong
If dwErr = 183 Then ' ERROR_ALREADY_EXISTS
    CallDLL #kernel32, "CloseHandle", hMutex As ULong, ret As Long
    CallDLL #user32, "FindWindowA", _NULL As ULong, title$ As Ptr, hwndInitial As ULong
    copydata.cbData.struct = Len(CommandLine$)
    copydata.lpData.struct = CommandLine$
    CallDLL #user32, "SendMessageA", hwndInitial As ULong, _WM_COPYDATA As ULong, _NULL As ULong, copydata As Struct, ret As Long
    End
End If

TextBox #app.file, 5, 5, 240, 20
Open title$ For Window As #app
#app "TrapClose [Quit]"
#app.file CommandLine$

hWnd = HWnd(#app)
Open "WMLiberty" For DLL As #wmlib
Callback lpfn, WMHandler(ULong, ULong, ULong, ULong), Long
CallDLL #wmlib, "SetWMHandler", hWnd As ULong, _WM_COPYDATA As ULong, lpfn As ULong, -1 As Long, ret As Long

[Wait]
    Scan
    CallDLL #kernel32, "Sleep", 1 As ULong, ret As Void
    GoTo [Wait]

[Quit]
Close #app
Close #wmlib
End

Function WMHandler(hwnd, msg, wparam, lparam)
    If msg = _WM_COPYDATA Then
        copydata.struct = lparam
        file$ = WinString(copydata.lpData.struct)
        #app.file file$
        WMHandler = -1
    End If
End Function

_________________
Brent
Back to top
View user's profile Send private message Send e-mail
RogerT
New Member


Joined: 04 May 2014
Posts: 4

PostPosted: Jul 1st, 2014, 9:26pm    Post subject: Re: Help Communicating between 2 instances Reply with quote

Thanks, I'll try this shortly when I get time to get into it. This looks similar to what I tried to do before but I didn't use WmLiberty.

I do use WmLiberty for drag and drop. So I got the drag and drop working from when I pm'ed you a few days ago.

Just so you know, I'm using this in my Mp3 player, ChallengerAmp.

You can get it from rtsystemcomponents.com/Camp/Camp.html .

I'll delete the above line if you want.

I'll try this later when I get time.

Thank, Roger
Back to top
View user's profile Send private message
RogerT
New Member


Joined: 04 May 2014
Posts: 4

PostPosted: Jul 4th, 2014, 6:48pm    Post subject: Re: Help Communicating between 2 instances Reply with quote

Thanks for the help. This headed me in the right direction. With some modifications and additions I have implemented it into my application. I just need to debug some more but it seems to be working good now.

The reason I kept getting access denied error before is I was trying to use the securityAttributes struct.

Thanks, Roger
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Bay Six Software Forum Index -> General Discussions All times are GMT
Page 1 of 1
Jump to:  
Quick Reply
Username:
Message:
   Shortcut keys: Alt+Q to activate, Alt+P to preview, Alt+S to submit
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum



Lo-Fi Version
Powered by phpBB © 2001, 2005 phpBB Group