Autor Tema: recibir parámetros  (Leído 3446 veces)

0 Usuarios y 1 Visitante están viendo este tema.

yokesee

  • Bytes
  • *
  • Mensajes: 35
  • Reputación: +1/-0
    • Ver Perfil
recibir parámetros
« en: Abril 23, 2016, 12:04:34 am »
hola estoy haciendo un programa que conecta chrome con mi exe
He conseguido hacer una extensión que conecte con el exe y mande parámetros el problema es que no los se recibir bien en vb6
lo e conseguido hacer en c# pero es un lenguaje que no conozco mucho.


e probado MsgBox Command$ en el evento main pero solo recibo una vez los parametros tambien e probado con un timer MsgBox Command$ que me este diciendo el commando pero tampoco.

os dejo el codigo de c# que me funciona

Código: [Seleccionar]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            while (OpenStandardStreamIn() != null || OpenStandardStreamIn() != "")
            {
                //Console.WriteLine(OpenStandardStreamIn());
                string a;
                a = OpenStandardStreamIn();
                if (a == "") {
                    System.Environment.Exit(0);
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show(a);
                }
               
            }
        }

        private static string OpenStandardStreamIn()
        {
            //Read first four bytes for length information
            System.IO.Stream stdin = Console.OpenStandardInput();
            int length = 0;
            byte[] bytes = new byte[4];
            stdin.Read(bytes, 0, 4);
            length = System.BitConverter.ToInt32(bytes, 0);

            string input = "";
            for (int i = 0; i < length; i++)
                input += (char)stdin.ReadByte();

            return input;
        }
    }
}

un saludo

Virgil Tracy

  • Kilobyte
  • **
  • Mensajes: 64
  • Reputación: +38/-1
    • Ver Perfil
Re:recibir parámetros
« Respuesta #1 en: Abril 24, 2016, 08:07:37 am »
Command$ devuelve todos los comandos en una sola linea, te faltaba separarlos usando un caracter delimitador, como en split()

Código: (VB) [Seleccionar]
Option Explicit

Public Sub Main()
Dim i As Integer, a

a = GetCommandLine()

For i = 1 To UBound(a)
    MsgBox a(i), vbInformation
Next

End Sub

'/// esta funcion me parece que es del guille
'/// se parece a la funcion split(),
'/// usa como delimitadores de commandos el espacio, el tab, o la coma
'///
Public Function GetCommandLine(Optional nMaxArgs As Integer = 10)
Dim c As String, cLíneaComando As String, nLen As Integer
Dim bArgIn As Boolean, i As Integer, nNroArgs As Integer

ReDim ArgArray(nMaxArgs)

nNroArgs = 0
bArgIn = False

cLíneaComando = Command()
nLen = Len(cLíneaComando)

For i = 1 To nLen

    c = Mid(cLíneaComando, i, 1)
   
    'Comprueba espacio o tabulación.
    If (c <> " " And c <> vbTab And c <> ",") Then
   
       If Not bArgIn Then
         
         If nNroArgs = nMaxArgs Then
            Exit For
         End If
         
         nNroArgs = nNroArgs + 1
         bArgIn = True
       
       End If
       
       ArgArray(nNroArgs) = ArgArray(nNroArgs) & c
       
    Else
       
       bArgIn = False
   
    End If

Next

ReDim Preserve ArgArray(nNroArgs)

GetCommandLine = ArgArray()

End Function


yokesee

  • Bytes
  • *
  • Mensajes: 35
  • Reputación: +1/-0
    • Ver Perfil
Re:recibir parámetros
« Respuesta #2 en: Abril 24, 2016, 10:22:54 am »
muchas gracias Virgil Tracy
el problema es que se cierra el programa una vez recibidos los comandos y se cierra la conexion no se como hacer para para mantener el programa abierto y pueda recibir probe ponerlo en el form y si funciona no se cierra la conexion pero si intento mandar mas datos no los recibe.
aqui pongo el codigo javascript

manifest.json
Código: [Seleccionar]
{
    // Extension ID: knldjmfmopnpolahpmmgbagdohdnhkik
    "key":"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDcBHwzDvyBQ6bDppkIs9MP4ksKqCMyXQ/A52JivHZKh4YO/9vJsT3oaYhSpDCE9RPocOEQvwsHsFReW2nUEc6OLLyoCFFxIb7KkLGsmfakkut/fFdNJYh0xOTbSN8YvLWcqph09XAY2Y/f0AL7vfO1cuCqtkMt8hFrBGWxDdf9CQIDAQAB",
    "name": "Native Messaging Example",
    "version": "1.0",
    "manifest_version": 2,
    "description": "Send a message to a native application.",
    "browser_action": {
    "default_title": "Test Extension",
    "default_popup": "main.html"
    },
    "icons": {
    "128": "icon-128.png"
    },
    "background": {
    "scripts": ["background.js"],
    "persistent": false
    },
    "permissions": [
    "nativeMessaging"
    ]
}

main.js
Código: [Seleccionar]
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

var port = null;

var getKeys = function(obj){
   var keys = [];
   for(var key in obj){
      keys.push(key);
   }
   return keys;
}


function appendMessage(text) {
  document.getElementById('response').innerHTML += "<p>" + text + "</p>";
}

function updateUiState() {
  if (port) {
    document.getElementById('connect-button').style.display = 'none';
    document.getElementById('input-text').style.display = 'block';
    document.getElementById('send-message-button').style.display = 'block';
  } else {
    document.getElementById('connect-button').style.display = 'block';
    document.getElementById('input-text').style.display = 'none';
    document.getElementById('send-message-button').style.display = 'none';
  }
}

function sendNativeMessage() {
  message = {"text": document.getElementById('input-text').value};
  port.postMessage(message);
  appendMessage("Sent message: <b>" + JSON.stringify(message) + "</b>");
}

function onNativeMessage(message) {
  appendMessage("Received message: <b>" + JSON.stringify(message) + "</b>");
}

function onDisconnected() {
  appendMessage("Failed to connect: " + chrome.runtime.lastError.message);
  port = null;
  updateUiState();
}

function connect() {
  var hostName = "com.google.chrome.example.echo";
  appendMessage("Connecting to native messaging host <b>" + hostName + "</b>")
  port = chrome.runtime.connectNative(hostName);

  port.onMessage.addListener(onNativeMessage);
  port.onDisconnect.addListener(onDisconnected);
  updateUiState();
}

document.addEventListener('DOMContentLoaded', function () {
  document.getElementById('connect-button').addEventListener(
      'click', connect);
  document.getElementById('send-message-button').addEventListener(
      'click', sendNativeMessage);
  updateUiState();
});


com.google.chrome.example.echo-win.json
Código: [Seleccionar]
{
    "name": "com.google.chrome.example.echo",
    "description": "Chrome Native Messaging API Example Host",
    "path": "c.exe",
    "type": "stdio",
    "allowed_origins": [
    "chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/"
    ]
}

muy importante hay que registrar la llamada al host en el registro ejemplo:
install_host.bat
Código: [Seleccionar]
REG ADD "HKCU\Software\Google\Chrome\NativeMessagingHosts\com.google.chrome.example.echo" /ve /t REG_SZ /d "%~dp0com.google.chrome.example.echo-win.json" /f

lo siento no se si se podían subir archivos al foro no vi la opción lo puse todo por si alguien esta interesado.
yo lo quiero usar para mandar acciones a mi programa cuando haga click en unos botones para mostrarme un menú personalizado y poder rellenar a mi gusto muchas cosas.

un saludo y gracias