cmake-js icon indicating copy to clipboard operation
cmake-js copied to clipboard

Add win_delay_load_hook.c

Open xiazhvera opened this issue 1 year ago • 5 comments

Support windows delay load hook in C. I create a new MACRO for c source as I'm not sure if there is a better way to detect the project language in cmake-js. Feel free to update the PR.

xiazhvera avatar Jan 18 '24 18:01 xiazhvera

It looks like the only difference is the line const PfnDliHook __pfnDliNotifyHook2 = load_exe_hook;
I wonder if that line could be wrapped in #ifdef __cplusplus or similar instead?

I've tried to write a test which triggers this issue, but I can't find how to tell cmake to disable the use of c++ so it builds successfully with the c++ version of the hook. How have you done it? https://github.com/cmake-js/cmake-js/tree/test/node-api-c

Julusian avatar Jan 18 '24 20:01 Julusian

If you run your test, you could find the following line in .\tests\es6\prototype-napi-c\build\addon_napi_c.vcxproj.filters

<None Include="D:\Amazon\IOT\cmake-js\lib\cpp\win_delay_load_hook.cc">
      <Filter>Source Files</Filter>
</None>

Though the lib is built without error, the win_delay_load_hook.cc was never compiled because cpp file could not be recoginized in the c project.

xiazhvera avatar Jan 18 '24 21:01 xiazhvera

I don't know CMake enough to know if #ifdef __cplusplus would help. I assume the issue was that the cmake could not set the correct compile rule for *.cc file. As along as the hook file end with *.cc, cmake could not generate the correct visual studio configuration.

xiazhvera avatar Jan 18 '24 21:01 xiazhvera

Though the lib is built without error, the win_delay_load_hook.cc was never compiled because cpp file could not be recoginized in the c project.

Of course.. very helpful of them to hide a misconfiguration that will cause build and/or runtime errors

I am open to merging this as-is, but I would like to consider options to make it more idiot proof first, even though it would appear that needing this to be in c is rare enough to not warrant much effort.

Perhaps if it was named .h instead, then it should be compiled in both cases? I should get out a windows machine and give this a test myself

Julusian avatar Jan 22 '24 15:01 Julusian

Though the lib is built without error, the win_delay_load_hook.cc was never compiled because cpp file could not be recoginized in the c project.

Of course.. very helpful of them to hide a misconfiguration that will cause build and/or runtime errors

I am open to merging this as-is, but I would like to consider options to make it more idiot proof first, even though it would appear that needing this to be in c is rare enough to not warrant much effort.

Perhaps if it was named .h instead, then it should be compiled in both cases? I should get out a windows machine and give this a test myself

The .h idea sounds nice. I will also test it out and update the PR when I got time.

xiazhvera avatar Jan 23 '24 18:01 xiazhvera