Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ “a”解决了哪些问题;COM-like";框架_C++_C_Com_Gobject - Fatal编程技术网

C++ “a”解决了哪些问题;COM-like";框架

C++ “a”解决了哪些问题;COM-like";框架,c++,c,com,gobject,C++,C,Com,Gobject,我经常看到该库与类似COM Windows的解决方案相比较,一般来说,我并不真正了解这个框架应该解决什么样的问题,以及采用它们带来的好处 我已经找到了一些小的答案,比如“它是一个可以轻松地将C库移植到其他语言的包装器”,但是GObject还提供了其他功能,比如信号/插槽机制,其中还涉及到其他一些东西,但我并不真正了解这一点 您能用简单的古英语解释一下吗?COM和类似的库提供了创建和使用二进制面向对象组件的能力 “二进制”意味着它是相当独立的语言,在C、C++、Pascal等中是可访问的。 COM

我经常看到该库与类似COM Windows的解决方案相比较,一般来说,我并不真正了解这个框架应该解决什么样的问题,以及采用它们带来的好处

我已经找到了一些小的答案,比如“它是一个可以轻松地将C库移植到其他语言的包装器”,但是GObject还提供了其他功能,比如信号/插槽机制,其中还涉及到其他一些东西,但我并不真正了解这一点


您能用简单的古英语解释一下吗?

COM和类似的库提供了创建和使用二进制面向对象组件的能力

“二进制”意味着它是相当独立的语言,在C、C++、Pascal等

中是可访问的。 COM上一个名为“自动化”的层提供了从脚本语言访问专门支持“自动化”的组件的能力


作为一个具体示例,Windows API提供了一个表示(并可以创建或修改)Windows快捷方式的自动化COM组件。Windows快捷方式是有点像符号链接的“.lnk”文件,只是应用程序必须显式取消引用它们。在我写这篇文章的计算机上,mingwg++安装包含一个JavaScript程序,使基于COM的功能可以作为一个简单的命令行命令使用

在该程序中创建COM对象:

var Shortcut = WinShell.CreateShortcut( prefix + assigned[lnkname] );
其中,
WinShell
是另一个Windows API COM对象,通过脚本主机环境提供的函数创建

完整的程序:

>MinGW\libexec\MinGW get\shlink.js
/*
*shlink.js
*
*$Id:shlink.js,v1.1 2012/04/06 22:49:36 keithmarshall Exp$
*
*调用Windows脚本主机以创建或修改Windows快捷方式,
*使用指定的参数。
*
*用法:
*cscript-nologo shlink.js[--option[=value]…]目标名称
*
*选项:
*--标准输出上的详细报告快捷方式参数分配
*
*--所有用户
*在“开始”菜单或上创建快捷方式
*桌面可供所有用户使用;(b)没有效力,
*除非指定了--“开始”菜单或--“桌面”)
*
*--桌面在当前用户的桌面上创建快捷方式
*用户(或对于所有用户,使用--all users)
*
*--开始菜单
*在用户的“开始”菜单中创建快捷方式(或
*所有用户的开始菜单,带有--all users)
*
*--arguments=“参数列表…”
*指定要传递给命令的参数
*由快捷方式调用
*
*--description=“text…”
*指定快捷方式的“工具提示”
*
*--热键=“[SHIFT+][CTRL+][ALT+]键”
*指定可以使用的热键组合
*调用快捷方式命令的步骤
*
*--icon=“d:\path\to\icon\file[,index]”
*指定要与快捷方式关联的图标;
*如果未指定,则为目标文件中的第一个图标,
*否则,将使用系统默认值
*
*--显示=正常|最大化|最小化
*指定程序所在窗口的样式
*由快捷方式调用的将开始运行
*
*--workingdir=“d:\path\to\working\directory”
*指定目录的绝对路径名
*将成为当前的工作目录
*启动快捷方式调用的程序
*
*参数:
*指向要调用的程序或文件的路径名
*要在快捷方式激活时打开。
*
*命名快捷方式文件本身的路径名;如果这
*不以“.lnk”或“.url”扩展名结尾,
*然后将附加“.lnk”,因此创建一个正则表达式
*文件系统链接类型快捷方式。
*
*
*该文件是mingw-get的一个组件。
*
*基思·马歇尔撰写
*版权所有(C)2012,MinGW项目
*
*
*特此免费向获得许可的任何人授予许可
*本软件和相关文档文件的副本(“软件”),
*不受限制地处理软件,包括但不限于
*使用、复制、修改、合并、发布、分发、再许可、,
*和/或出售软件副本,并允许
*为此提供的软件应符合以下条件:
*
*应包括上述版权声明和本许可声明
*在软件的所有副本或主要部分。
*
*本软件按“原样”提供,不提供任何形式的明示担保
*或暗示,包括但不限于适销性保证,
*适用于特定目的和非侵权。在任何情况下均不得
*作者或版权持有人应承担任何索赔、损害或其他责任
*无论是合同诉讼、侵权诉讼还是其他诉讼中产生的责任
*来自、不属于或与软件、使用或其他相关
*软件的交易。
*
*/
var cmdName=WScript.ScriptName;
var WinShell=WScript.CreateObject(“WScript.Shell”);
/*快捷方式的属性可以指定为参数
*到命令行选项,每个选项在
*GNU长选项表单,按具有属性关联的关键字
*按照以下规定:
*/
变量选项=数组(
.lnk文件的“name”、/*文件名/路径*/
“所有用户”,
“开始菜单”,
“桌面”,
“冗长”,
/* 
*期权性质
*  -------------     -------------------------
*/ 
“参数”、/*快捷方式。参数*/
“description”、/*快捷方式。description*/
“热键”,/*快捷键。热键*/
“icon”,/*Shortcut.IconLocation*/
“show”、/*Shortcut.WindowStyle*/
“target”,/*Shortcut.TargetPath*/
“workingdir”/*Shortcut.WorkingDirectory*/
);
/*“投诉”功能提供了
/*
 * shlink.js
 *
 * $Id: shlink.js,v 1.1 2012/04/06 22:49:36 keithmarshall Exp $
 *
 * Invoke the Windows Scripting Host to create or modify a windows shortcut,
 * with specified parameters.
 *
 * Usage:
 *   cscript -nologo shlink.js [--option[=value] ...] target name
 *
 * Options:
 *   --verbose  report shortcut parameter assignments on stdout
 *
 *   --all-users
 *          create the shortcut in the start menu, or on the
 *          desktop available to all users; (has no effect,
 *          unless --start-menu or --desktop is specified)
 *
 *   --desktop  create the shortcut on the desktop of the current
 *          user, (or for all users, with --all-users)
 *
 *   --start-menu
 *          create the shortcut in the user's start menu, (or
 *          all users' start menu, with --all-users)
 *
 *   --arguments="argument list ..."
 *      specify arguments to be passed to the command
 *      invoked by the shortcut
 *
 *   --description="text ..."
 *      specify the "tool tip" for the shortcut
 *
 *   --hotkey="[SHIFT+][CTRL+][ALT+]key"
 *          specify a hot-key combination which may be used
 *          to invoke the shortcut command
 *
 *   --icon="d:\path\to\icon\file[,index]"
 *          specify an icon to associate with the shortcut;
 *          if unspecified, the first icon in the target file,
 *          or failing that, a system default is used
 *
 *   --show=normal|maximised|minimised
 *          specify the style of window in which the program
 *          invoked by the shortcut will start running
 *
 *   --workingdir="d:\path\to\working\directory"
 *          specify the absolute path name for the directory
 *          which will become the current working directory when
 *          the program invoked by the shortcut is started
 *
 * Parameters:
 *   target the path name to the program to invoke, or the file
 *      to be opened, when the shortcut is activated.
 *
 *   name   the path name for the shortcut file itself; if this
 *      does not end with either a ".lnk" or ".url" extension,
 *      then ".lnk" will be appended, so creating a regular
 *      file system link type shortcut.
 *
 *
 * This file is a component of mingw-get.
 *
 * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
 * Copyright (C) 2012, MinGW Project
 *
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 */
var cmdName = WScript.ScriptName;
var WinShell = WScript.CreateObject("WScript.Shell");

/* Properties for the shortcut may be specified as arguments
 * to command line options, each of which is represented in the
 * GNU long option form, by keywords with property associations
 * as specified by:
 */
var options = Array(
      "name",       /*  File name/path of .lnk file */
      "all-users",
      "start-menu",
      "desktop",
      "verbose",
  /* 
   *  Option            Property
   *  -------------     -------------------------
   */ 
      "arguments",  /*  Shortcut.Arguments      */
      "description",    /*  Shortcut.Description    */
      "hotkey",     /*  Shortcut.HotKey     */
      "icon",       /*  Shortcut.IconLocation   */
      "show",       /*  Shortcut.WindowStyle    */
      "target",     /*  Shortcut.TargetPath     */
      "workingdir"  /*  Shortcut.WorkingDirectory   */
    );

/* The "complain" function provides a mechanism for writing
 * diagnostic messages to stderr, and optionally aborting the
 * calling script.
 */
function complain( condition, message )
{
  WScript.StdErr.WriteLine( cmdName + ": " + message );
  if( condition < 0 )
    WScript.Quit( -condition );
  return condition;
}

/* Strip ".js" suffix from command name.
 */
var i = cmdName.lastIndexOf( ".js" );
if( (i > 0) &&  (cmdName.substr( i ) == ".js") )
  cmdName = cmdName.substr( 0, i );

/* Initialise all options to "unassigned" state.
 */
var target = -1;
var lnkname = -1;
var desktop = -1;
var allusers = -1;
var startmenu = -1;
var verbosity = -1;
var unassigned = "+++unassigned+++";
var assigned = Array( options.length );
for( var k = 0; k < assigned.length; k++ )
{
  switch( options[k] )
  {
    case "name":
      lnkname = k;
      break;

    case "desktop":
      desktop = k;
      break;

    case "start-menu":
      startmenu = k;
      break;

    case "all-users":
      allusers = k;
      break;

    case "target":
      target = k;
      break;

    case "verbose":
      verbosity = k;
  }
  assigned[k] = unassigned;
}

/* Define the prefix, which will qualify the location
 * of the shortcut; initialise it to nothing, so that by
 * default shortcuts will be located by absolute path name,
 * as specified, or relative to current working directory.
 */
var prefix = "";

var j;
function assign_option( name, value )
{
  switch( name )
  {
    case "desktop":
    case "start-menu":
    case "all-users":
    case "verbose":
      j = i;
      return "set";
  }
  return value;
}

/* Parse the command line.
 */
var argv = WScript.Arguments;
for( i = 0; i < argv.length; i++ )
{
  if( argv( i ).indexOf( "--" ) == 0 )
  {
    /* Handle arguments specifying options...
     */
    if( (optind = argv( j = i ).indexOf( "=" ) + 1) > 3 )
    {
      optnam = argv( j ).substr( 2, optind - 3 );
      optarg = argv( j ).substr( optind );
    }
    else
    {
      optnam = argv( j ).substr( 2 );
      if( ++j < argv.length )
    optarg = argv( j );
      else
    optarg = unassigned;
    }

    var matched = 0;
    for( var k = 0; k < options.length; k++ )
    {
      if( optnam == options[k] )
      {
    matched = 1;
    assigned[k] = assign_option( options[k], optarg );
    k = options.length;
      }
      else if( options[k].indexOf(optnam) == 0 )
      {
    if( ++matched > 1 )
      complain( -2, cmdName + "option '" + argv( i ) + "' is ambiguous" );
    assigned[k] = assign_option( options[k], optarg );
      }
    }
    if( matched == 1 )
    {
      i = j;
    }
    else
      complain( -2, "option '" + argv( i ) + "' is not supported" );
  }

  /* Handle non-option arguments...
   */
  else if( (target >= 0) && (assigned[target] == unassigned) )
    /*
     * ...the first of which is the target to which the
     * (shortcut) link is to refer...
     */
    assigned[target] = argv( i );

  else if( (lnkname >= 0) && (assigned[lnkname] == unassigned) )
    /*
     * ...the second is the file system path name at which
     * the link file itself is to be saved...
     */
    assigned[lnkname] = argv( i );

  else
    /* ...and any more than two is an error.
     */
    complain( -2, "too many arguments" );
}

/* Verify that mandatory arguments have been specified...
 */
if( assigned[target] == unassigned )
  /*
   * First of these, the TargetPath specification, is required;
   * diagnose and abort, if missing.
   */
  complain( -2, "missing argument: no target path specified" );

if( assigned[lnkname] == unassigned )
  /*
   * Second, the path name for the link file itself is essential;
   * again, diagnose and abort if missing.
   */
  complain( -2, "missing argument: no shortcut name specified" );

/* We have both the mandatory arguments; check that the link name
 * is properly terminated by a ".lnk" or ".url" suffix...
 */
var suffix = "";
if( (i = assigned[lnkname].length - 4) > 0 )
  suffix = assigned[lnkname].substr( i );

/* ...and append ".lnk" as default, if not already present.
 */
if( (suffix != ".lnk") && (suffix != ".url") )
  assigned[lnkname] += ".lnk";

/* Add the appropriate prefix for '--desktop' or '--start-menu' shortcuts.
 */
if( assigned[desktop] != unassigned )
{
  if( assigned[startmenu] != unassigned )
    complain( -2, "options '--desktop' and '--start-menu' are incompatible" );
  else prefix = WinShell.SpecialFolders( (assigned[allusers] == unassigned)
      ? "Desktop" : "AllUsersDesktop" ) + "\\";
}
else if( assigned[startmenu] != unassigned )
  prefix = WinShell.SpecialFolders( (assigned[allusers] == unassigned)
      ? "StartMenu" : "AllUsersStartMenu" ) + "\\";

else if( assigned[allusers] != unassigned )
  complain( -2,
      "option '--all-users' also requires '--desktop' or '--start-menu'"
    );

/* Handle verbosity...
 */
function verbose_assignment( property, value )
{
  if( assigned[verbosity] == "set" )
    WScript.Echo( cmdName + ": set " + property + " = " + value );
}

/* Initialise the shortcut entity reference.
 */
if( assigned[verbosity] == "set" )
  WScript.Echo( cmdName + ": create shortcut: " + prefix + assigned[lnkname] );

var Shortcut = WinShell.CreateShortcut( prefix + assigned[lnkname] );

for( var k = 0; k < options.length; k++ )
{
  if( assigned[k] != unassigned )
    switch( options[k] )
    {
      case "arguments":
    verbose_assignment( "Shortcut.Arguments", assigned[k] );
    Shortcut.Arguments = assigned[k];
    break;

      case "description":
    verbose_assignment( "Shortcut.Description", assigned[k] );
    Shortcut.Description = assigned[k];
    break;

      case "hotkey":
    verbose_assignment( "Shortcut.HotKey", assigned[k] );
    Shortcut.HotKey = assigned[k];
    break;

      case "icon":
    verbose_assignment( "Shortcut.IconLocation", assigned[k] );
    Shortcut.IconLocation = assigned[k];
    break;

      case "show":
    verbose_assignment( "Shortcut.WindowStyle", assigned[k] );
        var style = Array(
        "normal",     1,
        "maximised",  3,
        "maximized",  3,
        "minimised",  7,
        "minimized",  7
      );
    for( j = 0; j < style.length; j++ )
      if( style[j++].indexOf( assigned[k] ) == 0 )
      {
        Shortcut.WindowStyle = style[j];
        j = 100;
      }
    if( j < 100 )
      complain( 1, "unrecognised mode '--show=" + assigned[k] + "' ignored" );
    break;

      case "target":
    verbose_assignment( "Shortcut.TargetPath", assigned[k] );
    Shortcut.TargetPath = assigned[k];
    break;

      case "workingdir":
    verbose_assignment( "Shortcut.WorkingDirectory", assigned[k] );
    Shortcut.WorkingDirectory = assigned[k];
    }
  else if( assigned[verbosity] == "set" )
    WScript.Echo( cmdName + ": option '--" + options[k] + "' is unassigned" );
}

/* Commit the shortcut entity to disk.
 */
Shortcut.Save();

/* $RCSfile: shlink.js,v $: end of file */