Click here to Skip to main content
15,917,702 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralHTMLEncode in Visual C++ 6.0 Pin
BadJerry4-Nov-03 0:26
BadJerry4-Nov-03 0:26 
GeneralRe: HTMLEncode in Visual C++ 6.0 Pin
murali_utr4-Nov-03 1:04
murali_utr4-Nov-03 1:04 
GeneralRe: HTMLEncode in Visual C++ 6.0 Pin
BadJerry4-Nov-03 1:50
BadJerry4-Nov-03 1:50 
QuestionPlease help me,what operation will cause buffer overrun? Pin
520013144-Nov-03 0:18
520013144-Nov-03 0:18 
AnswerRe: Please help me,what operation will cause buffer overrun? Pin
Steve S4-Nov-03 0:51
Steve S4-Nov-03 0:51 
AnswerRe: Please help me,what operation will cause buffer overrun? Pin
David Crow4-Nov-03 3:46
David Crow4-Nov-03 3:46 
AnswerRe: Please help me,what operation will cause buffer overrun? Pin
Michael Dunn4-Nov-03 4:48
sitebuilderMichael Dunn4-Nov-03 4:48 
GeneralProblems launching a program with CreateProcess Pin
Xzaran4-Nov-03 0:17
Xzaran4-Nov-03 0:17 
Hello everybody out there,

I have a dialog window application which sets current user environment variables with RegSetValueEx. The values are parsed when the user pressed the OK Button.

After the parsing a new program is launched with CreateProcess.

Everything works fine as the variables are set and the new launched program starts, but as soon as I want to check if it can read the env variables by clicking a funktion of the program, which would mainly read out the variables and create a path out of them, I have an critical error message from windows.

I guess that I have a pointer or process still adressing something that new program needs, but as I am new to this I don't have clue where to look.


Here is more or less the code I am using:

void CSetEnvDialogDlg::OnOK()
{

CString evJOBValue, evSHOTValue;// contain the values from the dialog the user has set
int index;
DWORD res;
DWORD dwRet;



// Open registry key where current user environmental variables are stored!

if (res ==
SetVariable("JOB",
(char*) evJOBValue.GetBuffer(3),
strlen(evJOBValue),
REG_EXPAND_SZ))

evJOBValue.ReleaseBuffer(-1);

if (res ==
SetVariable("SHOT",
(char*) evSHOTValue.GetBuffer(3),
strlen(evSHOTValue),
REG_EXPAND_SZ))

evSHOTValue.ReleaseBuffer(-1);

// propagate changes so that environment variables takes immediate effect!

if( SendMessageTimeout(HWND_BROADCAST,
WM_SETTINGCHANGE,
0,
(LPARAM) "Environment",
SMTO_ABORTIFHUNG,
10000,
&dwRet) ){
AfxMessageBox("Registry has been updated sucessfully!", MB_OK);}
else AfxMessageBox("Registry didn't update sucessfully!", MB_OK);

PROCESS_INFORMATION ProcessInfo;
STARTUPINFO StartupInfo;
ZeroMemory(&StartupInfo, sizeof(StartupInfo));
StartupInfo.cb = sizeof StartupInfo;

if(CreateProcess("Path to the exe file",
NULL,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&StartupInfo,
&ProcessInfo))
{
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
}
else
{
AfxMessageBox("The process could not be started...", MB_OK);
}


CDialog::OnOK();

}



DWORD CSetEnvDialogDlg::SetVariable(char *name, char *value, DWORD valuelen, DWORD type)
{
HKEY h;
DWORD rc;

rc = RegOpenKeyEx(HKEY_CURRENT_USER, "Environment", 0, KEY_WRITE, &h);

if (rc == ERROR_SUCCESS)
rc = RegSetValueEx(h, name, 0, type, (unsigned char*) value, valuelen);

RegCloseKey(HKEY_CURRENT_USER);

return rc;
}



XzaranConfused | :confused:
GeneralRe: Problems launching a program with CreateProcess Pin
David Crow4-Nov-03 4:07
David Crow4-Nov-03 4:07 
GeneralRe: Problems launching a program with CreateProcess Pin
Xzaran4-Nov-03 4:25
Xzaran4-Nov-03 4:25 
GeneralRe: Problems launching a program with CreateProcess Pin
David Crow4-Nov-03 4:32
David Crow4-Nov-03 4:32 
GeneralRe: Problems launching a program with CreateProcess Pin
Xzaran4-Nov-03 4:49
Xzaran4-Nov-03 4:49 
GeneralRe: Problems launching a program with CreateProcess Pin
David Crow4-Nov-03 5:02
David Crow4-Nov-03 5:02 
GeneralRe: Problems launching a program with CreateProcess Pin
Xzaran4-Nov-03 5:46
Xzaran4-Nov-03 5:46 
GeneralCFileDialog Pin
KKR3-Nov-03 23:30
KKR3-Nov-03 23:30 
GeneralRe: CFileDialog Pin
BadJerry3-Nov-03 23:46
BadJerry3-Nov-03 23:46 
GeneralRe: CFileDialog Pin
KKR4-Nov-03 0:03
KKR4-Nov-03 0:03 
GeneralRe: CFileDialog Pin
BadJerry4-Nov-03 0:09
BadJerry4-Nov-03 0:09 
GeneralRe: CFileDialog Pin
KKR4-Nov-03 0:38
KKR4-Nov-03 0:38 
GeneralRe: CFileDialog Pin
BadJerry4-Nov-03 0:47
BadJerry4-Nov-03 0:47 
GeneralRe: CFileDialog Pin
FearlessBurner4-Nov-03 1:57
FearlessBurner4-Nov-03 1:57 
GeneralRe: CFileDialog Pin
Bo Hunter4-Nov-03 12:48
Bo Hunter4-Nov-03 12:48 
GeneralReading a jpeg file Pin
BlackRider3-Nov-03 23:28
BlackRider3-Nov-03 23:28 
GeneralRe: Reading a jpeg file Pin
BadJerry3-Nov-03 23:39
BadJerry3-Nov-03 23:39 
GeneralRe: Reading a jpeg file Pin
BlackRider4-Nov-03 0:43
BlackRider4-Nov-03 0:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.