You're asking MapBasic to do more than it can do. What's worse, DDE events
won't be processed while a dialog is open, since it's modal by definition.
I'm not sure why you think you can't get some MapInfo functionality via
Integrated Mapping, since in that model, everything that can't be done with
Mapinfo.Do (i.e. Run Command) should be done by your client application.
As for finding a particular app via DDE:
First of all request a list sleeping MapBasic applications from MapInfo.
Once you have the list, you can check for your app in a couple of different
ways:
1. Very likely, the filename part of the MBX is fixed, and you hardcode that
value into the DDE client app. Use PathToFilename$ on each MBX path, and
compare to the hardcoded value. The first match is your app.
2. You could create a global string variable (e.g. gsAppFilename, which is
what the tool application sample does), set it in Sub Main, and use a DDE
Peek. Other applications can poke a different value, but it's difficult to
envision this happening other than intentionally.
3. You could add a RemoteQueryHandler to the MBX serving as the DDE server
and see if the remote query string matches a conventional value (e.g.
"AreYouMyVerySpecialMapBasicApplication?"), returning "Yes" if it matches
and something else otherwise. Then, the DDE client would "Peek" for the
identifying query string and if the return value is "Yes", Bob's your uncle.