Okay, i've ALMOST got it working. I've gotten both ShellExecute() and ShellExecuteEx() working. Instead of launching vlc and the the file with a command parameter, I just opened the file
, but I seem to have a little problem.
First, when I typed you're code for ShellExecute, I had gotten an LPCWSTR error, but luckily I found a function online to fix that
. With the ShellExecuteEx() function, it will run the file, but when it finishes and VLC closes, the program freezes for anywhere between 5 and 20 seconds (freeze as in I can't even close it, I have to click the stop debug button) before continuing. Plus, it won't run another file when the loop comes back around to the function. Like before, it completely skips that part of the code and prints "SHELLEXECUTE". It'll do this for both ShellExecute and ShellExecuteEX. Although, if I change the video string to directly point to a video file instead of letting it choose a random file, it will load just fine each time.
#include "DarkGDK.h"
using namespace std;
//convert a string to LPCWSTR
std::wstring s2ws(const std::string& s)
{
int len;
int slength = (int)s.length() + 1;
len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
wchar_t* buf = new wchar_t[len];
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
std::wstring r(buf);
delete[] buf;
return r;
}
void DarkGDK ( void )
{
string sopen = "open";
std::wstring wopen = s2ws(sopen);
LPCWSTR lopen = wopen.c_str();
dbSetDir( "C:/Users/Dolan/Videos/" );
string MainDirectory = dbGetDir();
dbPerformCheckListForFiles();
int t;
for ( t = 1; t <= dbChecklistQuantity(); t++ )
{
dbPrintC ( "Files= " );
dbPrintC ( dbChecklistString ( t ) );
dbPrint ( " " );
}
dbSync();
dbSyncRate( 60 );
while ( LoopGDK() )
{
dbPerformCheckListForFiles();
int FileCount = 3 + dbRND( dbChecklistQuantity()-3 );
dbFindFirst();
//Choose a random file
int i;
for ( i = 0; i < FileCount -1; i++ )
{
dbFindNext();
}
string slash = "/";
string video = MainDirectory += slash += dbGetFileName();
//string video = "C:/Users/Dolan/Videos/My Video.MP4";
std::wstring svideo = s2ws(video);
LPCWSTR lvideo = svideo.c_str();
dbPrintC ( double ( i ) );
dbPrintC ( ": " );
dbPrintC ( dbGetFileName() );
dbPrint ( " " );
dbPrint("VLC PLAYER");
SHELLEXECUTEINFO SHInfo = {0};
SHInfo.cbSize = sizeof (SHELLEXECUTEINFO);
SHInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
SHInfo.lpVerb = lopen;
SHInfo.lpFile = lvideo;
SHInfo.lpParameters = NULL;
SHInfo.nShow = SW_SHOW;
ShellExecuteEx (&SHInfo);
WaitForSingleObject(SHInfo.hProcess,INFINITE);
//ShellExecute(GetDesktopWindow(), lopen, lvideo,NULL,NULL,SW_SHOW );
dbPrint("SHELLEXECUTE");
dbWait(5000);
dbSync();
}
return;
}
Here's my current code. The video string that points to a file and ShellExecute are commented out.