views:

128

answers:

1

Using the C/C++ Windows API RegisterWindowMessage()

I am using the name of the application as the message name.

Next I call CreatMutex() using the same name so that I can tell if it already exists. If it does, I know this application is already running and not to launch a second instance of it. THis is the operation of my function Running()

My confusion is over the message name. It seems that "AutoConvert.exe" and "AutoAppend.exe" are interpreted as the same name. Why?

Added: Im not at my machine but this is something like the function that is called in both apps to check if the app is currently running

INT AlreadyRunning( string sAppName ) {
    INT runchk = RegisterWindowMessage( sAppName.c_str() );
    INT retval = CreateMutex( 0, 1, sAppName.c_str() );
    if( retval > 0 ) {
        if( GetLastError = ERROR_ALREADY_EXISTS ) {
        SendMessage HWND_BROADCAST, runchk, 0, 0;
        return 1;
        }
    }
    return 0;
}

When I get back I need to do some further testing as you make a good point.

A: 

This code:

#include <windows.h>
#include <stdio.h>

int main() {
    int m1 = RegisterWindowMessage( "AutoConvert.exe" );
    int m2 = RegisterWindowMessage( "AutoAppend.exe" );

    printf( "%d %d\n", m1, m2 );
}

for me prints two different integer values (i.e. it has registered two different messages) - what does it print for you?

anon
Thank you for your comments. See above
Mike Trader