How to remove c # dll from c ++ dll

I have created a C # dll which contains RSA algo and the same DLL is loaded into the dll dll. When I try to delete a C # dll after its using system throws an exception that the C # dll is already in use even though I have all the interface pointers. Below is my code:

in C ++

ICryptInterfaceRSA *crpt = null;
coinitialize(null);
hresult hr = ::cocreateinstance(guid1,guid2,<reinterpret cast>(void**)&crypt);
//doing my encryption and decryption
crpt->Release();
coUninitialize();

//Problem occurs at below mentioned code 
BOOL b = DeleteFile("C# dll file path");
DWORD dw = GetLasterror();

      

dw is given as 5 (File already in use)

How to overcome this problem. If it cannot be removed then what are the workarounds. Please help me. Thanks in advance.

+3


source to share


1 answer


Several possible checks / answers:

If you don't need to remove it "right now", you can use MoveFileEx to remove it on the next reboot (if the destination is NULL, it removes, not moves).

Use Process Explorer to find out which handles are still open and write code to explicitly close them. You can also close the handles using the Process Explorer interface and confirm that you can delete the DLLs after you force them to close (your application might accidentally crash).



Try GetModuleHandle ("dllname.dll") to see if the DLL is still loaded in your process (returns NULL if not) and try FreeLibrary on the handle if it is still loaded.

If the C # code is yours, can you use C ++ / CLI and normal "export functions" instead of COM? You have more control over download / release this way.

Your design is kind of flawed, I did my best to change it if possible. I've seen programs (mainly Anti-Virus) that will keep files for a sufficient amount of time after they are available. Depending on its ability to delete a file immediately after downloading and freeing it, it does not appear to be reliable.

0


source







All Articles