0cx00007b or installing drivers from the program

 
3r3-31.

Entry


 
Good day. Do you know the exception 0cx00007b ? Since the transfer of the engine X-ray under x64 There were a lot of reports about the problem 0cx00007b. In 90% of cases, it was a problem with the lack of a 64 bit OpenAL driver.
Pragma comment ), But in our case, you can't do that.
 
So step 1: [b] explicit linking 3r3338. or hi extern "C" .
 
What we need: untie exe from engine libraries. This is done in the following way:
 
1) Move the engine launch function to the dynamic library:
 
3r3171. 3r3172. extern "C" - //LoadLibrary, if memory serves me, Sishne API
{
void ENGINE_API RunApplication (LPCSTR commandLine)
{
//Your code
}
}
 

2) Call the function from our exe:


 
3r3171. 3r3172. using RunFunc = void (__ cdecl *) (const char *); //Declare a convenient type of function
bool OpenALFound = false; //It will come in handy for us later
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
if (OpenALFound)
{
HMODULE hLib = LoadLibrary ("xrEngine.dll"); //Get the module with our
function. IsRunFunc RunFunc = (IsRunFunc) GetProcAddress (hLib, "RunApplication"); //Get the function from the
module. RunFunc (params); //Run the
engine.}
return 0;
}
 

Step 2: Check the driver


 

Well, everything is simple, we get the system one (maybe someone will be surprised, but the OS is not always on the C :) partition and check the dll in the drivers folder:


 
3r3171. 3r3172. ///R_ASSERT is an internal macro that checks the value of the first argument for true, if false, the program will display an error message 3r33332. //WinMain code
TCHAR szOpenALDir[MAX_PATH]= {0}; //Get the system patch
R_ASSERT (GetSystemDirectory (szOpenALDir, MAX_PATH * sizeof (TCHAR)));
#ifndef UNICODE
_snprintf_s (szOpenALDir, MAX_PATH * sizeof (CHAR), "% s% s", szOpenALDir, " OpenAL32.dll");
#else
_snwprintf_s (szOpenALDir, MAX_PATH * sizeof (WCHAR), L "% s% s", szOpenALDir, L " OpenAL32.dll");
#endif
DWORD dwOpenALInstalled = GetFileAttributes (szOpenALDir);
//Attributes are valid, so the driver is in place. All right, run.
if (dwOpenALInstalled! = INVALID_FILE_ATTRIBUTES)
{
OpenALFound = true;
}
 
3r3113. Step 3: File not found
 

First of all, we need to ask the administrator for user rights, since Will have to work with the system directory:


 
3r3171. 3r3172. //Check if we are running from admin
bool IsProcessWithAdminPrivilege ()
{
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
LPVOID pAdministratorsGroup = nullptr;
BOOL bRet = FALSE;
//init SID to control privileges
AllocateAndInitializeSid (& NtAuthority, ? SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, ? ? ? ? ? ? & pAdministratorsGroup);
//ckeck membership
CheckTokenMembership (nullptr, pAdministratorsGroup, & bRet);
//clean pointer
if (pAdministratorsGroup)
{
FreeSid (pAdministratorsGroup);
pAdministratorsGroup = nullptr;
}
return !! bRet;
}
{
//WinMain code
//If you do not have administrator rights, ask for them and restart
if (! IsProcessWithAdminPrivilege ())
{
TCHAR szPathToLib[MAX_PATH]= {0};
GetModuleFileName (nullptr, szPathToLib, ARRAYSIZE (szPathToLib));
SHELLEXECUTEINFO shellInfo = {sizeof (SHELLEXECUTEINFO)};
shellInfo.lpVerb = TEXT ("runas");
shellInfo.lpFile = szPathToLib;
shellInfo.hwnd = nullptr;
shellInfo.nShow = SW_NORMAL;
if (ShellExecuteEx (& shellInfo))
ExitProcess (GetCurrentProcessId ());
}
}
 

Step two: copy the library to the system 3r3221.
 
3r3171. 3r3172. {
//WinMain code
TCHAR szPath[MAX_PATH]= {0};
//For example, take the path from the executable file 3r33333. GetModuleFileName (GetModuleHandle (nullptr), szPath, MAX_PATH);
PathRemoveFileSpec (szPath);
#ifndef UNICODE
_snprintf_s (szPath, MAX_PATH * sizeof (CHAR), "% s% s", szPath, " OpenAL32.dll");
#else
_snwprintf_s (szPath, MAX_PATH * sizeof (WCHAR), L "% s% s", szPath, L " OpenAL32.dll");
#endif
dwOpenALInstalled = GetFileAttributes (szPath);
if (dwOpenALInstalled! = INVALID_FILE_ATTRIBUTES) //File finds, move on
{
DWORD LibrarySize = 0;
HANDLE hFile = CreateFile (szPath, GENERIC_READ, NULL, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
R_ASSERT (hFile! = INVALID_HANDLE_VALUE);
FILE_STANDARD_INFO fileInfo = {0};
GetFileInformationByHandleEx (hFile, FileStandardInfo, & fileInfo, sizeof (fileInfo));
LPVOID pImage = HeapAlloc (GetProcessHeap (), ? fileInfo.EndOfFile.QuadPart);
ReadFile (hFile, pImage, fileInfo.EndOfFile. QuadPart, & LibrarySize, nullptr);
CloseHandle (hFile);
hFile = CreateFile (szOpenALDir, GENERIC_WRITE, NULL, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
R_ASSERT (hFile! = INVALID_HANDLE_VALUE);
WriteFile (hFile, pImage, fileInfo.EndOfFile. QuadPart, & LibrarySize, nullptr);
HeapFree (GetProcessHeap (), ? pImage);
CloseHandle (hFile);
OpenALFound = true; //We say that everything is in order; you can run the
engine.}
}
 
Conclusion
 
Of course, the method is quite funny, but it is suitable for such projects. Good luck to all!

+ 0 -

Add comment