Search code examples
c#c++dllunmanagedmanaged

Utilizing a Managed C# DLL from an ETL Tool via a Mixed-Mode C++/CLI DLL - Possible?


I am working within a 32-bit ETL tool (Pervasive Data Integrator v9). I need to give this tool the ability to call an external function that will remove a file from within a ZIP archive without extracting the archive.

The ETL tool provides the ability to load an external DLL and call its functions. The DLL and its function gets referenced by ETL tool's custom script language like this:

Declare function OemToCharA lib "user32" (byval lpszSrc as string, byval lpszDst as string) as long

The function (OemToCharA in this example) is then called somewhere in the lines of the script that follow that declaration. I have tested this with a registered DLL and it works.

So I want to build a DLL with a function that will do the zip manipulation.

Since I don't know how to manipulate zip files programatically, I found DotNetZip - a free .NET class library that provides the heavy lifting for the zip archive operations. Problem for me is that it is .NET (managed). I would still like to try to use it. So I built a C# DLL (.NET 4.0) with a function that utilizes DotNetZip to do the required zip file manipulation. I pass in two parameters, "zip file location" and the "file to remove" and the zip archive gets updated.

I read about the idea of building a mixed-mode C++/CLI DLL to take advantage of managed .NET code in the native world. I found this VS solution which consists of 3 basic projects:

  1. Managed (C#) DLL project
  2. Mixed-mode C++ DLL wrapper project which references the C# DLL
  3. A native (unmanaged) C++ console test app project which references the C++ wrapper

I built a test solution based on that pattern which removes a file from a zip archive and it works great. Please note however that the mixed mode DLL is called from a native C++ console app which is part of the VS solution. I didn't have to register any DLLs and it just works.

However ultimately I need the ETL tool to call the mixed mode DLL. I am not able to get this to work.

Things I have tried on the ETL server thus far:

  • I tried to register the mixed-mode wrapper DLL but SysWow64\regsvr32 fails to find an entry point in the DLL.
  • I installed VS 2015 VC++ x86 and x64 redistributable libraries on the ETL server.
  • I placed the DLLs from my solution (i.e., the mixed mode, c# and dotnetzip dlls) in the ETL engine folder because the console app worked when the DLLs were in its deploy folder.

The ETL tool has the ability to call an external application so I believe I could let it call a console app similar to my VS test solution but I'd really like to get this to work with only the DLLs. Is this possible? If so, what am I missing?


Solution

  • Kudos to Matt, thanks for the hint to use Process Monitor.

    • ETL tool was not finding the DLL but Process Monitor told me the folders it was checking...I moved the DLLs to one of the checked folders
    • My wrapper function was originally void with an output parameter for the return value - that was causing issues as I didn't have a good example in the ETL documentation of how to call a void function. I changed the function to return a "long" and removed the output parameter.

    After making those two changes it started working. Thanks again Matt!