Yes, if you make a dynamic link and make the c-style interface. lib.exe will generate import libraries that are compatible with the gcc toolchain.
This will solve your binding problems. However, this is only the beginning of the problem.
Your big problems will be like exceptions and memory allocation.
- You must make sure that the exception did not go from VC ++ to gcc code, there are no guarantees of compatibility.
- Each object from the VC ++ library will have to live on the heap, because:
- Do not mix gcc new / delete with anything from VC ++, bad things will happen. This also applies to building an object on the stack. However, if you create an interface such as create_some_obj () / delete_some_obj (), you cannot use gcc new to create VC ++ objects. Perhaps create a small handler object that handles construction and destruction. This way you keep RAII, but still use the c-interface for the true interface.
- The calling agreement must be correct. In VC ++ there is cdecl and stdcall. If gcc tried to call an imported function with the wrong type of call, bad things will happen.
The bottom line contains a simple ANSI C compatible interface and everything should be fine. The fact that crazy C ++ goes behind is ok if it is contained.
Oh, and make sure all the code is redirected, or you run the risk of opening the whole outline of the worm.
litghost
source share