SHMSiseApp.7z
0.06MB
SHMSIse.zip
0.10MB
공유메모리로 주식 시세나 프로세스간 데이터 공유하는 방법
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/*
* Module: SiseThread
* Delta: 1.0.0 (05/18/2019 11:48:34)
* Filename: SiseThread.h
* $Author: krkim $
* $Id: SiseThread.h 7995 2025-06-29 11:27:20Z krkim $
* $Revision: 7995 $
* 메세지큐를 별도로 갖기위한 시세작업쓰레드 생성
*/
#pragma once
using namespace stdext;
#include <BizThread.h>
#include "DlgOutBar.h"
#include "helper.h"
#include <SiseLogic.h>
#include <DlgStockList.h>
#include <DlgLedger.h>
#include <DlgSentHist.h>
#include <DlgToolReplay.h>
#include <CFGApp.h>
#include <BizDataCenter.h>
#include "HMSiseWnd.h"
#include "HMRealWnd.h"
#include "kxMemPool.h"
#include <STSisePack.h>
#include <iostream>
#include <condition_variable>
#include <mutex>
#include <thread>
#define MAX_SISEWND 7
#define MAX_SISEPOOL 100 //나중에 환경설정으로
//시세창 윈도우UI ID
enum ENUM_SISEUID
{
SISEUID_JANGO, //잔고창
SISEUID_HOGA, //호가창
SISEUID_HOGA2, //호가창2 20230612 두번째호가창
SISEUID_BUNSISE, //분시세창
SISEUID_DAILY, //일시세창
SISEUID_BOOKMARK, //즐겨찾기
};
extern int g_use_recvthread;
extern bool g_use_scope_lock;
extern void PushRecvQueue(STSiseEventPack pack);
class CSiseThread : public CWinThread
{
DECLARE_DYNCREATE(CSiseThread)
public:
CSiseThread(); //적 만들기에 사용되는 protected 생성자입니다.
virtual ~CSiseThread();
public:
static bool m_bUseThreadPool;
static bool m_bUseMemPool;
BOOL m_bQuerySiseOnline = 1; //호가,체결가 조회를 DB가 아닌 실시간서버로부터
HMSiseWnd *m_pSiseWnd; //조회,일시세등 전역기능
int m_waitvolstockcount; //대기종목수
kxMemPool<STSisePack>* m_pRecvMemPool;
void QuitMe();
//0 = 코스피,1=코스닥 리얼등록
HMRealWnd *GetRealSiseWnd(int index){ return m_pRealWnd[index];}
void SetRealWnd(int index, HMRealWnd *pWnd) { m_pRealWnd[index] = pWnd; }
BOOL SetReal(HMSiseInfo *pSItem);
BOOL ResetReal(HMSiseInfo *pSItem);
BOOL SetRealDanSise(HMSiseInfo* pSItem); //시간외단일가 리얼등록
BOOL UnRealDanSise(HMSiseInfo* pSItem);
//void SetUISiseCode(int what,LPSTR szCode); //현재감시종목코드
//char* GetUISiseCode(int what);
void SetUISiseCode(int what, char* szcode);//int에서 char로 변경 ETF종목코드에 영문자 들어가기때문
LPCSTR GetUISiseCode(int what);
void SetSiseUIWnd(int what,HWND hWnd) { m_hSiseUIWnd[what] = hWnd; }
HWND GetSiseUIWnd(int what,char *pncode = NULL);
int SetRealDanList();
protected:
HMRealWnd *m_pRealWnd[3];//0=코스피리얼,1=코스닥리얼,2=ETF/ETN
//20250926 int에서 char로 변경 ETF종목코드에 영문자 들어가기때문
string m_szsisecode[MAX_SISEWND];
HWND m_hSiseUIWnd[MAX_SISEWND]; //시세받을 창
BizThread<int, void> m_threadBid; //20230106
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
void CreateHiddenSiseWindow(BOOL bAutoStart = FALSE);
void CreateRealSiseWindowList();
//매수점검 where = 0:체결시세,1:호가시세서 주문
int TryBidOrder(HMSiseInfo* pSItem, /*ENUM_ORDWHERE*/ byte where,int checkonly);
void OnThreadRecvSise(STSiseEventPack eventpack,int id);
protected:
void ThreadStart();
void ThreadStop(DWORD dwWaitMilisec = 5000);
BOOL IsThreadRun();
int Thread_doWork();
void OnThreadEnd(int flag);
static DWORD WINAPI ThreadProc(LPVOID pParam);
//시세기록
int OnWatchSise(HMSiseInfo* pSItem, STJangoInfo* pFItem, int timegapsecs);
//다이렉트로 매수시도(wheresise = 호가,체결틱 수신여부)
int OnTradeAction(HMSiseInfo* pSItem, LPCSTR shtcode, byte wheresise, int tid = 0);
protected:
int BidCheckPoint(HMSiseInfo* pSItem, byte where);
DECLARE_MESSAGE_MAP()
afx_msg void OnStartService(WPARAM wParam, LPARAM lParam);
afx_msg void OnServiceDestory(WPARAM wParam, LPARAM lParam);
afx_msg void OnRealSise(WPARAM wParam, LPARAM lParam);
public:
};
|
cs |
https://www.paypal.com/paypalme/duruedit
PayPal.Me를 통해 Durumul 님에게 결제
paypal.me/duruedit로 이동한 후 금액을 입력하세요. PayPal 서비스를 이용하면 언제나 간편하고 안전합니다. PayPal 계정이 없으세요? 걱정하지 마세요.
www.paypal.com
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/*
* Module: SHMSiseAPI.H
* Delta: 1.0.0 (05/18/2019 11:48:34)
* Filename: SHMSiseAPI.h
* $Author: krkim $
* $Id: SHMSiseAPI.h 7995 2025-06-29 11:27:20Z krkim $
* $Revision: 7995 $
* Contacts: https://durumul.com durumul@gmail.com
* 주식시세공유메모리 관리자
*/
#ifndef SHMTOOL__H
#define SHMTOOL__H
#include <list>
#include <string>
#include <map>
#include <unordered_map>
#include <STSise.h>
using namespace std;
#pragma pack( push, 1 )
#pragma once
using namespace NSHomi_Common;
namespace ns_SHMSiseAPI
{
#define MYUNSORTEDMAP unordered_map //hash_map이 C++11 에서 없어지고 unordered_map로 표준화됨
#define MYSORTEDMAP map
#define SHMSISE_WINDOWCLASSNAME "SHMSise"
#define SHMSISE_WINDOWEXENAME "SHMSise.exe"
#define SHMSISE_MAPNAME "SHMSise-Map"
#define SHMSISE_MUTEXNAME "SHMSise-Mutex"
#define SHMSISE_WINDOW "SHMSise" //window class and title name
#define WM_SHMSISE WM_USER + 3003//message
#define SHMSISE_CLEAR 0//subcommand in wParam
#define SHMSISE_GETDATA 1//subcommand in wParam
#define SHMSISE_SETDATA 2//subcommand in wParam
#define SHMSISE_SETCMD 3
#define SHMSISE_SYSTEMID 999
#define SHMSISE_CMD_ATTACH "ATTACH"
#define SHMSISE_CMD_DETACH "DETACH"
//환경설정
typedef struct _SHMSISECONF
{
HANDLE hFileMap;
LPVOID mapping; //pointer to shared memory
HANDLE hMutex; //Lock Unlock
int nMaxItems; //공유메모리 데이타수 shared memory max count
int nTotalMapSize;
bool bFirstCreated;
_SHMSISECONF() {
hFileMap = NULL;
mapping = NULL;
hMutex = NULL;
nTotalMapSize = 0;
nMaxItems = 2000;
bFirstCreated = false;
};
}SHMSISECONF, FAR *LPSHMSISECONF;
//공유매핑파일(MMF) 해더정보
typedef struct _SHMSISEHEADER
{
int mapsize;
int realcount; //실제저장된 갯수
int offset2write;
int offset2read;
int rollback;
int writecount;
int readcount;
int lastwrateindex; //마지막 기록인덱스
int lastreadindex; //마지막 읽은인덱스
bool bFirstCreated;
int lasttime; //마지막 기록시간 hhmmss
LPVOID pdata; //실제데이타 시작위치(realdata entry point) 20250928
_SHMSISEHEADER() {
mapsize = 0;
realcount = 0;
offset2write = 0;
offset2read = 0;
rollback = 0;//쓰기위치를 0포인트로 이동
writecount = 0;
readcount = 0;
lastwrateindex = 0;
lastreadindex = 0;
lasttime = 0;
bFirstCreated = false;
pdata = NULL;
};
}SHMSISEHEADER, FAR *LPSHMSISEHEADER;
//공유매핑파일 데이터영역
#if 0
typedef struct _SHMSISEITEM
{
long id;
char szCmd[32];
char szKeyName[32];
char szParam[2048];
LPARAM param2; //요청자 HWND
}SHMSISEITEM,FAR *LPSHMSISEITEM;
#else
typedef struct _SHMSISEITEM
{
int index;
long ncode;
char shtcode[8];
LPARAM param; //요청자 HWND
STStockInfo si; //종목마스터 정보
STTickSise ts; //현재시세(틱이 아니라 당일일시세임) 20250403
STHogaSise hs; //현재수신또는보정된호가 20250403
}SHMSISEITEM, FAR* LPSHMSISEITEM;
#endif
//외부호출자(Caller) 정보
typedef struct _SHMSISEAPP
{
int id;
string keyname;
string logdir;
HWND hWnd;
}SHMSISEAPP, FAR *LPSHMSISEAPP;
typedef MYUNSORTEDMAP<string,SHMSISEAPP> SHMSISE_APPMAP;
class SHMSiseAPI
{
public:
SHMSiseAPI(int maxitem = 5000);
virtual ~SHMSiseAPI();
public:
LPSHMSISEHEADER GetSHMHeader();
int GetSHMHeader(LPSHMSISEHEADER lpHeader);
int GetSHMData(int index, LPSHMSISEITEM lpItem, int unmapeverytime = 0);
//void SetSHMData(LPCSTR szMapName, LPCSTR szMutexName, LPSHMSISEITEM lpData, int unmapeverytime = 0);
int DestroySharedMemory();
int CreateSharedMemory(LPCSTR szMapName, LPCSTR szMutexName,int nMaxItems = 0);
CString GetFormatMessageString(DWORD dwError);
long SetSiseCmd(int index, LPSHMSISEITEM lpItem, LPARAM param);
void GoRangLog(LPCSTR szkeyname, LPCSTR szbuff, LPARAM hWnd = NULL);
int AddSHMData(LPSHMSISEITEM lpItem, int unmapeverytime = 0);
int SetSHMData(int index, LPSHMSISEITEM lpItem, int unmapeverytime = 0);
void SHUnMap();
public:
SHMSISECONF m_siseconf;
HWND m_hSHMSiseWnd;
protected:
SYSTEMTIME uptime;
char lastupdate[8 + 1];//일자
protected:
int AttachSHM(); //공유메모리에 접근
};
}
#endif
|
cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
|
/*
* Module: SHMSiseAPI.cpp
* Delta: 1.0.0 (05/18/2019 11:48:34)
* Filename: SHMSiseAPI.cpp
* $Author: krkim $
* $Id: SHMSiseAPI.cpp 7995 2025-06-29 11:27:20Z krkim $
* $Revision: 7995 $
* Contacts: https://durumul.com durumul@gmail.com
* 주식시세공유메모리 관리자
*/
//이파일은 외부프로그램에서 included disable.
#include "stdafx.h"
#include <SHMSiseAPI.h>
#include <stdio.h>
#include <afxmt.h>
#pragma warning(disable : 4996)
using namespace ns_SHMSiseAPI;
#define HHMMSS2INT(hh,mm,ss) ((hh * 10000) + (mm * 100) + (ss * 100)+ss)
//SHMSISECONF SHMSiseAPI::m_siseconf;
SHMSiseAPI::SHMSiseAPI(int maxitem)
{
memset(&uptime, 0, sizeof(SYSTEMTIME));
#if 0
marketid = (int)ENUM_MARKETID::NONE;
memset(marketgb, 0, sizeof(marketgb));
ncode = 0;
memset(shtcode, 0, sizeof(shtcode));
memset(excode, 0, sizeof(excode));
memset(hname, 0, sizeof(hname));
memset(shtname, 0, sizeof(shtname));
memset(upname, 0, sizeof(upname));
memset(category, 0, sizeof(category));
#endif
//lastupdate[0] = 0x00;
memset(&lastupdate, 0, sizeof(lastupdate));
//noerror = 0;
//psi = NULL;
m_hSHMSiseWnd = NULL;
//pjan = NULL;
if(maxitem > 0)
m_siseconf.nMaxItems = maxitem;
}
SHMSiseAPI::~SHMSiseAPI()
{
}
//CMutex g_mutex(FALSE, "testmutex");
CString SHMSiseAPI::GetFormatMessageString(DWORD dwError)
{
LPVOID lpMsgBuf;
/*
FormatMessage( DWORD dwFlags,
LPCVOID lpSource,
DWORD dwMessageId,
DWORD dwLanguageId,
LPTSTR lpBuffer,
DWORD nSize,
va_list *Arguments )
*/
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS
, NULL
, dwError
, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)
, (LPTSTR)&lpMsgBuf
, 0
, NULL
);
CString str;
str.Format(_T("%s"), lpMsgBuf);
LocalFree(lpMsgBuf);
return str;
}
int SHMSiseAPI::CreateSharedMemory(LPCSTR szMapName,LPCSTR szMutexName,int nMaxItems)
{
int rc = 0;
BOOL fInit;
HANDLE hMapObject = NULL; // handle to file mapping
int nSize = 0;
SHMSISEITEM *pRootItem = NULL, *pItem = NULL;
#ifndef _DEBUG
SHMSISEITEM *pItemList[4300] = { 0, };
#endif
LPSHMSISEITEM lpNeTraceData = NULL;
m_siseconf.nTotalMapSize = sizeof(SHMSISEHEADER) + nSize;
if (nMaxItems <= 0)
nMaxItems = m_siseconf.nMaxItems;
nSize = sizeof(SHMSISEITEM) * nMaxItems;
//static LPVOID lpvMem = NULL; // pointer to shared memory
SetLastError(ERROR_SUCCESS);
//Create a named file mapping object.
//use paging file,no security attributes,RW attr,size:high 32-bits&low 32-bits,name of map object
hMapObject = CreateFileMapping((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE, 0,
m_siseconf.nTotalMapSize, szMapName);// SHMSISE_TRACEMAP);
if (hMapObject == NULL)
return -1;
m_siseconf.hFileMap = hMapObject;
DWORD dwError = GetLastError();
// The first process to attach initializes memory.
m_siseconf.bFirstCreated = fInit = (dwError != ERROR_ALREADY_EXISTS);
//Get a pointer to the file-mapped shared memory.
//m_mapping = MapViewOfFile(hMapObject,FILE_MAP_READ|FILE_MAP_WRITE,0,0,0);//default: map entire file
m_siseconf.mapping = MapViewOfFile(hMapObject, FILE_MAP_READ | FILE_MAP_WRITE,
0, 0, m_siseconf.nTotalMapSize);//default: map entire file
if (m_siseconf.mapping == NULL)
return -2;
m_siseconf.hMutex = CreateMutex(NULL, FALSE, szMutexName);
if (GetLastError() == ERROR_ALREADY_EXISTS) {
rc = -3;
}
// Initialize memory if this is the first process.
if (fInit)
memset((LPVOID)m_siseconf.mapping, 0, m_siseconf.nTotalMapSize);
else
rc = -4;
SHMSISEHEADER *pmapheader;
pmapheader = (LPSHMSISEHEADER)m_siseconf.mapping;
pmapheader->offset2read = sizeof(SHMSISEHEADER);
pmapheader->offset2write = sizeof(SHMSISEHEADER);
pmapheader->mapsize = m_siseconf.nTotalMapSize;
SYSTEMTIME curtime;
GetLocalTime(&curtime);
pmapheader->lasttime = HHMMSS2INT(curtime.wHour, curtime.wMinute, curtime.wSecond);
int nItemSize = sizeof(SHMSISEITEM);
#ifndef _DEBUG
pRootItem = (SHMSISEITEM*)(LPVOID)(pmapheader + sizeof(SHMSISEHEADER));
for (int ii = 0; ii < m_siseconf.nMaxItems; ii++) {
pItem = (SHMSISEITEM*)&pRootItem[ii];
pItem->index = ii;
//pItem += sizeof(SHMSISEITEM);
pItemList[ii] = pItem;
}
#endif
return rc;//0 = 성공
}
int SHMSiseAPI::DestroySharedMemory()
{
BOOL fIgnore;
if(m_siseconf.mapping != NULL)
fIgnore = UnmapViewOfFile(m_siseconf.mapping);// Unmap shared memory from the process's address space.
if (m_siseconf.hFileMap)
fIgnore = CloseHandle(m_siseconf.hFileMap);// Close the process's handle to the file-mapping object.
if(m_siseconf.hMutex)
CloseHandle(m_siseconf.hMutex);
m_siseconf.mapping = NULL;
m_siseconf.hFileMap = NULL;
m_siseconf.hMutex = NULL;
return TRUE;
}
LPSHMSISEHEADER SHMSiseAPI::GetSHMHeader()
{
SHMSISEHEADER* pmapheader = NULL;
WaitForSingleObject(m_siseconf.hMutex, INFINITE); //뮤텍스의 진입점
pmapheader = (LPSHMSISEHEADER)m_siseconf.mapping;
ReleaseMutex(m_siseconf.hMutex);
return pmapheader;
}
int SHMSiseAPI::GetSHMHeader(LPSHMSISEHEADER lpHeader)
{
int rc = -1;
LPVOID lpSharedData;
SHMSISEHEADER *pmapheader;
WaitForSingleObject(m_siseconf.hMutex, INFINITE); //뮤텍스의 진입점 ReleaseMutex와 pair짝
pmapheader = (LPSHMSISEHEADER)m_siseconf.mapping;
if (pmapheader) {
memcpy(lpHeader, pmapheader, sizeof(SHMSISEHEADER));
rc = 0;
}
ReleaseMutex(m_siseconf.hMutex);
return rc;
}
int SHMSiseAPI::GetSHMData(int index,LPSHMSISEITEM lpItem, int unmapeverytime)
{
int rc = 0;
//LPVOID lpSharedData;
SHMSISEHEADER *pmapheader;
SHMSISEITEM* pRootItem = NULL, * pItem = NULL;
//뮤텍스를 걸어서 프로세스간(쓰레드는 기본) 공유메모리 상호배제 역할을 한다!
//크리티컬 세션은 한 프로세스 내에서 쓰레드 끼리 동기화 위한 것이고,
//프로세스끼리 동기화는 안된다.
WaitForSingleObject(m_siseconf.hMutex, INFINITE); //뮤텍스의 진입점
pmapheader = (LPSHMSISEHEADER)m_siseconf.mapping;
if (pmapheader == NULL) {
rc = -1;
goto exit_now;
}
pmapheader->lastreadindex = index;
#if 0
if (pmapheader->offset2read >= pmapheader->mapsize) {
pmapheader->offset2read = sizeof(SHMSISEHEADER);
}
if (pmapheader->readcount >= pmapheader->writecount) {
rc = 0;
goto exit_now;
}
if (pmapheader->offset2write < sizeof(SHMSISEHEADER) ||
pmapheader->offset2read == pmapheader->offset2write)
{
rc = 0;
pmapheader->offset2write = sizeof(SHMSISEHEADER);
pmapheader->offset2read = pmapheader->offset2write;
goto exit_now;
}
#endif
#if 0
DWORD dwFileSize = GetFileSize(m_hFileMap, NULL); //무용지물
MEMORY_BASIC_INFORMATION mbi = { 0 };//페이지 블록크기임(실데이타 크기아님)
VirtualQueryEx(GetCurrentProcess(), m_mapping, &mbi, sizeof(mbi));
#endif
//lpSharedData = (char*)m_siseconf.mapping + pmapheader->offset2read;
pRootItem = (SHMSISEITEM*)(LPVOID)(pmapheader + sizeof(SHMSISEHEADER));
pItem = (SHMSISEITEM*)&pRootItem[index];
*lpItem = *pItem;
if (pmapheader->rollback) {
pmapheader->rollback = 0;
}
pmapheader->readcount++;
if (unmapeverytime) {
SHUnMap();
}
exit_now:
ReleaseMutex(m_siseconf.hMutex);
return rc;
}
//이미생성된 공유메모리에 접근한다.
int SHMSiseAPI::AttachSHM()
{
int rc = 0;
if (m_siseconf.hFileMap == NULL)
m_siseconf.hFileMap = OpenFileMapping(FILE_MAP_READ | FILE_MAP_WRITE, FALSE, SHMSISE_MAPNAME);// SHMSISE_TRACEMAP);
if (m_siseconf.hFileMap == NULL)
return -2;
if (m_siseconf.hMutex == NULL) {
m_siseconf.hMutex = CreateMutex(NULL, TRUE, SHMSISE_MUTEXNAME);// "Gorang-Mutex");
if (GetLastError() == ERROR_ALREADY_EXISTS) {
int aa = 0;
aa = 1;
}
}
if (m_siseconf.hMutex == NULL)
return -3;
if (m_siseconf.mapping == NULL) {
m_siseconf.mapping = MapViewOfFile(m_siseconf.hFileMap,
FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, m_siseconf.nTotalMapSize);
}
if (m_siseconf.mapping == NULL)
return -4;
return rc;
}
//20210403
int SHMSiseAPI::AddSHMData(LPSHMSISEITEM lpItem, int unmapeverytime)
{
int rc = 0;
SHMSISEITEM* pRootItem = NULL, * pItem = NULL;
SHMSISEITEM* pItemList[4800] = { 0, };
SHMSISEHEADER* pmapheader;
LPVOID lpSharedData;
int attach_error = AttachSHM();
if (attach_error)
return -1;
if (m_siseconf.nMaxItems <= 0)
return -2;
WaitForSingleObject(m_siseconf.hMutex, INFINITE); //뮤텍스락(진입점)
pmapheader = (LPSHMSISEHEADER)m_siseconf.mapping;
int index = pmapheader->readcount++;
//if (pmapheader->offset2write >= pmapheader->mapsize) {
// pmapheader->offset2write = sizeof(SHMSISEHEADER);
// pmapheader->rollback = 1;
//}
//lpSharedData = (char*)m_siseconf.mapping + pmapheader->offset2write;
//memcpy(lpSharedData, lpData, sizeof(SHMSISEITEM));
//pmapheader->offset2write += sizeof(SHMSISEITEM);
//pmapheader->writecount++;
pRootItem = (SHMSISEITEM*)(LPVOID)(pmapheader + sizeof(SHMSISEHEADER));
pItem = (SHMSISEITEM*)&pRootItem[index];
*pItem = *lpItem;
if (unmapeverytime) {
SHUnMap();
}
exit_now:
ReleaseMutex(m_siseconf.hMutex); //뮤텍스 언락
return index;
}
//20210403
int SHMSiseAPI::SetSHMData(int index,LPSHMSISEITEM lpItem, int unmapeverytime)
{
int rc = 0;
int nSize = sizeof(SHMSISEITEM) * m_siseconf.nMaxItems;
SHMSISEITEM* pRootItem = NULL, * pItem = NULL;
SHMSISEITEM* pItemList[4800] = { 0, };
SHMSISEHEADER* pmapheader;
LPVOID lpSharedData;
int attach_error = AttachSHM();
if (attach_error)
return -1;
if (m_siseconf.nMaxItems <= 0 || index >= m_siseconf.nMaxItems)
return -2;
pmapheader = GetSHMHeader();
if (!pmapheader)
return -3;
if (index >= pmapheader->readcount)
return -4;
WaitForSingleObject(m_siseconf.hMutex, INFINITE); //뮤텍스락(진입점)
pmapheader = (LPSHMSISEHEADER)m_siseconf.mapping;
//if (pmapheader->offset2write >= pmapheader->mapsize) {
// pmapheader->offset2write = sizeof(SHMSISEHEADER);
// pmapheader->rollback = 1;
//}
//lpSharedData = (char*)m_siseconf.mapping + pmapheader->offset2write;
//memcpy(lpSharedData, lpData, sizeof(SHMSISEITEM));
//pmapheader->offset2write += sizeof(SHMSISEITEM);
//pmapheader->writecount++;
pRootItem = (SHMSISEITEM*)(LPVOID)(pmapheader + sizeof(SHMSISEHEADER));
pItem = (SHMSISEITEM*)&pRootItem[index];
*pItem = *lpItem;
//pItem += sizeof(SHMSISEITEM);
if (unmapeverytime) {
SHUnMap();
}
exit_now:
ReleaseMutex(m_siseconf.hMutex); //뮤텍스 언락
return index;
}
void SHMSiseAPI::SHUnMap()
{
if (m_siseconf.mapping)
BOOL flag = UnmapViewOfFile(m_siseconf.mapping);
if (m_siseconf.hFileMap)
CloseHandle(m_siseconf.hFileMap);
m_siseconf.mapping = NULL;
m_siseconf.hFileMap = NULL;
}
long SHMSiseAPI::SetSiseCmd(int index, LPSHMSISEITEM lpItem, LPARAM param)
{
SHMSISEITEM tData = { 0, };
if (m_hSHMSiseWnd == NULL)
m_hSHMSiseWnd = ::FindWindow(NULL, SHMSISE_WINDOWCLASSNAME);
else if(!IsWindow(m_hSHMSiseWnd)){
m_hSHMSiseWnd = ::FindWindow(NULL, SHMSISE_WINDOWCLASSNAME);
}
if (m_hSHMSiseWnd == NULL)
{
DWORD dwerr = GetLastError();
return 0;
}
tData.param = param;
SetSHMData(index, lpItem);
//::SendMessage(m_hSHMSiseWnd, WM_BATGORANG, (WPARAM)SHMSISE_SETCMD, (LPARAM)0L);
////::PostMessage(m_hSHMSiseWnd, WM_BATGORANG, (WPARAM)SHMSISE_SETCMD, (LPARAM)0L);
//if (!strnicmp(tData.szCmd, SHMSISE_CMD_DETACH, 6)) {
// SHUnMap();
//}
return 1;
}
void SHMSiseAPI::GoRangLog(LPCSTR szkeyname, LPCSTR szbuff, LPARAM hWnd)
{
SHMSISEITEM tData = { 0, };
if (m_hSHMSiseWnd == NULL)
m_hSHMSiseWnd = ::FindWindow(NULL, SHMSISE_WINDOWCLASSNAME);
else if (!IsWindow(m_hSHMSiseWnd)) {
m_hSHMSiseWnd = ::FindWindow(NULL, SHMSISE_WINDOWCLASSNAME);
}
if (m_hSHMSiseWnd == NULL)
{
DWORD dwerr = GetLastError();
return;
}
#if 0
strncpy(tData.szKeyName,szkeyname,sizeof(tData.szKeyName));
strncpy(tData.szParam,szbuff,sizeof(tData.szParam));
tData.param2 = hWnd;
SetSHMData(SHMSISE_MAPNAME, SHMSISE_MUTEXNAME ,&tData);
////Set Shared Memory of NETracer
////Nofity to NETracer Window
////::PostMessage(m_hSHMSiseWnd, WM_BATGORANG, (WPARAM)SHMSISE_SETDATA, (LPARAM)0L);
//::SendMessage(m_hSHMSiseWnd, WM_BATGORANG, (WPARAM)SHMSISE_SETDATA, (LPARAM)0L);
#endif
}
|
cs |
한글텍스트편집기(Text Editor) 국산 두루에디트로 코딩,한글공부
한글텍스트편집기(Text Editor)
무료에디터(free)
durumul.com
'TechTree(IT|Dev|SW) > C | C++ | VC++' 카테고리의 다른 글
[국내이슈] 증권사 API조회제한 탈피v2.0 (0) | 2025.09.22 |
---|---|
[소스방출] AceKit (0) | 2025.08.09 |
카톡같은 메신저(네이트온등) 소스 공개예정 (0) | 2025.07.31 |
윈도우즈 스킨라이브러리(Window Skin Library) (0) | 2025.07.12 |
VC++ Project Converting 2019 to VC++2022 Community (0) | 2025.06.27 |