3

I'm trying to call CoCreateInstance(...) via a 64-bit Java library: org.eclipse.swt.internal.ole.win32.COM. The DLL I'm trying to hook into is a DLL for Visual SourceSafe. The point of the project is to port a VSS plugin (http://sourceforge.net/projects/vssplugin/) made for 32-bit Eclipse to 64-bit Eclipse.

The call works fine when I use the 64-bit version of org.eclipse.swt.internal.ole.win32.COM, but with the 32-bit version, the call fails. The call is being used like this:

private void init(GUID guid) {
    long[] ppv = new long[1];
    int result = COM.CoCreateInstance(guid, 0, COM.CLSCTX_INPROC_HANDLER | COM.CLSCTX_INPROC_SERVER | COM.CLSCTX_LOCAL_SERVER,
            COM.IIDIDispatch, ppv);
    if (result != COM.S_OK)
        OLE.error(OLE.ERROR_CANNOT_CREATE_OBJECT, result);
    init(new OleAutomation(new IDispatch(ppv[0])));
}

The call fails and returns -2147221164, which I guess is some kind of error code specifying that the corresponding registry entry can't be found.

Some things I've tried include:

Does anyone have advice on this?

kwikness
  • 1,425
  • 4
  • 21
  • 37

2 Answers2

5

CoCreateInstance is just going to call LoadLibraryEx, and that can't load 32-bit libs in a 64-bit process. Period, ever. You could, on the other hand:

  1. obtain a legitimate 64-bit copy of the com component.
  2. create your own not-in-process COM server that in turn calls the one you've got, and call CoCreateInstance for the ID of that.
  3. Create a web service that wraps this thing and use java to call that.
  4. go back to a 32-bit Eclipse.
bmargulies
  • 97,814
  • 39
  • 186
  • 310
  • 1
    Sorry, but that's a terrible and discouraging response. It's obviously not impossible: http://stackoverflow.com/questions/2925479/ways-to-wrap-32-bit-dll-so-it-will-work-in-a-64-bit-os – kwikness Dec 28 '11 at 19:54
  • 1
    @kwikness, sorry or not, you can't load a 32bit lib in 64bit process, simple as that. you can wrap it in a 32bit process and communicate through RMI or whatever you feel you have to. But you can't load it in-process. – bestsss Dec 28 '11 at 20:08
  • I never specified that I was opposed to such a solution, but this is quite enough pointless smart-alecking for one SO post. Thanks for your updated answer bmargulies. – kwikness Dec 28 '11 at 20:16
1

If the COM DLL is automation compatible you just need to set DllSurrogate registry entry. COM subsystem will start 32-bit DllHost.exe that will serve as an out-proc COM server for your 64-bit process.

Sergey Podobry
  • 7,101
  • 1
  • 41
  • 51