dll만든 후 헤더 구조체에 데이터가 안들어갑니다.

l595659의 이미지

기존에 만든 코드를 dll/lib 를 만들어서 MFC에서 테스트 해봤는데
헤더 안에 있는 구조체에 데이터가 들어가질 않네요
컴파일은 되는데 해당 인자에 데이터가 안들어가다보니까 이후 기능이 작동하지 않더라구요

헤더는 아래와 같이 해놨습니다

#ifdef CREATEDLL_EXPORTS
#define SERVERDLL3_DECLSPEC __declspec(dllexport)
#else
#define SERVERDLL3_DECLSPEC __declspec(dllimport)
#endif
 
#define _AFXDLL
#include "framework.h"
#include <vector>
#include <tchar.h>
#include <ctime>
#include <winsock.h>
#include <algorithm>
#include <string>
#include <stdlib.h> 
#pragma warning(disable: 4996)
 
#define MAX_CLIENT_NUM 255
#define BUFSIZE 1024
 
struct SocketComm {
	SOCKET server_sock;					/*서버 소켓*/
	SOCKADDR_IN serv_socketAddr;		/*서버 소켓 정보 구조체*/
 
	SOCKET clnt_sock;					/*클라이언트 소켓*/
	SOCKADDR_IN clnt_socketAddr;		/*서버 소켓 정보 구조체*/
 
	std::vector<SOCKET> client_list;			/*TCP 다중 클라이언트용 벡터*/
	std::vector<SOCKADDR_IN> udpClient_list;	/*UDP 다중 클라이언트용 벡터*/
	int index;							/*m_user_list 구조체 활용하기 위한 index*/
 
	char key[BUFSIZE] = "ufmsystems";
	int keycount;
	char encrypt[BUFSIZE];
	int encryptsize;
	char datasize[20];
	char decrypt[BUFSIZE];
}; extern SocketComm m_socket_comm;
 
SERVERDLL3_DECLSPEC int winsockInit();
SERVERDLL3_DECLSPEC void serverSocket(int domain, int type, int protocol);
class TCPServer
{
public:
	SERVERDLL3_DECLSPEC TCPServer();
	SERVERDLL3_DECLSPEC ~TCPServer();
	//---------------------변수-------------------------//
	const char* slniPath;				/*ini 위치*/
	TCHAR KeyInfo[MAX_PATH];		/*Key 정보가 들어갈 변수*/
	int ServerPort_Num;				/*ServerPort 정보가 들어갈 변수*/
	int ClientCount_Num;			/*ClientCount_Num 정보가 들어갈 변수*/
	int size = sizeof(SOCKADDR_IN);	/*SOCKADDR_IN 구조체 길이*/
	char readbuffer[BUFSIZE];		/*Recv 정보를 넣을 변수*/
	int recvsize;					/*Recv 리턴값을 받아올 변수*/
	char serverText;				/*Send할때 사용할 포맷 (출력용)*/
	char ConnTime[BUFSIZE];		/*접속한 시간*/
	char CloseTime[BUFSIZE]; 		/*종료한 시간*/
	char RecvTime[BUFSIZE];		/*수신한 시간*/
 
	char DisConnectInfo_str[BUFSIZE];
	char ConnectInfo_str[BUFSIZE];
	//-----------------------함수----------------------------//
	SERVERDLL3_DECLSPEC void IniInfo(const char* iniLocation, const char* Section, const char* Key); //ini 파일 내용 가져오기
	SERVERDLL3_DECLSPEC void BeforeAccept(); //bind, listen
	SERVERDLL3_DECLSPEC int ClntAccept(); //accept
	SERVERDLL3_DECLSPEC void MultiClient(); //vector pushback
	SERVERDLL3_DECLSPEC void ServRecv(SOCKET clntsock);
	SERVERDLL3_DECLSPEC void ServSend();
	SERVERDLL3_DECLSPEC void EraseVec(SOCKET clntsock);
	SERVERDLL3_DECLSPEC void ServCurSelSend(int num, char buf[], int bufsize);
	//------------------------------------------------------//
 
};

이렇게 헤더를 짜놨는데 cpp파일에서 Accept 후에 클라이언트 소켓 정보를 구조체에 넣어서
다음 쓰레드 진행할 때 해당 값을 가져오게
_beginthread(TCPSendRecvComm, NULL, (void*)m_socket_comm.clnt_sock);

이렇게 해놨었는데 clnt_sock 값이 0이다 보니까 recv, send등이 안됩니다...

라스코니의 이미지

기존에 코드를 그대로 dll/lib로 옮길수 있다고 보지 마시고 이렇게 한번 해보시죠.

// lib/dll code 간략 구조
 
// 기능 관련 정의
class xxx {
}
 
// 외부로 노출되는 API 정의
__declspec class xxx* Init() {
   class xxx *tmp = new class xxx();
 
   if(tmp)
       return tmp;
   else
       return NULL;
}
 
dll을 부르는 쪽
#include <classXXX.hpp>
link dll;
class xxx *myWork = _init();
// do something...
myWork->SetupTCP();
l595659의 이미지

사실상 dll을 위해서 새로 짜던가 해야 하는거네요? 어느정도 바꿔서

라스코니의 이미지

인터넷에서 목적과 비슷한 예제부터 해보시는 걸 추천합니다. 처음 시도시 기본 골격이 제일 중요합니다. 그래서 예제부터 시작하는 것이 제일 좋습니다.

구글에서 검색해 보니 첫번째로 이게(https://luckygg.tistory.com/281) 나오네요.
처음에는 이것저것 고민하지 마시고 다른 선각자(?)가 닦아준 길을 배우면서 익혀야 하고 어느정도 익숙해 지고 난 후 그때서야 이것저것 해보시는게 좋습니다.

l595659의 이미지

그냥 부딪쳐 보려고 했어서 더 헤맸던거 같네요 정말 감사합니다 예제 따라해보고 생각해봐야겠어요!

l595659의 이미지

따라해서 class를 dll로 내보내고 사용까지 해봤는데 구조체부분에 쓰려니까 영 감이 안잡히네요..

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.