CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2012
    Posts
    3

    CreateProcess inside NPAPI plugin

    Hello
    I am trying to create a function inside a NPAPI plugin that will execute a command received as an argument using CreateProcess...
    I managed somehow to convert from const char to LPCWSTR, the plugin loads in the browser but when I try to call the function in breaks and it displays Plugin cannot be loaded... ( javascript error )

    Bellow is the code, the plugin is built using FireBreath

    Code:
    // Method run
    FB::variant HarrisonRunCmdPluginAPI::runCommand(const char command)
    {
        STARTUPINFO startupInfo = {0};
    	startupInfo.cb = sizeof(startupInfo);
    
    	PROCESS_INFORMATION processInformation;
    	
    	LPCWSTR cmd = (LPCWSTR)command;
    
    	// Try to start the process
    	BOOL result = ::CreateProcess(
    	  cmd,
    	  NULL,
    	  NULL,
    	  NULL,
    	  FALSE,
    	  NORMAL_PRIORITY_CLASS,
    	  NULL,
    	  NULL,
    	  &startupInfo,
    	  &processInformation
    	);
    
    	if(result == 0)
    	  return("Could not create process");
    	else
    		return true;
    }
    if I hardcode an exe file like "c:\\windows\\notepad.exe" it works with no problem...

    Can someone tell me what I am doing wrong...

    Thank you

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: CreateProcess inside NPAPI plugin

    Quote Originally Posted by bula View Post
    Bellow is the code, the plugin is built using FireBreath
    Code:
    // Method run
    FB::variant HarrisonRunCmdPluginAPI::runCommand(const char command)
    ...
    You are passing the command as a single character!
    But I hope you assumed to pass it in as a const char* command!
    Didn't you?
    Victor Nijegorodov

  3. #3
    Join Date
    Feb 2012
    Posts
    3

    Re: CreateProcess inside NPAPI plugin

    if I put const char* I get the following error on compile:

    54): error C2665: 'FB::variant_detail::conversion::convert_variant' : none of the 5 overloads could convert all the argument types

    I have a little experience with js and php my in visual c++ I am noob

    can you please help me...

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: CreateProcess inside NPAPI plugin

    Well, I have no experience with js and php either!
    Perhaps you show us what 'FB::variant_detail::conversion::convert_variant' and
    Quote Originally Posted by bula
    Code:
    FB::variant HarrisonRunCmdPluginAPI::runCommand(...)
    are?
    Victor Nijegorodov

  5. #5
    Join Date
    Feb 2012
    Posts
    3

    Re: CreateProcess inside NPAPI plugin

    I am not sure, almost all the code in the project is generated by firebreath... i just wrote this function form an example function...

    HarrisonRunCmdPluginAPI is the object that that contains all the methods of the NPAPI plugin...

    and FB is the firebreath class from witch ( I think )
    HarrisonRunCmdPluginAPI ( my class ) inherits some methods needed for functionality...


    for example if I replace all the code in the function with:

    Code:
       return command;
    When I call the obj from js I get the argument back with no trouble at all...

  6. #6
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: CreateProcess inside NPAPI plugin

    Sorry but such an :info: doesn't help at all! I already wrote that I have no idea what that plugin is...

    And BTW, don't you get some compiler warning messages about this line:
    Quote Originally Posted by bula
    Code:
    FB::variant HarrisonRunCmdPluginAPI::runCommand(const char command)
    {
    	...	
    	LPCWSTR cmd = (LPCWSTR)command;
    Victor Nijegorodov

  7. #7
    Join Date
    Apr 1999
    Posts
    27,449

    Re: CreateProcess inside NPAPI plugin

    Quote Originally Posted by bula View Post
    I am not sure, almost all the code in the project is generated by firebreath... i just wrote this function form an example function...
    But somewhere the compiler is seeing that function, else it would not have given the error.
    and FB is the firebreath class from witch ( I think )
    HarrisonRunCmdPluginAPI ( my class ) inherits some methods needed for functionality...
    Do not describe what you think it is.

    Do a search for the function declaration that the error is referring to, and post it (or them if the function is indeed overloaded). The error says there are 5 overloads to that function, and we don't know what any of them are.
    for example if I replace all the code in the function with:

    Code:
       return command;
    When I call the obj from js I get the argument back with no trouble at all...
    C++ isn't a language to experiment with by throwing stuff on the wall and seeing what sticks. All you'll do is create buggy, faulty programs, if you can get the code to compile.

    Regards,

    Paul McKenzie

  8. #8
    Join Date
    Jan 2013
    Posts
    1

    Re: CreateProcess inside NPAPI plugin

    Hi
    I know this is old thread but i want take my chance.
    i try your method but everytime i test it i get "Could not create process" message even i try use cmd as hardcord like this:
    Code:
    BOOL result = ::CreateProcess(
              (LPCWSTR) "c:\\windows\\notepad.exe",
              NULL,
              NULL,
              NULL,
              FALSE,
              NORMAL_PRIORITY_CLASS,
              NULL,
              NULL,
              &startupInfo,
              &processInformation
            );
    but the result is always 0.
    May you help me?

  9. #9
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: CreateProcess inside NPAPI plugin

    Quote Originally Posted by arminIT View Post
    Hi
    I know this is old thread but i want take my chance.
    i try your method but everytime i test it i get "Could not create process" message even i try use cmd as hardcord like this:
    ...
    but the result is always 0.
    May you help me?
    MSDN may help you... but only if you will read it and read it very carefully.
    For example the CreateProcess article mentions:
    Return value
    If the function succeeds, the return value is nonzero.
    If the function fails, the return value is zero. To get extended error information, call GetLastError.
    Victor Nijegorodov

  10. #10
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: CreateProcess inside NPAPI plugin

    Quote Originally Posted by arminIT View Post
    i try your method but everytime i test it i get "Could not create process" message even i try use cmd as hardcord like this:
    Code:
    BOOL result = ::CreateProcess(
              (LPCWSTR) "c:\\windows\\notepad.exe",
              NULL,
              NULL,
              NULL,
              FALSE,
              NORMAL_PRIORITY_CLASS,
              NULL,
              NULL,
              &startupInfo,
              &processInformation
            );
    Do you have any idea what the highlighted line really does? Just try it put like this and see what it outputs:
    Code:
    #define UNICODE
    #include <windows.h>
    #include <stdio.h>
    
    int wmain ()
    {
        wprintf(L"%s", (LPCWSTR) "c:\\windows\\notepad.exe");
        return 0;
    }
    but the result is always 0.
    May you help me?
    Result 0 means CreateProcess returned FALSE. Doesn't it look normal when you provide a garbage data?
    Last edited by Igor Vartanov; January 26th, 2013 at 05:50 AM.
    Best regards,
    Igor

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured