views:

263

answers:

4

Hi There, Does anyone know the code or have ideas on how to kick off an exe using visual c++ 2005.

The environment the dll is on if Windows Mobile. The c# to do this using P/Invoke is

[DllImport("coredll.Dll")] private static extern int CreateProcess(string strImageName, string strCmdLine, IntPtr pProcessAttributes, IntPtr pThreadAttributes , int bInheritsHandle, int dwCreationFlags, IntPtr pEnvironment, IntPtr pCurrentDir, Byte[] bArray, ProcessInfo oProc);

//c# Code to start .exe CreateProcess("\Program Files\myprogram\myprogram.exe.exe", "", IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, new Byte[128], pi);

The reason I need it in C++ is because I am forced to use a native dll to carry out pre and post intit checks etc when running a custom cab installer.

Your thoughts are much appreciated. Tony

+1  A: 
PROCESS_INFORMATION ProcessInfo = { 0 };

if (CreateProcess(ImagePath,
                  NULL,
                  NULL,
                  NULL,
                  FALSE,
                  0,
                  NULL,
                  NULL,
                  NULL,
                  &ProcessInfo))
{
    CloseHandle(ProcessInfo.hThread);
    CloseHandle(ProcessInfo.hProcess);
}
else
{
    return GetLastError();
}
jachymko
A: 

If you mean running an exe on the device, then no visual studio can't do it directly. You need to setup a custom build step or pre/post build steps to run a application that will do it for you. You can use the WM5 SDK code example prun (or create your own). PRun uses RAPI to run the application on the device, so the device needs to be connected through ActiveSync for this to work.

If you are trying to make stuff "automatically" happen on the device (e.g. unit tests), you may like to look into running the device emulator. This may get you more control than trying to use a physical device.

Shane Powell
A: 

Try this:

BOOL RunExe(CString strFile)
{
    WIN32_FIND_DATA fd;
    HANDLE   hFind;
    BOOL     bFind;

    hFind = FindFirstFile(strFile, &fd);
    bFind = (hFind != INVALID_HANDLE_VALUE);

    if(bFind)
    {
    if(!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
    {
     SHELLEXECUTEINFO info;
     ZeroMemory(&info, sizeof(info));
     info.cbSize = sizeof(info);
     info.fMask = SEE_MASK_NOCLOSEPROCESS;
     info.hwnd = 0;
     info.lpVerb = _T("open");
     info.lpFile = strFile;
     info.lpParameters = NULL;
     info.lpDirectory = NULL;
     info.nShow = SW_SHOW;
     info.hInstApp = NULL;
     ShellExecuteEx(&info); 
    }
    else
     bFind = FALSE;
    }

    FindClose(hFind);

    return bFind;    
}
JDM
Why would you use the weight of a CString for something like this?
ctacke