com4j icon indicating copy to clipboard operation
com4j copied to clipboard

Support licensed object instantiation with IClassFactory2

Open ro6 opened this issue 10 years ago • 4 comments

We've been using com4j happily for years but the software we integrate with is about to start requiring a license key and we're trying to figure out if that's something com4j supports or could be modified to support easily. The examples we were shown for passing the license key are in C# and use CoGetClassObject (https://msdn.microsoft.com/en-us/library/windows/desktop/ms684007(v=vs.85).aspx) to get an instance of IClassFactory2 (https://msdn.microsoft.com/en-us/library/windows/desktop/ms680095(v=vs.85).aspx), on which they call CreateInstanceLic (https://msdn.microsoft.com/en-us/library/windows/desktop/ms694342(v=vs.85).aspx) to get an instance of the actual COM interface needed.

My research so far leads me to believe that the IClassFactory2 method of instantiation is at a lower level than what com4j provides, and library internals would have to be augmented to allow passing the license key in from Java.

Can anyone confirm this?

Thanks!

ro6 avatar Sep 22 '15 10:09 ro6

Yes, I believe it's true that com4j cannot support this as is. com4j only creates objects using CoCreateInstance.

mpoindexter avatar Sep 22 '15 15:09 mpoindexter

One thing you might be able to do as a workaround is to use something like JNA to call CoGetClassObject, and then use COM4J.wrap to take ownership of the pointer and convert it to a IClassFactory2

mpoindexter avatar Sep 22 '15 21:09 mpoindexter

I saw that method the other day while looking through the code. I'll see if I can get it working that way.

ro6 avatar Sep 23 '15 11:09 ro6

We need this same functionality. Has anyone had any success with the work-around using JNA?

raner avatar Jul 01 '17 01:07 raner