Depending on the operating system (64/32), the settings file runs at 64 bits. also resolves the issue: "Trying to load an incorrect program."

Source: Internet
Author: User

Button Event

void Csqlcontestdlg::onok ()

{

CString strpath = "cmd.exe";

if (IsWow64 ())

{

Wow64disablewow64fsredirection (NULL);

}

Startupinfo si = {sizeof (startupinfo)};

ZeroMemory (&si,sizeof (startupinfo));

SI.CB = sizeof (STARTUPINFO);

Si.wshowwindow = Sw_show;

Si.dwflags = Startf_useshowwindow;

Process_information Pi;

memset (&pi,0,sizeof (pi));

if (CreateProcess (NULL, (char*) (LPCSTR) strpath,null,null,false,0,null,null,&si,&pi))

{  

}

Block the previous process

while (WaitForSingleObject (pi.hprocess,20))

{

;

}

Wow64revertwow64fsredirection (NULL);

}

/****************************************************/

/* Determine if it is a 64-bit system */

/****************************************************/

typedef BOOL (WINAPI *lpen_iswow64process) (Handle,pbool);

BOOL Csqlcontestdlg::iswow64 ()

{

BOOL bIsWow64 = false;

Lpen_iswow64process fniswow64process;

Fniswow64process = (lpen_iswow64process) GetProcAddress (GetModuleHandle (TEXT ("kernel32")), "iswow64process");

if (NULL! = fniswow64process)

{

if (!fniswow64process (GetCurrentProcess (), &biswow64)) {};

}

return bIsWow64;

}

/****************************************************/

/* If the system is 64-bit, cancel the key position of the file */

/****************************************************/

typedef BOOL (WINAPI *lpen_wow64disablewow64fsredirection) (pvoid* OldValue);

BOOL csqlcontestdlg::wow64disablewow64fsredirection (pvoid* OldValue)

{

BOOL BRet = false;

Lpen_wow64disablewow64fsredirection fnwow64disablewow64fsredirection;

Fnwow64disablewow64fsredirection = (lpen_wow64disablewow64fsredirection)

GetProcAddress (GetModuleHandle (TEXT ("kernel32")), "wow64disablewow64fsredirection");

if (NULL! = fnwow64disablewow64fsredirection)

{

if (Fnwow64disablewow64fsredirection (OldValue))

{

BRet = true;

}

}

return bRet;

}

/****************************************************/

/* If the system is 64-bit, restore the key position of the file */

/****************************************************/

typedef BOOL (WINAPI *lpen_wow64revertwow64fsredirection) (PVOID OldValue);

BOOL csqlcontestdlg::wow64revertwow64fsredirection (PVOID OldValue)

{

BOOL BRet = false;

Lpen_wow64revertwow64fsredirection fnwow64revertwow64fsredirection;

Fnwow64revertwow64fsredirection = (lpen_wow64revertwow64fsredirection) GetProcAddress (GetModuleHandle (TEXT (" Kernel32 "))," wow64revertwow64fsredirection ");

if (NULL! = fnwow64revertwow64fsredirection)

{

if (Fnwow64revertwow64fsredirection (OldValue))

{

BRet = true;

}

}

return bRet;

}

Depending on the operating system (64/32), the settings file runs at 64 bits. also resolves the issue: "Trying to load an incorrect program."

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.