0

I have a small activex control that is running on Windows mobile 6. I able to use the api CreateProcessW when I hard code the Application name L"\blah\blah.exe".

When I call another API that returns a BSTR which contains the application that I want to pass to the CreateProcessW it doens't work. I have checked and the application string is populated but I am guesing I am having a conversion problem between BSTR and LPCWSTR (Wide cha error?) . I have tried converting it with OLE2CW and OLE2W.

I am not a VC expert and I only need to get this working so my question is.

  1. When I receive a BSTR via a API how would I convert it to be able to pass it to the Application parameter in CreateProcessW? This is windows mobile 6 (Wince 5.2). A Code snippet would be great.

Code Example without any conversion:

 BSTR app = NULL;

_host->GetAppString(_T("app"),&app);

     CreateProcessW(app,L"22222",0,0,0,0,0,0,0,&processInformation);

The character set is Unicode.

Thanks

Rikardt
  • 11
  • There's no need to convert a BSTR, it is compatible with a LPCWSTR. This won't get better until you add proper error handling so you *know* why it fails. – Hans Passant Jul 29 '13 at 09:40
  • Hi Hans, I did add Error handeling but didn;t add it at the top. The only error I get is that the system cannot find the file specified. I believe a BSTR string is not completely compatible with a LPCWSTR on a windows CE system which is not 32bit. – Rikardt Jul 29 '13 at 10:50
  • "File not found" is a *very* common error, pretty unlikely we can help you find the file. Make sure it the full path, like c:\foo\bar\baz.exe. You should of course have documented this in your question. And no, CE is 32-bit. – Hans Passant Jul 29 '13 at 10:53
  • You are correct about CE. there is no file path C:\. CE file paths are \\. I know the path is correct. I specified that hard coding it works. Please ignore my question if it irritates you and if I haven't given you enough information. I apologize. – Rikardt Jul 29 '13 at 11:06

1 Answers1

0

According to this MSDN article (also this SO article), you can extract a wchar_t pointer by using the _bstr_t class, like

_bstr_t bsApp(app, true);
wchar_t *pApp = (wchar_t *)bsApp;
CreateProcessW(pApp, L"22222", 0, 0, 0, 0, 0, 0, 0, &processInformation);

EDIT: using CString

CStringW ss = app:
CreateProcessW(ss, L"22222", 0, 0, 0, 0, 0, 0, 0, &processInformation);
Community
  • 1
  • 1
Edward Clements
  • 5,040
  • 2
  • 21
  • 27
  • Hi Edward , It look like the BSTR returned from the API is encoded as a ANSI. When I write it to the file it contains the path correctly but is missing the second character example "\\dummy\dummy.exe" but when I write a BSTR that I created with L" I get the extra spaces exampleo \ d d \ d d \ d d \ d . I did some research and it seems it can be encoded to a ANSI as well. Not sure How I would convert it back to WIDE though. – Rikardt Jul 29 '13 at 13:27
  • I hadn't realised that MFC for Windows CE contains `CString` -- edited answer above to use `CStringW` – Edward Clements Jul 29 '13 at 13:52