Saturday 15 January 2011

c# - Proper Manner for Writing COM/ATL Wrapper for 32-bit DLL -


I have a question about writing a COM / ATL wrapper for a 32-bit DLL.

The problem here is, according to some of my other questions, I often have to do coding work on a large codebase, which includes libraries related to the magnitude of different vendors. We have software that can be used in various types of machines It runs on different types of architecture. This code is mainly written in C #, and C + + DLLs are connected or compiled / linked and later when needed (managed by C # in my opinion, easier than managed C ++ ) C / is included.

Anyway, a program contains the C # code which should be interfaced with a 64-bit DLL, for which the source is unavailable. The goal of this software is not to mention the host machine is all 64-bit. C # is running in ccpu mode, automatically generated as 64-bit (without woof), and it is able to p / collect the already compiled, third-party 64-bit DLL.

There is no way to get a 64-bit version of this DLL for the same DLL for which only 32-bit versions are available to me. 1.) 32-bit DLL, a 2.) Function Exported header file (i.e. #define EXP __declspec (dllexport), EXP BOOL WINAPI DLL_Function (IN int myInt, OUT int * result); and 3.) After a comprehensive 32-bit lip file.

After extensive research, I learned that, apparently, COM / ATL is a fair way to use 32-bit DLL with 64-bit process, obviously, The 32-bit COM process was used, and the interface with it. An architecture looks okay from the perspective, but I can not find any tutorials or particularations in particular as to how to do it. I have tried to use the Visual Studio 2010 ATL wizard, but it is still fine how to do it properly. Is there an automatic device? Any templates or tutorials? I promise that I have lost my ability to the best network, and thinking about only 1). If I am seeing this problem correctly, or 2.) Do you have any resources Know about, or 3.) Do anyone have any kind of normal IPC templates?

From what I have read, it seems that image mismatch is a common problem for programmers, yet I can not comment on any detailed explanation (or at least for clarification), "com / Apart from using ATL "one of my previous posts generated a response, in which a question p / applicant questions were asked in detail, which was astonishing - I am thinking that maybe we can not Fixed "64/32-bit cross-architecture

-corpg

EDIT: I am already familiar, and understand the architecture, but the details of the implementation I'm thinking about

You can get at least ATL solution in just a few minutes.

Step-by-step instructions:

  1. Create an empty solution
  2. Add the ATL project using the Visual Studio Wizard. It will be C ++, ATL project, EXTULTABLE EXE - you will need EXE because it will be different 32-bit process hosting your 32-bit code
  3. Add this class to this project, simplify the ATL You will have a class (such as CFoo) with the IDispatch-derived interface IFoo
  4. - a method for the IFoo interface - from the object, all the default. Add, and implement in the related CFoo class, eg CFU :: B C / +>
  5. C + + is divided, create and ensure that it is COM-registered (run executable once with the / regserver parameter) < / Li>
  6. Add C # project, apply its bitness to x64 , add COM reference of your ATL COM server at step 5 above
  7. Add your C # Add [STAThread] to code and C # from call bar - you're done!

    C #:

      class program {[STAThread] static zero main (string [] args) {HostLib .Foo foo = New HostLib.Foo ( ); Foo.Bar (); }}   

    C ++ IDL:

      [// ...] Interface IFoo: IDispatch {[ID (1)] HRESULT bar () ; };   

    C ++:

      // IFoo STDMETHOD (bar) {messagebox (GetActiveWindow), _T ("Hello, 32-bit World ! "), _T (" Information "), MB_OK); Return S_OK; }   

    64-bit C # code is called via 32-bit COM EXE and bar method

    Source: /.

No comments:

Post a Comment