Skip to content

Add win_delay_load_hook.c #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xiazhvera
Copy link

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.

@Julusian
Copy link
Collaborator

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

@xiazhvera
Copy link
Author

xiazhvera commented Jan 18, 2024

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
Copy link
Author

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.

@Julusian
Copy link
Collaborator

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

@xiazhvera
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants