CnUnix

[알림판목록 I] [알림판목록 II] [글목록][이 전][다 음]
[ CnUnix ] in KIDS
글 쓴 이(By): ksangeun (우주인)
날 짜 (Date): 2002년 12월 16일 월요일 오후 05시 49분 31초
제 목(Title): Re: VC++로 개발할 때


정확하게 IPC의 주 목적을 몰라서, 별 도움이 되지 않을 답변이 될 수도

있지만, Message Queue를 이용한다면, COPY_DATA말고,

PostThreadMessage가 기억이 확실치는 않지만, 다른 프로세스의

thread로도 message를 posting하는게 가능한 것 같습니다.

(방금 MSDN을 찾아보니, Message ID 0~WM_USER까지만 다른 프로세스로의

마샬링을 지원한다네요... 사용자 정의 메세지는 안될듯...)


메모리 공유를 위한 방법으로는

일단 Memory-mapped file을 사용하는 방법이 있고요,

Memory-mapped file은 MSDN을 찾아보면 쉽게 쓰실 수 있고요....

또 다른 방법으로,

VC로 만든 같은 에플리케이션이나 DLL의 여러개의 인스턴스간에

손쉬운 IPC 방법이 있습니다.

한개의 변수를 여러개의 인스턴스가 공유를 하는 방법인데요...

아래 내용을 참조하시고요... 

To share data between different instances of the same application or 
DLL...

The Visual C++ compiler lets you name your own data segments.  You can 
pass an option to the linker that tells it to share one of these custom 
data segments, in which case all instances of your module (DLL or EXE) 
will map to the same instance of your custom data segment.

Put this in the code module where you want the "process-global" variables:


#pragma data_seg(".SHARED")

char pg_pszShared[256] = {0}; // variables MUST be initialized,
 // not sure why

#pragma data_seg()

#pragma comment(linker, "/section:.SHARED,RWS")


Note that the name ".SHARED" could be whatever you want.  And you can add 
almost any variables you want between the two "#pragma data_seg()" 
directives.  I've encountered two restrictions so far: pointers that point 
to data that's outside the shared segment don't work (for hopefully 
obvious reasons), and variables for classes that do their own 
memory-management (like MFC's CString) don't work.

The "data_seg" pragma tells the compiler to put all the variables 
following in the specified data segment (or rather, data section in Win32 
speak).  Calling it the second time with no argument tells it to go back 
to using the default data section.

The "comment" pragma passes an option to the linker that tells it to 
actually share the specified data section.  You could put this in a .DEF 
file too.  


             __ o      
             |/|_    __o__         /  
           _/|     |_/       _L___o__             
             |.     /.      .               L___ o__
          어...    어..      억.....       철. 푸. 덕.
[알림판목록 I] [알림판목록 II] [글 목록][이 전][다 음]
키 즈 는 열 린 사 람 들 의 모 임 입 니 다.