-
February 1st, 2012, 03:02 PM
#1
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
-
February 1st, 2012, 03:18 PM
#2
Re: CreateProcess inside NPAPI plugin
Originally Posted by bula
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
-
February 1st, 2012, 03:32 PM
#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...
-
February 1st, 2012, 03:36 PM
#4
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
Originally Posted by bula
Code:
FB::variant HarrisonRunCmdPluginAPI::runCommand(...)
are?
Victor Nijegorodov
-
February 1st, 2012, 03:47 PM
#5
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:
When I call the obj from js I get the argument back with no trouble at all...
-
February 1st, 2012, 03:54 PM
#6
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:
Originally Posted by bula
Code:
FB::variant HarrisonRunCmdPluginAPI::runCommand(const char command)
{
...
LPCWSTR cmd = (LPCWSTR)command;
Victor Nijegorodov
-
February 1st, 2012, 04:52 PM
#7
Re: CreateProcess inside NPAPI plugin
Originally Posted by bula
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:
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
-
January 23rd, 2013, 05:01 AM
#8
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?
-
January 23rd, 2013, 05:19 AM
#9
Re: CreateProcess inside NPAPI plugin
Originally Posted by arminIT
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
-
January 26th, 2013, 05:46 AM
#10
Re: CreateProcess inside NPAPI plugin
Originally Posted by arminIT
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|