Jump to content

Help needed - compile a .cpp file into a .dll


Recommended Posts

Upload all the files you changed (everything in project's folder + GameReferences.h file) somewhere and give me the link, so I can compare them with mine.

Also try with the Debug version. The original author released the Debug version, so is possible that he/she never tested the Release version.

If the code has bugs sometimes the Debug version still works.

 

LE: I have the impression you didn't updated the address for qword_145907F18 variable.

In your DLL I can find 18 7F 90 05 bytes, which is the old address (0x05907F18), instead finding 98 EE 8C 05 bytes (0x058CEE98), which is the new address.

See this: https://forums.nexusmods.com/index.php?/topic/7759433-help-needed-compile-a-cpp-file-into-a-dll/?p=71250908

Edited by Wolfmark
Link to comment
Share on other sites

  • Replies 64
  • Created
  • Last Reply

Top Posters In This Topic

Hi Wolfmark.

 

Yes, you were right - I missed that bit!! I only found one instance of 0x05907F18 in main.ccp, changed it to 0x058CEE98, recompiled as debug and repackaged - exactly the same result :sad:.

 

Here's my files if you want to check them. The only difference at my end is the source folder - I changed it to C:\Users\Kev\Downloads\build\src\f4se just to make things easier for me to understand. Having that long clipboard version folder name was driving me nuts. I hope that doesn't mess anything up!

Link to comment
Share on other sites

Everything looks OK, except one little thing: the plugin verifies the game version and if is different than 1.10.98 then it displays "Game Version Error" message box and fails to load.

So this must be changed. But the question is: why did you say that "No complaints about version or other error messages though." when this should actually be the first thing the plugin does (see line 3237 from main.cpp)?

 

I assume the plugin is not enabled / loaded for some reason.

 

Note that you don't need to repackage the entire thing whenever you compile the DLL. You only have to copy the new DLL in Data\F4SE\Plugins folder. And make sure that the old one is removed or doesn't have the DLL extension.

 

So:

 

1. Install again the latest "official" release (the one for version 1.10.98).

2. Start the game and you should see "Game Version Error" message box.

3. Replace the old DLL with the new one.

4. Start the game again and you should still see "Game Version Error" message box.

 

Currently it seems that the game simply doesn't load the DLL (for some reason). Maybe F4SE is not installed correctly ... I don't know.

Verify My Games\Fallout4\F4SE for error messages. Upload the folder and post a link, so I can take a look.

 

Then you'll need to fix the code that verifies the run-time version.

Edited by Wolfmark
Link to comment
Share on other sites

Yes, you're absolutely correct - it's giving the following error in f4se.log:

 

F4SE runtime: initialize (version = 0.6.17 010A08A0 01D52DEF60164826, os = 6.2 (9200))
imagebase = 00007FF661260000
reloc mgr imagebase = 00007FF661260000
plugin directory = C:\Program Files (x86)\Steam\steamapps\common\Fallout 4\Data\F4SE\Plugins\
checking plugin C:\Program Files (x86)\Steam\steamapps\common\Fallout 4\Data\F4SE\Plugins\\ClipboardExtension.dll
couldn't load plugin C:\Program Files (x86)\Steam\steamapps\common\Fallout 4\Data\F4SE\Plugins\\ClipboardExtension.dll (Error 1114)
config path = C:\Program Files (x86)\Steam\steamapps\common\Fallout 4\Data\F4SE\f4se.ini
init complete
RegisterPapyrusFunctions_Hook

 

....all other plugins are loading and working perfectly.

 

So I guess the question now is - how do I find out what error 1114 is?

 

EDIT: I searched the net and found this:

 

error 1114 dynamic link library (DLL) intialization routine failed.

 

That's a generic Microsoft error though, and I'm not sure if the error number is a Microsoft or F4SE error number. But, it is DLL related so maybe it's a generic MS error?

Link to comment
Share on other sites

Yes, that's the error. But I don't know the cause.

The idea is that LoadLibrary call fails. And the error code is 1114, which means ERROR_DLL_INIT_FAILED.

 

Is the original file (for 1.10.98), or the one you've built (for 1.10.138)?

If is your file, try the original one, see if that can be loaded successfully (it still should fail, but with another error, because the F4 run-time is not the expected one).

If is the original file then try your file.

Edited by Wolfmark
Link to comment
Share on other sites

Yes, my compiled dll gives the error 1114 in the log, but the original dll gives an error message window complaining about the wrong version.

 

http://repo.duckdns.org/pub/junk/clipboard/Capture09.PNG

 

...so it looks like the recompiled dll is the problem :sad:.

 

My (uneducated) guess is that the dll is now recompiling perfectly, but not actually working because we still need to modify those blasted RelocAddr numbers that MaybeSomeone pointed out on the Clipboard comments page.

 

The million dollar question is - how do we do that?

Link to comment
Share on other sites

The addresses are OK, I've verified them.

The code has a bug (line 73): a global variable from main.cpp (nullHandle) is initialized using the value of a global variable from another unit (g_invalidRefHandle).

UInt32 nullHandle = *g_invalidRefHandle;

The standard doesn't specify the order of initialization, so this depends on compiler (the version, the settings etc...).

So it seems that nullHandle is initialized before g_invalidRefHandle => an exception occurs => the DLL cannot be loaded.

Probably Struckur compiled with different settings or with a different Visual Studio version.

Link to comment
Share on other sites

Starting from your files (the clipboard-cpp-files.zip archive):

 

1. The C/C++ => Preprocessor => Preprocessor Definitions is invalid. I said "Add _CRT_SECURE_NO_WARNINGS to the list with preprocessor definitions", but you instead replaced the default ones with _CRT_SECURE_NO_WARNINGS.

For Debug the setting should be: _DEBUG;CLIPBOARD_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS

For Release this setting should be: NDEBUG;CLIPBOARD_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS

 

2. The C/C++ => Advanced => Forced Include File should be "common/IPrefix.h", not "common/IPrefix.h;%(ForcedIncludeFiles)" (without quotes).

Or maybe Visual Studio 2019 adds the last part automatically.

 

3. Fix the bug in line 73. This is the line that causes the error 1114. Replace

UInt32 nullHandle = *g_invalidRefHandle;

with

UInt32 nullHandle; // = *g_invalidRefHandle;

and then edit F4SEPlugin_Query and change:

// ### do not do anything else in this callback
// ### only fill out PluginInfo and return true/false
 
// supported runtime version
with
// ### do not do anything else in this callback
// ### only fill out PluginInfo and return true/false
nullHandle = *g_invalidRefHandle; // WMK
// supported runtime version

4. The F4SEPlugin_Query and F4SEPlugin_Load are not exported by default (probably Struckur used a DEF file that was not uploaded on GitHub), so their signature must be fixed. Add __declspec(dllexport) at the start of the line:

__declspec(dllexport) bool F4SEPlugin_Query(const F4SEInterface * f4se, PluginInfo * info) { // WMK
__declspec(dllexport) bool F4SEPlugin_Load(const F4SEInterface * f4se){ // WMK

That's all for now. Do the changes and then test the resulted DLL. Should complain about invalid Fallout 4 version.

Then create another zip with the project's files (everything in project's folder + GameReferences.h file) and give me the link to verify that everything is ok.

 

https://imgur.com/a/r0Xpyng

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...