Создание Proxy DLL для маршалинга в программе
От: Ivanalt  
Дата: 23.08.07 09:54
Оценка:
Преамбула: в одном воркспэйсе живут два проекта: ATL и MFC, созданные в меру моего разумения технологии СОМ.
Исходя из каких-то высших соображений, они должны общаться между собой посредством proxy/stub маршалинга.

В МСДНе пишут:
the .c and .h files that MIDL generated must be compiled and linked to create a proxy DLL, and that DLL must be entered into the system registry so that clients can locate your interfaces.


Вопрос1: КАКИЕ из имеющихся в проекте .c и .h файлов генерирует имеено MIDL??? И каким образом их надо компилировать и линковать???

The first step in building the DLL is to write a module definition file for the linker, as shown in this example: 

LIBRARY        example.dll
DESCRIPTION    'generic proxy/stub DLL'
EXPORTS        DllGetClassObject      @1 PRIVATE
               DllCanUnloadNow        @2 PRIVATE
               DllRegisterServer      @4 PRIVATE
               DllUnregisterServer    @5 PRIVATE


Вопрос2: ГДЕ должен быть прописан этот модуль??? ЧТО и КАК в нем надо прописать???

Еще там есть что-то насчет командной строки.
Но чтобы опеспечить переносимость на другие ИМХО эту proxy DLL надо размещать внутри воркспэйса.

Alternatively, you can specify these exported functions on the LINK command line of your makefile.
The exported functions are declared in Rpcproxy.h, which Dlldata.c includes, and default implementations are part of the RPC run-time library. COM uses these functions to create a class factory, unload DLLs (after making sure that no objects or locks exist), retrieve information about the proxy DLL, and to self-register and unregister the proxy DLL. To take advantage of these predefined functions, you need to invoke the Cpreprocessor /D (or -D) option when you compile the Dlldata.c and Example_p.c files, as shown in the following makefile:
example.h example.tlb example_p.c example_i.c dlldata.c : example.idl
    midl example.idl
dlldata.obj : dlldata.c
    CL /c /DWIN32 /DREGISTER_PROXY_DLL dlldata.c
example.obj : example_p.c
    CL .c.DWIN32 /DREGISTER_PROXY_DLL example_p.c
iids.obj : example_i.c
PROXYSTUBOBJS = dlldata.obj example.obj iids.obj
PROXYSTUBLIBS = kernel32.lib rpcndr.lib rpcns4.lib rpcrt4.lib uuid.lib
proxy.dll : $(PROXYSTUBOBJX) example.def
    link /dll /out:proxy.dll /def:example.def
        $(PROXYSTUBOBJS) $(ORIXYSTUBLIBS)
    regsvr32 /s proxy.dll
 
If you do not specify these preprocessor definitions at compile time, these functions are not automatically defined (that is, the macros in Rpcproxy.c expand to nothing). You would have to have defined them explicitly in another source file, whose module would also be included in the final linking and compilation on the C compiler command line.
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.