Skip to content

Commit

Permalink
1) Pink output for .DLL load error and getprocaddress failures.
Browse files Browse the repository at this point in the history
2) Loading .DLL failure will now raise an exception.
  • Loading branch information
JPeterMugaas committed May 21, 2024
1 parent cc94ea3 commit 684d2e9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 28 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

cmake_minimum_required (VERSION 3.21)

set(EFXC2_VERSION 0.0.10.233)
set(EFXC2_VERSION 0.0.10.234)
project (efxc2 VERSION ${EFXC2_VERSION}
DESCRIPTION "Enhanced fxc2"
HOMEPAGE_URL "https://github.com/JPeterMugaas/efxc2"
Expand Down Expand Up @@ -97,6 +97,7 @@ install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/README.md
${CMAKE_CURRENT_SOURCE_DIR}/license_MPL_2_0.txt
${CMAKE_CURRENT_SOURCE_DIR}/HISTORY.md
${CMAKE_CURRENT_SOURCE_DIR}/INSTALL.md
DESTINATION ${CMAKE_INSTALL_DOCDIR})

if(EFXC2_USE_PVS_STUDIO)
Expand Down
24 changes: 24 additions & 0 deletions efxc2CompilerAPIContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
#include "efxc2Console.h"

efxc2CompilerAPIContainer::CompilerAPIContainer::CompilerAPIContainer() {
efxc2Console::Console console = efxc2Console::console;
h = LoadLibraryEx(DLL_NAME, nullptr, 0);
if (h == nullptr) {
console.PinkOutput();
std::wcerr << std::format(L"{} failed to load ", DLL_NAME);
std::cerr << std::endl;
console.ResetOutput();
efxc2Utils::print_windows_error();
throw efxc2Exception::Win32APIFailure();
}
/* for some reason, when compiling for Clang 18.1.4, you get this warning V2005 saying you should do not
C-type casts. I suspect that this is how they implemented std::bit_cast. The V2005 also needs to
Expand All @@ -28,55 +34,73 @@ efxc2CompilerAPIContainer::CompilerAPIContainer::CompilerAPIContainer() {
#pragma warning( pop )
#endif
if (ptr_D3DCompile2 == nullptr) {
console.PinkOutput();
std::cerr << "Error: could not get the address of D3DCompile2.\n";
console.ResetOutput();
efxc2Utils::print_windows_error();
throw efxc2Exception::Win32APIFailure();
}
ptr_D3DStripShader = std::bit_cast<pD3DStripShaderg>(GetProcAddress(h, (const char*)"D3DStripShader")); //-V2005 //-V2533
if (ptr_D3DStripShader == nullptr) {
console.PinkOutput();
std::cerr << "Error: could not get the address of D3DStripShader.\n";
console.ResetOutput();
efxc2Utils::print_windows_error();
throw efxc2Exception::Win32APIFailure();
}
ptr_D3DGetBlobPart = std::bit_cast<pD3DGetBlobPartg>(GetProcAddress(h, (const char*)"D3DGetBlobPart")); //-V2005 //-V2533
if (ptr_D3DGetBlobPart == nullptr) {
console.PinkOutput();
std::cerr << "Error: could not get the address of D3DGetBlobPart.\n";
console.ResetOutput();
efxc2Utils::print_windows_error();
throw efxc2Exception::Win32APIFailure();
}
ptr_D3DSetBlobPart = std::bit_cast<pD3DSetBlobPartg>(GetProcAddress(h, (const char*)"D3DSetBlobPart")); //-V2005 //-V2533
if (ptr_D3DSetBlobPart == nullptr) {
console.PinkOutput();
std::cerr << "Error: could not get the address of D3DSetBlobPart.\n";
console.ResetOutput();
efxc2Utils::print_windows_error();
throw efxc2Exception::Win32APIFailure();
}
ptr_D3DDisassemble = std::bit_cast<pD3DDisassembleg>(GetProcAddress(h, (const char*)"D3DDisassemble")); //-V2005 //-V2533
if (ptr_D3DDisassemble == nullptr) {
console.PinkOutput();
std::cerr << "Error: could not get the address of D3DDisassemble.\n";
console.ResetOutput();
efxc2Utils::print_windows_error();
throw efxc2Exception::Win32APIFailure();
}
ptr_D3DLoadModule = std::bit_cast<gD3DLoadModulep>(GetProcAddress(h, (const char*)"D3DLoadModule")); //-V2005 //-V2533
if (ptr_D3DLoadModule == nullptr) {
console.PinkOutput();
std::cerr << "Error: could not get the address of D3DLoadModule.\n";
console.ResetOutput();
efxc2Utils::print_windows_error();
throw efxc2Exception::Win32APIFailure();
}
ptr_D3DCreateLinker = std::bit_cast<gD3DCreateLinkerp>(GetProcAddress(h, (const char*)"D3DCreateLinker")); //-V2005 //-V2533
if (ptr_D3DCreateLinker == nullptr) {
console.PinkOutput();
std::cerr << "Error: could not get the address of D3DCreateLinker.\n";
console.ResetOutput();
efxc2Utils::print_windows_error();
throw efxc2Exception::Win32APIFailure();
}
ptr_D3DCreateFunctionLinkingGraph = std::bit_cast<gD3DCreateFunctionLinkingGraphp>(GetProcAddress(h, (const char*)"D3DCreateFunctionLinkingGraph")); //-V2005 //-V2533
if (ptr_D3DCreateFunctionLinkingGraph == nullptr) {
console.PinkOutput();
std::cerr << "Error: could not get the address of D3DCreateFunctionLinkingGraph.\n";
console.ResetOutput();
efxc2Utils::print_windows_error();
throw efxc2Exception::Win32APIFailure();
}
ptr_D3DPreprocess = std::bit_cast<gD3DPreprocessp>(GetProcAddress(h, (const char*)"D3DPreprocess")); //-V2005 //-V2533
if (ptr_D3DPreprocess == nullptr) {
console.PinkOutput();
std::cerr << "Error: could not get the address of D3DPreprocess.\n";
console.ResetOutput();
efxc2Utils::print_windows_error();
throw efxc2Exception::Win32APIFailure();
}
Expand Down
54 changes: 27 additions & 27 deletions efxc2CompilerAPIContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,33 @@
#include "efxc2.h"

namespace efxc2CompilerAPIContainer {
constexpr auto DLL_NAME = L"d3dcompiler_47.dll";
class CompilerAPIContainer {
public:
explicit CompilerAPIContainer();
pD3DCompile2g get_ptr_D3DCompile2() const { return ptr_D3DCompile2; }
pD3DStripShaderg get_ptr_D3DStripShader() const { return ptr_D3DStripShader; }
pD3DGetBlobPartg get_ptr_D3DGetBlobPart() const { return ptr_D3DGetBlobPart; }
pD3DSetBlobPartg get_ptr_D3DSetBlobPart() const { return ptr_D3DSetBlobPart; }
pD3DDisassembleg get_ptr_D3DDisassemble() const { return ptr_D3DDisassemble; }
gD3DLoadModulep get_ptr_D3DLoadModule() const { return ptr_D3DLoadModule; }
gD3DCreateLinkerp get_ptr_D3DCreateLinker() const { return ptr_D3DCreateLinker; }
gD3DPreprocessp get_ptr_D3DPreprocess() const { return ptr_D3DPreprocess; }
gD3DCreateFunctionLinkingGraphp get_ptr_D3DCreateFunctionLinkingGraph() const { return ptr_D3DCreateFunctionLinkingGraph; }
private:
HMODULE get_h() const { return h; }
/*these need to be marked as will not serialize. */
HMODULE h; //-V122_NOPTR
pD3DCompile2g ptr_D3DCompile2; //-V122_NOPTR
pD3DStripShaderg ptr_D3DStripShader; //-V122_NOPTR
pD3DGetBlobPartg ptr_D3DGetBlobPart; //-V122_NOPTR
pD3DSetBlobPartg ptr_D3DSetBlobPart; //-V122_NOPTR
pD3DDisassembleg ptr_D3DDisassemble; //-V122_NOPTR
gD3DLoadModulep ptr_D3DLoadModule; //-V122_NOPTR
gD3DCreateLinkerp ptr_D3DCreateLinker; //-V122_NOPTR
gD3DCreateFunctionLinkingGraphp ptr_D3DCreateFunctionLinkingGraph; //-V122_NOPTR
gD3DPreprocessp ptr_D3DPreprocess; //-V122_NOPTR
};
constexpr auto DLL_NAME = L"d3dcompiler_47.dll";
class CompilerAPIContainer {
public:
explicit CompilerAPIContainer();
pD3DCompile2g get_ptr_D3DCompile2() const { return ptr_D3DCompile2; }
pD3DStripShaderg get_ptr_D3DStripShader() const { return ptr_D3DStripShader; }
pD3DGetBlobPartg get_ptr_D3DGetBlobPart() const { return ptr_D3DGetBlobPart; }
pD3DSetBlobPartg get_ptr_D3DSetBlobPart() const { return ptr_D3DSetBlobPart; }
pD3DDisassembleg get_ptr_D3DDisassemble() const { return ptr_D3DDisassemble; }
gD3DLoadModulep get_ptr_D3DLoadModule() const { return ptr_D3DLoadModule; }
gD3DCreateLinkerp get_ptr_D3DCreateLinker() const { return ptr_D3DCreateLinker; }
gD3DPreprocessp get_ptr_D3DPreprocess() const { return ptr_D3DPreprocess; }
gD3DCreateFunctionLinkingGraphp get_ptr_D3DCreateFunctionLinkingGraph() const { return ptr_D3DCreateFunctionLinkingGraph; }
private:
HMODULE get_h() const { return h; }
/*these need to be marked as will not serialize. */
HMODULE h; //-V122_NOPTR
pD3DCompile2g ptr_D3DCompile2; //-V122_NOPTR
pD3DStripShaderg ptr_D3DStripShader; //-V122_NOPTR
pD3DGetBlobPartg ptr_D3DGetBlobPart; //-V122_NOPTR
pD3DSetBlobPartg ptr_D3DSetBlobPart; //-V122_NOPTR
pD3DDisassembleg ptr_D3DDisassemble; //-V122_NOPTR
gD3DLoadModulep ptr_D3DLoadModule; //-V122_NOPTR
gD3DCreateLinkerp ptr_D3DCreateLinker; //-V122_NOPTR
gD3DCreateFunctionLinkingGraphp ptr_D3DCreateFunctionLinkingGraph; //-V122_NOPTR
gD3DPreprocessp ptr_D3DPreprocess; //-V122_NOPTR
};
}

#endif /*EFXC2COMPILERAPICONTAINER_H_INCLUDED*/

0 comments on commit 684d2e9

Please sign in to comment.