unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Jason Rumney <jasonr@gnu.org>
Cc: emacs-devel@gnu.org
Subject: emacsclientw
Date: Mon, 13 Nov 2006 11:41:14 +0000	[thread overview]
Message-ID: <455859DA.5010402@gnu.org> (raw)
In-Reply-To: <f7ccd24b0611121813s19fc0d08rbfd0ff25e8fb73de@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 384 bytes --]

Have you tested the emacsclientw.exe build with MSVC?

I think there is also a need for something that starts Emacs if it is 
not already running, so I came up with the following (based on 
runemacs.c), which I intended to check into the nt directory. The 
intention is to use this to associate Emacs with file types in Explorer 
and other applications that allow external editors.



[-- Attachment #2: emacsassoc.c --]
[-- Type: text/plain, Size: 3223 bytes --]

/* Copyright (C) 2006 Free Software Foundation, Inc.

This file is part of GNU Emacs.

GNU Emacs is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Emacs; see the file COPYING.  If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.  */


/*
  Simple program to start emacsclient or emacs with its console window
  hidden.

  This program is provided for conveniently associating emacs with
  files in Windows Explorer and other GUI programs.

  */

#include <windows.h>
#include <string.h>
#include <malloc.h>

int launch_app(char *dir_name, char *app_name, LPSTR cmd_line)
{
  STARTUPINFO start;
  SECURITY_ATTRIBUTES sec_attrs;
  PROCESS_INFORMATION child;
  int wait_for_child = FALSE;
  DWORD priority_class = NORMAL_PRIORITY_CLASS;
  DWORD ret_code = 0;
  char *new_cmd_line;

  new_cmd_line = alloca (MAX_PATH + strlen (cmd_line) + 3);

  /* Quote executable name in case of spaces in the path.  */
  *new_cmd_line = '"';
  strcpy (new_cmd_line + 1, dir_name);

  strcat (new_cmd_line, "\\");
  strcat (new_cmd_line, app_name);
  strcat (new_cmd_line, "\" ");

  /* Append original arguments if any.  */
  strcat (new_cmd_line, cmd_line);

  memset (&start, 0, sizeof (start));
  start.cb = sizeof (start);
  start.dwFlags = STARTF_USESHOWWINDOW | STARTF_USECOUNTCHARS;
  start.wShowWindow = SW_HIDE;
  /* Ensure that we don't waste memory if the user has specified a huge
     default screen buffer for command windows.  */
  start.dwXCountChars = 80;
  start.dwYCountChars = 25;

  sec_attrs.nLength = sizeof (sec_attrs);
  sec_attrs.lpSecurityDescriptor = NULL;
  sec_attrs.bInheritHandle = FALSE;

  if (CreateProcess (NULL, new_cmd_line, &sec_attrs, NULL, TRUE, priority_class,
                     NULL, NULL, &start, &child))
    {
      WaitForSingleObject (child.hProcess, INFINITE);
      GetExitCodeProcess (child.hProcess, &ret_code);

      CloseHandle (child.hThread);
      CloseHandle (child.hProcess);
    }
  else
    ret_code = 1;

  return ret_code;
}

int WINAPI
WinMain (HINSTANCE self, HINSTANCE prev, LPSTR cmd_line, int show)
{
  char dir_name[MAX_PATH];
  char *p;

  /* Figure out what directory this is run from, so we can find the
     emacsclient and emacs executables.  */
  if (!GetModuleFileName (NULL, dir_name, MAX_PATH))
    goto error;
  if ((p = strrchr (dir_name, '\\')) == NULL)
    goto error;
  *p = 0;

  if ((launch_app (dir_name, "emacsclient.exe", cmd_line) == 0)
      || launch_app(dir_name, "emacs.exe", cmd_line) == 0)
    return 0;

 error:
  MessageBox (NULL, "Could not start Emacs", "Error", MB_ICONSTOP);
  return 1;
}


[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

  parent reply	other threads:[~2006-11-13 11:41 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-12 22:17 I can't build from cvs sources on cygwin for some time now Eric Lilja
2006-11-12 22:23 ` Juanma Barranquero
2006-11-12 22:29   ` Eric Lilja
2006-11-12 22:34     ` Juanma Barranquero
2006-11-12 22:46       ` Eric Lilja
2006-11-12 22:56         ` Eric Lilja
2006-11-12 23:05           ` Juanma Barranquero
2006-11-12 23:22             ` Eric Lilja
2006-11-12 23:44               ` Juanma Barranquero
2006-11-12 23:52                 ` Eric Lilja
2006-11-13  0:07           ` Jason Rumney
2006-11-13  0:49             ` Juanma Barranquero
2006-11-13  2:13               ` Juanma Barranquero
2006-11-13  8:21                 ` Eric Lilja
2006-11-13 11:37                 ` Jason Rumney
2006-11-13 12:25                   ` Juanma Barranquero
2006-11-13 11:41                 ` Jason Rumney [this message]
2006-11-13 12:23                   ` emacsclientw Juanma Barranquero
2006-11-13 16:19                     ` emacsclientw Lennart Borgman
2006-11-13 12:36                   ` emacsclientw dhruva
2006-11-13 12:39                     ` emacsclientw Juanma Barranquero
2006-11-13 13:14                       ` emacsclientw dhruva
2006-11-13 13:31                         ` emacsclientw Juanma Barranquero
2006-11-13 22:43                         ` emacsclientw Jason Rumney
2006-11-13 22:56                           ` emacsclientw Lennart Borgman
2006-11-14  3:32                           ` emacsclientw dhruva
2006-11-14  7:18                             ` emacsclientw Mathias Dahl
2006-11-14  7:34                               ` emacsclientw Jason Rumney
2006-11-14  8:44                                 ` emacsclientw Mathias Dahl
2006-12-05 23:15                                   ` emacsclientw Stuart D. Herring
2006-11-14  8:39                               ` emacsclientw dhruva
2006-11-14  7:30                             ` emacsclientw Jason Rumney
2006-11-13 14:11                   ` emacsclientw Lennart Borgman
2006-11-13 14:40                     ` emacsclientw Juanma Barranquero
2006-11-13 19:36                       ` emacsclientw Stefan Monnier
2006-11-13 20:08                         ` emacsclientw Juanma Barranquero
2006-11-13 21:33                           ` emacsclientw Stefan Monnier
2006-11-13 22:23                             ` emacsclientw Lennart Borgman
2006-11-13 22:40                             ` emacsclientw Juanma Barranquero
2006-11-13 22:54                               ` emacsclientw Lennart Borgman
2006-11-13 23:10                                 ` emacsclientw Juanma Barranquero
2006-11-14  0:45                                   ` emacsclientw Lennart Borgman
2006-11-13 23:20                               ` emacsclientw Jason Rumney
2006-11-13 20:12                     ` emacsclientw Eli Zaretskii
2006-11-12 23:01         ` I can't build from cvs sources on cygwin for some time now Juanma Barranquero
2006-11-12 23:24           ` Eric Lilja
2006-11-12 23:45             ` Juanma Barranquero
2006-11-13 12:21 ` Eric Lilja

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=455859DA.5010402@gnu.org \
    --to=jasonr@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).