fungos / cr

cr.h: A Simple C Hot Reload Header-only Library
https://fungos.github.io/cr-simple-c-hot-reload/
MIT License
1.57k stars 103 forks source link

Starting a DLL #4

Closed Pombal closed 6 years ago

Pombal commented 6 years ago

Hello!

I have some questions regarding the usage of cr, it might be that these are unsupported use cases or I'm just doing something wrong :)

I have a DLL that gets started by a server and from a client I'd like to monitor that DLL and reload it with changes. The first problem is the first call to cr_plugin_update sees that the dll has changed and loads it because the timestamp is not initialised during cr_plugin_load. This triggers a call to DllMain which causes problems because the dll is only supposed to be started from the server.

The second problem I see is doing a GetCurrentDirectory from DLLMain shows the directory of the client but the current workspace for that DLL should be the directory where it is in. This is after the first problem.

Lastly, building the changes from inside Visual Studio gives an error because the pdb is being used by another process and the changed dll will not be produced.

The code I'm using is basically the same as the example provided in the README. Any ideas on what I might be doing wrong would be greatly appreciated.

Thanks!

fungos commented 6 years ago

Hi. I'm not sure to follow your use-case to be able to give some directions right now. Your last point is weird and may indicate some wrong usage as the pdb should never be locked.

a recap: the pdb should never be locked, because as soon the application using the dll (in your case the server), during the cr_plugin_update before loading it for the first time, it will in reality copy the dll and pdb with a new name and use that one. So it seems that your visual studio is trying to write over this new copy for some reason, or this copy is not happening, or an error patching the dll to point to this new pdb is not working. So, try checking if this error is happening in the server https://github.com/fungos/cr/blob/master/cr.h#L1165-L1166.

How do your project and directories are structured? I mean, do you have 3 projects: server, client and logic (dll)? If you can describe a bit more, where are their output placement and naming?

Why do you need that the client signal the server indicating that the dll should be reloaded? The idea is that cr.h on the server will do this anyway. So what I'm seeing is that you want to have more control on how/when the dll is reloaded, in this case what do you gain by using cr.h instead doing a simple plugin system?

Pombal commented 6 years ago

The directories and use case are structured as follows: There is a server ( which I have no control over and cannot modify the code of ) at directory e.g. "C:/server". which will load a dll ( e.g myserver.dll ) which I do control. myserver.dll is the one I am interested in reloading. I also have a client in e.g "C:/client" which I also have control over and will tell the server to start which will eventually load myserver.dll. In the client I have a normal update loop which monitors "C:/server/myserver.dll".

The first two problems come from this usage scenario. The third problem probably also comes from this usage since now I'm starting to understand that I should have control over the server since it is basically the host and the guest is the dll and I was ( without realising ) trying to make it so that my client is the host.

Is there any way of making this scenario work? Thanks for the help :)

fungos commented 6 years ago

Not with cr.h.

And if you do not have control over the server application, then you're pretty much stuck with the server plugin api or some low level trickery on windows.