Use of CreateProcess on WinCE6 - windows-ce

I'm trying to launch a process from my program, namely cmd.exe.
Doc says I have to use CreateProcess, and below is how I use it :
CreateProcess((LPCWSTR) "\Windows\cmd.exe", (LPCWSTR) "", 0,0,0,0,0,0,0,0);
dw = GetLastError();
printf("%u \n", dw);
The path is the one displayed by the target (on the target, I found a shortcut to cmd.exe which states it resides in \windows.
The error is always the same (2), regardless of how I write the path. Apparently, the error code for (2) is Invalid_Path.
Thanks for having read,
GQ

You are passing an incorrect string to create process. Just casting a byte-oriented string to LPCWSTR doesn't fix the problem that it is incorrect data - you really have to use a Unicode string, which you can spell as
CreateProcess(L"\\Windows\\cmd.exe", NULL, 0,0,0,0,0,0,0,0);
Alternatively, you can use the TEXT() macro.

The path is incorrect. Use double backslash.
CreateProcess(TEXT("\\Windows\\cmd.exe"), TEXT(""), 0,0,0,0,0,0,0,0);

Additionally, the last parameter cannot be NULL. It must be a pointer to PROCESS_INFORMATION structure. For details, see the following link
MSDN link for Creating Process in Windows CE 6.0

Related

registering for device notifications

so iv'e been searching for a way to get notifications when a USB device is connected to the pc. i found this code here: https://learn.microsoft.com/en-us/windows/desktop/devio/registering-for-device-notification
now i have a few problems with this code(visual c++).
I tried putting it in my visual c++ 2017 but it won't compile. there are 6 errors in 2 types:
lines 330, 344, 495: error E0167.
'argument of type "PTSTR" is incompatible with parameter of type "LPCWSTR" '
https://www.bing.com/search?q=C%2B%2B%20argument+of+type+%22PTSTR%22+is+incompatible+with+parameter+of+type+%22LPCWSTR%22
lines 330, 350, 495: error C2664.
"'LPWSTR *CommandLineToArgvW(LPCWSTR,int *)': cannot convert argument 1/3 from 'PTSTR' to 'LPCWSTR'"
https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c2664?f1url=https%3A%2F%2Fmsdn.microsoft.com%2Fquery%2Fdev15.query%3FappId%3DDev15IDEF1%26l%3DEN-US%26k%3Dk(C2664)%26rd%3Dtrue&view=vs-2017
before line 330 there is a comment that says to add Windows to the project. i did that but I'm still getting these errors, and searching them in the web didn't help since i do understand the error but have no idea how to fix it. I would highly appreciate it if you could help me compile this code. thanks in advance!
Well, first of all, that example code is poorly written. It is mixing things like PWSTR with LPTSTR. PWSTR is a pointer to a wide-character string whereas LPTSTR is a pointer to either a character string or a wide-character string depending on the project settings.
Since the code is using wide-character strings in some places and calling functions that end with W, you need to configure the project to use wide-character strings for everything. I don't have VS 2017, but in VS 2015 you configure your project to use wide-character strings by setting Project->Properties->General->Character Set to Use Unicode Character Set.
EDIT: To answer your comment.
The problem you are having is primarily due to line 13:
PWSTR g_pszAppName;
This is one of two variables declared explicitly as a wide-character string pointer. You can try to modify the code not to use any wide character strings as follows:
Change line 13 to:
PTSTR g_pszAppName = _T("MyApp"); // Put your app name here
Remove these 2 lines (330 and 331):
PWSTR* ppArgV = CommandLineToArgvW(lpstrCmdLine, &nArgC);
g_pszAppName = ppArgV[0];
You may also want to change Project->Properties->General->Character Set back to what it was originally.

Invalid parameter information was passed to method 'differential.parsecommitmessage'

It show me an error:
ERR-CONDUIT-CORE: Invalid parameter information was passed to method `differential.parsecommitmessage`.
(Run with `--trace` for a full exception trace.)
When I type arc diff in CMD. I use arcanist and php to review my code, and the tools required on my computer is the lasted. Someone can help me?
make sure your commit file is UTF-8.
check your input words,do not contains special character.
make your filepath in english, I fixed it by remove my chinese word

Excel automation isn't working in C++Builder XE7

I am trying to use the code below to open an .xlsx file from C++Builder in RAD Studio XE7:
#include "ComObj.hpp"
Variant Excel = CreateOleObject("Excel.Application");
Variant Books = Excel.OlePropertyGet("Workbooks");
Excel.OlePropertySet("Visible", true);
// An escape character is missing but the problem remains
Books.OleProcedure("Open", L"D:\1.xlsx"); // exception here
But the last line causes exception with message:
Project2.exe raised exception class EOleException with message 'Unfortunately, we were unable to find the file TRUE.xlsx. It may have been moved, renamed or deleted?'.
Screen with place where the source breaks
The code in Delphi seems to work fine:
uses ComObj;
var
Excel, Books: Variant;
begin
Excel := CreateOleObject('Excel.Application');
Books := Excel.Workbooks;
Excel.Visible := True;
Books.Open('D:\1.xlsx'); // code passes
end;
Does anyone know the solution?
Update1:
The following code in VB also works fine:
Sub Button1_Click()
Dim xlApp As Excel.Application
Dim xlBooks As Excel.Workbooks
Set xlApp = CreateObject("Excel.Application")
Set xlBooks = xlApp.Workbooks
xlApp.Visible = True
xlBooks.Open ("D:\1.xlsx")
End Sub
Update2:
Sending a raw string literal causes the same exception.
Books.OleProcedure("Open", uR"(D:\1.xlsx)");
It also doesn't seem to be an environment problem. I tested the example at several computers with no effect.
In C++ the backslash character is the escape character in string literals and so needs itself to be escaped. Instead of
L"D:\1.xlsx"
you need to write
L"D:\\1.xlsx"
The error message is strange though. It is almost as though some conversion in the COM dispatch code interprets the 1 as a truth value and converts it to text. You could try passing the filename as a System::WideString which might side-step the issue.
System::WideString filename = L"D:\\1.xlsx";
Books.OleProcedure("Open", filename);
What you are reporting seems almost too weird to be true though! I have to confess I'm having some trouble believing it because it is so outlandish.
Just faced a similar problem with C++ Builder XE7 and thought I would share what I found. Any attempt to set or send a string literal of any type caused either a Bad Variable Type error, was set as TRUE in Excel like Dmitrii or caused a memory error.
What I eventually found was that there is an OLEVariant type in C++ Builder that contains data types compatible with OLE automation and at runtime can convert as required.
I first tried changing all my Variant variables to OLEVariant without success but then was able to use a cast on any string I sent to make it work, even older char strings. So you might try
Books.OleProcedure("Open", (OleVariant)L"D:\1.xlsx");
even without the WideString formatting it worked for what I was doing so this might work as well
Books.OleProcedure("Open", (OleVariant)"D:\1.xlsx");
As for escaping I'm not sure if you need to escape the backslash in the second case with a simple string or not.
The problem seems very specifically related to the use of C++ and thus the way that C++ compilers deal with literal strings (or at least this particular C++ compiler). Quite what the problem is in this case I cannot say - it could even be a bug in the compiler since (seemingly) correct escaping doesn't address the problem.
You could employ various strategies to eliminate the possibility that it is handling of the literal string in this case. But since this does involve a literal string and since you are using XE7 I believe you should be able to bypass this more explicitly by expressing the literal as a raw string (as per C++11, which is/should be supported by C++ Builder XE7):
Books.OleProcedure("Open", uR"(D:\1.xlsx)"); // uR indicates UTF-16 Raw string
Note that with raw string literals you specifically do not escape \ chars.

How to use strstrip for parsing a string in two parts

I would like to know hot to parse a string like this "hello world" into "helloworld" using the strstrip kernel function. I am developing a Linux Kernel char device and this functions causes me a Kernel Panic (or Kernel Opss).
The way I'm using this function is the following:
char result[100];
strcpy(result, "hello world");
strstrip(result);
strstrip(&result); //Also tried this
strstrip("100+200"); //Also tried this
The Kernel error is caused as soon as the strstrip line gets executed. What is the proper way to call this function?
Actually strstrip helps to remove the white spaces at the front. It does not remove all the white spaces with in the string.
Please look at the below example.
char result[100];
strcpy(result, " hello world from stack exchange");
printk("\n before: %s",result);
strcpy(result, strstrip((char*)result));
printk("\n after: %s",result);
Hope it helps.
srtstrip() is a wrapper function for strim() (http://lxr.linux.no/linux+v3.11.2/lib/string.c#L361) in modern kernels. As it will attempt to modify the string itself, you cannot call it with a static string as you have in the third attempt.
The second attempt you have is passing a pointer to an array variable which is also a pointer. So you are passing a char** which if you look at the link above you can see is not correct.
The first attempt should not cause a kernel error, but you do not appear to be receiving the return value in a a local variable. What kind of error are you receiving? I will update this answer if you can provide that information.
In the end though as Balamurugan A points out, this function does not do what you seem to think it does. strsep() (http://lxr.linux.no/linux+v3.11.2/lib/string.c#L485) may help you out here but it will only be a stepping stone to removing all spaces. You will actually have to copy the string into a new buffer word by word as there is not way to simply "shift memory contents", as it were.

C++/CLI Converting System::String to const char*

I'm using Microsoft Visual C++ 2008
I want to join some strings, and then use it with "system" command.
I tried to do it like this:
System::String^ link;
link = "wget.exe --output-document=log http://ADDRESS";
link = link + System::String::Copy(textBox_login->Text);
link = link + "&passwd=";
link = link + System::String::Copy(textBox_passwd->Text);
system(link); //LINE WITH ERROR
But i get error C2664: 'system' : cannot convert parameter 1 from 'System::String ^' to 'const char *'
I appreciate any help ;)
Take a look at this question and this question.
In essence, the problem is that the system function expects a variable of the type const char* rather than System::String.
So you need to convert the string to a const char* (Using code from this answer) and use that as an argument for the system function.
IntPtr p = Marshal::StringToHGlobalAnsi(clistr);
const char* linkStr = static_cast<char*>(p.ToPointer());
system(linkStr);
Marshal::FreeHGlobal(p);
To use system as you do, you will need Marshalling. This requires extra precautions which can lead to unforeseen pain.
I recommend that you call wget via the System::Process class
It integrates with .NET much better and you can use System::String^ directly
after doing as Yacoby said, almost everything works fine, but when it gets to
link = link + "&passwd=";
it cuts everything what is afterwords in string.
when i remove '&' it works just fine... i need the '&' sign
You got the technical solution to your problem but here are a couple other things you might want to consider:
Instead of opening a process to do the HTTP request for you, use an API (.NET or C++, in .NET it's much easier than standard C++, look at WebRequest) to do this. Especially if you plan to do something with the response.
In general if you're appending to a String multiple times, prefer a StringBuilder. Since String is immutable in .NET, every append requires a new String to be constructed.
In this case, don't use a String to build the URL in the first place. Use System::Uri instead.

Resources