임계영역 설정 Ctirical Section

Programming/C,CPP,CS 2016. 11. 7. 11:07 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

임계영역 설정 Ctirical Section








CreateMutex
Critical Section Objects
DeleteCriticalSection
EnterCriticalSection
InitializeCriticalSectionAndSpinCount
LeaveCriticalSection
Synchronization Functions
TryEnterCriticalSection






void WINAPI InitializeCriticalSection( LPCRITICAL_SECTION lpCriticalSection );

void WINAPI DeleteCriticalSection( LPCRITICAL_SECTION lpCriticalSection );

void WINAPI EnterCriticalSection( LPCRITICAL_SECTION lpCriticalSection );

void WINAPI LeaveCriticalSection( LPCRITICAL_SECTION lpCriticalSection );

BOOL WINAPI TryEnterCriticalSection( LPCRITICAL_SECTION lpCriticalSection );








1. 임계영역 변수선언

CRITICAL_SECTION cs;


2. 초기화

InitializeCriticalSection( &cs );


3. 사용


임계영역 진입

EnterCriticalSection( &cs );


임계영역 탈출

LeaveCriticalSection( &cs );


4. 삭제

DeleteCriticalSection( &cs );






Jsoncpp 주의 사항

Programming/C,CPP,CS 2016. 11. 1. 12:05 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.





Json::Value  retrieve_list= NULL;



둘은 다르다.


Json::Value  retrieve_list;

'Programming > C,CPP,CS' 카테고리의 다른 글

[jsoncpp] getList Names  (0) 2017.02.06
임계영역 설정 Ctirical Section  (0) 2016.11.07
OpenSSL x86 Build  (0) 2016.10.28
pjproject-2.5.5  (0) 2016.10.14
pjsip Building for Microsoft Windows  (1) 2016.10.12

MFC x64 ADO msado15.dll

Programming/MFC 2016. 10. 28. 18:05 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

MFC 에서


x64 환경에서


ADO msado15.dll 를 사용하고 싶었다.







#import "c:\Program Files\Common Files\System\ADO\msado15.dll" rename("EOF", "EndOfFile")




1. tlh 파일 추출하기

#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "adoEOF") rename("BOF", "adoBOF")

 

구문을 그대로 두고 컴파일을 진행 한다.

 

컴파일이 성공하면 Object 파일들이 생성 되는 Debug 폴더 또는 Release 폴더로 가보자.

 

#import 처리기가 하는 역할이 dll 에서 tlh 를 추출하여 헤더 파일에 그대로 붙여 넣는 작업을 해주는 역할이기 때문에 Debug 폴더나 Release 폴더에 가보면 다음과 같은 파일이 보일것이다.

 

msado15.tlh

msado15.tli

 

각각 용량은 167KB, 146KB 정도로 꽤 큰편이다.

 

위 두파일을 복사해서 #import 구문을 사용했던 소스와 동일한 경로에 붙여넣기 한다.

 

#import ".........

코드를 다음과 같이 변경한다.

#include "msado15.tlh"

 

이렇게 하면 #import 로 추출된 tlh 파일을 include 하는 구조이기 때문에 동일한 역할을 수행한다.

 

/MP 스위치를 켜고 빌드 -> 솔루션 다시 빌드 를 선택하여 컴파일을 진행해 보면 또 컴파일 실패가 된다.

 

msado15.tlh(5025): fatal error C1083: 포함 파일을 열 수 없습니다. "....\msado15.tli': No such file or directory"

 

하지만 컴파일 오류 내용을 잘 보면 포함 파일을 열 수 없습니다. 라고 나오는것을 알 수 있기 때문에 tlh 파일 안에서 msado15.tli 파일을 찾을 수 없다 라는 오류를 알 수 있다.

 

msado15.tlh 파일을 메모장등의 에디터로 열어보자.

 

편집 -> 찾기 메뉴를 이용하요 .tli 를 찾아 보면 거의 끝부분에서 다음 줄을 찾을 수 있다.

 

//

// Wrapper method implementations

//

#include ".......\debug\msado15.tli"

 

 

앞 경로는 개인정보 보호상 삭제..

 

Full Path 로 된 #include  문을 찾을 수 있는데 바로 이 부분의 경로가 Debug 폴더까지 들어가 있어서 파일을 찾을 수 없는것으로 나오는것이다.

 

경로를 #import 문이 있는 소스의 경로로 수정한 다음 다시 한번 컴파일 해보면

 

제대로 컴파일 되는것을 확인 할 수 있다.

 

x64 ADO import

Programming/MFC 2016. 10. 28. 16:33 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

ERROR


error C2813: /MP를 지정하면 #import를 사용할 수 없습니다. 

error C2653: 'ADODB' : 클래스 또는 네임스페이스 이름이 아닙니다.


x64 ADO import



ADO 바이너리가 두 군데 나뉘어 배포된다. x32 바이너리는 C:\Program Files (x86)\Common Files\System\ado\에 있고, x64 바이너리는 C:\Program Files\Common Files\System\ado\에 있다. 그러니 ADO를 import할 땐 이런 식으로 하면 된다.




#import "C:\Program Files\Common Files\System\ado\msado15.dll"





#import "C:\Program Files (x86)\Common Files\System\ado\msado15.dll"





#import "libid:EF53050B-882E-4776-B643-EDA472E8E3F2"






x32 x64 상관 없이 돌리려면




#if defined(WIN64)

#import "C:\Program Files\Common Files\System\ado\msado15.dll"

#else

#import "libid:EF53050B-882E-4776-B643-EDA472E8E3F2"

#endif




참조 : https://andromedarabbit.net/wp/unhappy_when_importing_x64_ado/





OpenSSL x86 Build

Programming/C,CPP,CS 2016. 10. 28. 15:39 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

OpenSSL x86 Build


Windows7 64bit


Visual Studio 2013






1. download openssl 

openssl-1.0.2j.tar.gz


http://openssl.org/source/





extract to D:\openssl-1.0.2j






2. download/install ActivePerl for Win64 


http://www.activestate.com/activeperl/downloads





C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts


execute VS2013 x86 네이티브 도구 명령 프롬프트, VS2013 x86 Native Tools Command Prompt





change directory to D:\openssl-1.0.2j


3. Setting Target openssldir


perl Configure VC-WIN32 no-idea no-mdc2 no-rc5 --prefix=d:\openssl32bit no-shared no-asm threads



no-asm 옵션을 추가하지 않으면 nasm 을 설치하여야 하므로.....


no-idea, no-mdc2, no-rc5 옵션은 특허가 포함되어있는 모듈이므로


꼭 필요하지 않다면 사용하지 않는 것이 좋습니다.



참고 : http://greenfishblog.tistory.com/81



사진은 64비트 버전의 것을 복붙을 하여서 명령어가 다릅니다. 참고바랍니다.








4. Setting complie enviroment


ms\do_ms








5. Complie


nmake -f ms\ntdll.mak install






설치 명령어는 사실


openssl 폴더에 있는



INSTALL.W64 , INSTALL.W32 만 따라하셔도 충분히 가능합니다.








'Programming > C,CPP,CS' 카테고리의 다른 글

임계영역 설정 Ctirical Section  (0) 2016.11.07
Jsoncpp 주의 사항  (0) 2016.11.01
pjproject-2.5.5  (0) 2016.10.14
pjsip Building for Microsoft Windows  (1) 2016.10.12
oRTP  (0) 2016.10.11
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Java SocketServer control Image, DBConnect, String




package com.tistory.tansanc;

import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

import javax.imageio.ImageIO;

class DBConnect {
	ResultSet rs = null;
	Connection conn = null;
	Statement stmt = null;
	public DBConnect() {
		try {
			String url = "jdbc:sqlserver://192.168.10.17:1433;DatabaseName=MSSQLSERVER";
			
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			conn = DriverManager.getConnection(url, "sa", "1234");
			stmt = conn.createStatement();
			

		} catch (Exception e) {

		}
	}

	public void finalize() {
		try {
			rs.close();
			stmt.close();
			conn.close();
		} catch (Exception e) {

		}
	}
}

class PerClientThread extends Thread {
	Socket s;
	static ArrayList socketArray = new ArrayList();
	static DBConnect dbc;
	
	public PerClientThread()
	{
		
	}
	@Override
	public void run() {
		// TODO Auto-generated method stub

		socketArray.add(s);
		BufferedReader br;

		
		try {
			br = new BufferedReader(new InputStreamReader(s.getInputStream()));
			String temp;
			while ((temp = br.readLine()) != null) {
				// DB Query
				if (temp.startsWith("select")) {
					
					try {
						dbc.rs = dbc.stmt.executeQuery("SELECT * FROM [dbo].[TESTDB]");

						while (dbc.rs.next()) {
							String field1 = dbc.rs.getString("Date");
							String field2 = dbc.rs.getString("FileName");
							System.out.println(field1);
							System.out.println(field2);

							java.sql.Blob blb = dbc.rs.getBlob("Image");
							byte[] imagebytes = blb.getBytes(0, (int) blb.length());
							BufferedImage theImage = ImageIO.read(new ByteArrayInputStream(imagebytes));

						}
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					temp = "SQL:" + temp;
					System.out.println(temp);
				}
				// Arduino
				else if (temp.startsWith("insert"))
				{
					
				}
				// Arduino
				else if (temp.startsWith("image"))
				{

			        int size = Integer.parseInt(br.readLine());
			        
			        DataInputStream inputStream = new DataInputStream(s.getInputStream());
			        
			        byte[] imageAr = new byte[size];
			        inputStream.read(imageAr, 0, size);

			        BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageAr));

			        System.out.println("Received " + image.getHeight() + "x" + image.getWidth() + ": " + System.currentTimeMillis());
			        ImageIO.write(image, "png", new File("C:\\test2.png"));


				}
				// Arduino
				else if (temp.startsWith("to"))
				{
					
				}
				System.out.print(s.getInetAddress() + " : ");
				System.out.println(temp);
				for (int i = 0; i < socketArray.size(); i++) {
					PrintWriter os = new PrintWriter(socketArray.get(i).getOutputStream(), true);
					os.print(s.getInetAddress() + " : ");
					os.println(temp);
				}
			}

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		super.run();
	}
}

public class Server {
	public static void main(String[] args) throws Exception {
 
		System.out.println("Server Side");
		ServerSocket ss = new ServerSocket(33333);
		Socket s;
		while (true) {
			s = ss.accept();
			PerClientThread pct = new PerClientThread();
			pct.s = s;
			pct.dbc = new DBConnect();
			pct.start();
		}

	}
}










Client.java
package com.tistory.tansanc;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;

class MyFrame extends JFrame {
	public static JTextArea textArea;
	JTextField textField;
	PrintWriter out;
	Socket s;

	public MyFrame() {
		textArea = new JTextArea();
		textField = new JTextField();
		add(BorderLayout.CENTER, textArea);
		add(BorderLayout.SOUTH, textField);
		textField.addActionListener(new FieldListener());
		setSize(300, 200);
		setTitle("채팅프로그램 Client");
		setVisible(true);
		// GUI를 설계한다.
	}

	class FieldListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			if (textField.getText().compareTo("image") == 0) {

				BufferedImage image;
				ByteArrayOutputStream byteArrayOutputStream = null;
				DataOutputStream os = null;
				try {
					image = ImageIO.read(new File("C:\\test.png"));
					byteArrayOutputStream = new ByteArrayOutputStream();
					ImageIO.write(image, "png", byteArrayOutputStream);
					os = new DataOutputStream(s.getOutputStream());
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
				try {
					int size = byteArrayOutputStream.size();
					out.println("image");
					out.println(size);
					os.write(byteArrayOutputStream.toByteArray());
					os.flush();
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}

			} else {
				out.println(textField.getText());
				textField.setText("");
			}
			// 메세지 보내기
		}
	}
}

class SendThread extends Thread {
	PrintWriter out;

	public SendThread(PrintWriter out) {
		this.out = out;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		super.run();
	}
}

class RecvThread extends Thread {
	BufferedReader in;

	public RecvThread(BufferedReader in) {
		this.in = in;
	}

	@Override
	public void run() {
		String temp;
		try {
			while ((temp = in.readLine()) != null) {

				MyFrame.textArea.setText(MyFrame.textArea.getText() + "\n" + temp);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

class ClientModule {
	MyFrame mFrame;
	SendThread mSendThread;
	RecvThread mRecvThread;
	Socket s;

	// 서버에 패킷을 보내는 Thread
	// 서버로부터 패킷을 받는 Thread
	public ClientModule() // 준비
	{

		try {
			s = new Socket("192.168.10.17", 33333);
			PrintWriter out = new PrintWriter(s.getOutputStream(), true);
			BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
			mFrame = new MyFrame(); // GUI 객체
			mFrame.s = s;
			mFrame.out = out;
			mSendThread = new SendThread(out);
			mRecvThread = new RecvThread(in);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	void start() // 시작
	{
		mSendThread.start();
		mRecvThread.start();
	}
}

public class Client {
	public static void main(String[] args) {
		ClientModule cm = new ClientModule();
		// 초기화 작업
		cm.start();
		// Thread.start();
	}
}





MSSQL 테이블명, 컬럼명 검색

Programming/MFC 2016. 10. 27. 16:54 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

MSSQL 테이블명, 컬럼명 검색








-- 테이블명 검색

SELECT * FROM information_schema.TABLE_CONSTRAINTS WHERE TABLE_NAME = '테이블명'





-- 컬럼명 검색

SELECT * FROM information_schema.COLUMNS WHERE COLUMN_NAME = '컬럼명'





-- PK 검색

SELECT * FROM information_schema.KEY_COLUMN_USAGE

'Programming > MFC' 카테고리의 다른 글

MFC x64 ADO msado15.dll  (0) 2016.10.28
x64 ADO import  (0) 2016.10.28
Visual Studio 2013 클래스뷰, 리소스뷰 가 보이지 않을때  (0) 2016.10.27
CEdit control의 font 바꾸기  (0) 2016.10.25
CTextProgressCtrl hide Edge  (0) 2016.10.25
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Visual Studio 2013 클래스뷰, 리소스뷰 가 보이지 않을때













Visual Studio 종료시 에러 메세지의 지시대로


Microsoft SQL Server Compact 4.0 을 설치하면 정상적으로 작동된다.

'Programming > MFC' 카테고리의 다른 글

x64 ADO import  (0) 2016.10.28
MSSQL 테이블명, 컬럼명 검색  (0) 2016.10.27
CEdit control의 font 바꾸기  (0) 2016.10.25
CTextProgressCtrl hide Edge  (0) 2016.10.25
MFC CWnd Control Border Color Change  (0) 2016.10.20

Redis Client Connect Test

Programming/Redis 2016. 10. 26. 11:52 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Redis Client Connect Test





CLIENT LIST

The CLIENT LIST command returns information and statistics about the client connections server in a mostly human readable format.

Return value

Bulk string reply: a unique string, formatted as follows:

  • One client connection per line (separated by LF)
  • Each line is composed of a succession of property=value fields separated by a space character.

Here is the meaning of the fields:

  • id: an unique 64-bit client ID (introduced in Redis 2.8.12).
  • addr: address/port of the client
  • fd: file descriptor corresponding to the socket
  • age: total duration of the connection in seconds
  • idle: idle time of the connection in seconds
  • flags: client flags (see below)
  • db: current database ID
  • sub: number of channel subscriptions
  • psub: number of pattern matching subscriptions
  • multi: number of commands in a MULTI/EXEC context
  • qbuf: query buffer length (0 means no query pending)
  • qbuf-free: free space of the query buffer (0 means the buffer is full)
  • obl: output buffer length
  • oll: output list length (replies are queued in this list when the buffer is full)
  • omem: output buffer memory usage
  • events: file descriptor events (see below)
  • cmd: last command played

The client flags can be a combination of:

O: the client is a slave in MONITOR mode
S: the client is a normal slave server
M: the client is a master
x: the client is in a MULTI/EXEC context
b: the client is waiting in a blocking operation
i: the client is waiting for a VM I/O (deprecated)
d: a watched keys has been modified - EXEC will fail
c: connection to be closed after writing entire reply
u: the client is unblocked
U: the client is connected via a Unix domain socket
r: the client is in readonly mode against a cluster node
A: connection to be closed ASAP
N: no specific flag set

The file descriptor events can be:

r: the client socket is readable (event loop)
w: the client socket is writable (event loop)


'Programming > Redis' 카테고리의 다른 글

Hiredis SMEMBERS 활용  (0) 2017.01.24
Hiredis Subscribe/Publish with CWinThread  (0) 2016.10.05
How to use Pub/sub with hiredis in C++?  (0) 2016.09.29
hiredis fatal error C1853:  (0) 2016.09.29
hiredis MFC import Visual Studio 2013  (0) 2016.09.28

MFCGridCtrl OnEraseBkgnd ScrollBar

Programming/MFCGridCtrl 2016. 10. 26. 11:34 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

MFCGridCtrl OnEraseBkgnd ScrollBar Redraw








MFC Dialog Color 를 바꾸기 위해


OnEraseBkgnd 을 오버라이딩하여 사용하면


Dialog 를 새로 그리게 되는데


이때 CGridCtrl 의 스크롤바 영역도 같이 새로 그리게 된다.








그래서 스크롤바가 존재하지만 안보이는 경우가 발생한다.


그럴때는 OnEraseBkgnd 에서 Dialog 를 새로그린 다음



m_Grid.SetRedraw(true, true);






Redraw 를 하면


스크롤 바를 새로 그린다.