C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[20779] Re:dll에서 전역변수가 작동을 안 하네요??
얼큰 [cityguy2] 2530 읽음    2002-08-13 10:34
안녕하세요 얼큰이 이성현입니다.

뭐 저도 초보라.. 정확한 답변이 될지 모르겠네요..

DLL을 사용할때는 프로그램에 DLL에 해당하는 헤더 파일을 인클루드 해서 사용합니다.

아래에 보면 사용하시는 DLL의 헤더파일에 변수가 선언되지 않았는데요..

NullRenderDll.h 이 파일을 include해서 사용할때

#include<NullRanderDll.h>
밑에
extern bool Volume__OnOff;<-----------------------------변수가 작동을 안 함..
extern float TOTAL;//대입값<-----------------------------변수가 작동을 안 함..
extern float m_fVolumePos;<-----------------------------변수가 작동을 안 함..
extern float m_fBalancePos;<-----------------------------변수가 작동을 안 함..
으로 선언 하시고 사용하세요..

하나 더 말씀 드리면.
변수에 static bool Valum__OnOff; 라고 선언하면
이 변수는 다른 파일에서는 사용할 수 없습니다. 그 파일에서만 사용가능합니다.

답이 될런지??? 그럼 즐프하세요 ^^

heartsim 님이 쓰신 글 :
: 안녕하세요...
: dll을 자주 사용을 안 하다 이번에 사용을 하게 되었는데,
: 전에는 문제가 없었는데 이번 dll에서는 문제가 있더군요.
:
: 음..그러니간 함수안에서 지역변수를 사용했을 경우에는 문제가 없는데,
: 함수에서 전역변수가 필요해서 전역변수를 선언하는 경우 변수가 작동을 안 하는군요.@@;;
: 그래서 이번에는 함수안에서 static으로 선언을 해주었는데도 역시나 작동을 안 하는군요...
:
: 이런 낭패가.............^^;(전에는 몰랐었음...;;; 지역변수를 사용한 함수만 사용했기 때문)
:
:
: 전혀 문제가 없을거라 생각을 했는데, 디버깅을 해보니 변수값이 전혀 움직이지 않고 작동도 안함..
: dll에서는 전역변수나 함수안에서의 static변수사용할 때 다른 작업을 별도로 해주어야 하나요??
:
:
: <NullRenderDll.h> 헤더 파일
: extern "C" __declspec(dllexport) void OnVolume(float value);
: extern "C" __declspec(dllexport) void OnBalance(float value);
: extern "C" __declspec(dllexport) void SetSpeakerVolume(float fVolPercent);
: extern "C" __declspec(dllexport) float GetSpeakerVolume();
:
: extern "C" __declspec(dllexport) void Volume_OnOff();
:
: //extern "C" __declspec(dllexport) void __fastcall GetMainVol();
:
: <NullRenderDll.cpp> cpp파일
: #include <vcl.h>
: #include <windows.h>
: //#include "NullRendering.h"
:
: #include "NullRenderDll.h"
: #include "math.h"
: #include "DShow.h"
: #include "windows.h"
: #include "windowsx.h"
:
: #include "stdio.h"
: #include "assert.h"
: #include "winbase.h"
: //#include "winError.h"
:
: #include "atlbase.h"
: #include "atlconv.h"
: #pragma hdrstop
:
: #define VOLUME_FULL 0L
: #define VOLUME_SILENCE -10000L
:
: //---------------------------------------------------------------------------
: //   Important note about DLL memory management when your DLL uses the
: //   static version of the RunTime Library:
: //
: //   If your DLL exports any functions that pass String objects (or structs/
: //   classes containing nested Strings) as parameter or function results,
: //   you will need to add the library MEMMGR.LIB to both the DLL project and
: //   any other projects that use the DLL.  You will also need to use MEMMGR.LIB
: //   if any other projects which use the DLL will be performing new or delete
: //   operations on any non-TObject-derived classes which are exported from the
: //   DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling
: //   EXE's to use the BORLNDMM.DLL as their memory manager.  In these cases,
: //   the file BORLNDMM.DLL should be deployed along with your DLL.
: //
: //   To avoid using BORLNDMM.DLL, pass string information using "char *" or
: //   ShortString parameters.
: //
: //   If your DLL uses the dynamic version of the RTL, you do not need to
: //   explicitly add MEMMGR.LIB as this will be done implicitly for you
: //---------------------------------------------------------------------------
:
:         bool Volume__OnOff;<-----------------------------변수가 작동을 안 함..
:
:         float TOTAL;//대입값<-----------------------------변수가 작동을 안 함..
:
:     float m_fVolumePos;<-----------------------------변수가 작동을 안 함..
:
:     float m_fBalancePos;<-----------------------------변수가 작동을 안 함..
: //함수 안에서 static으로 선언을 해도 역시나 작동을 안함...
:
:     IGraphBuilder *m_pGB;
:     IMediaControl *pMC;
:         IBasicVideo *pBV;
:         IMediaSeeking *pMS;
:         IBasicAudio *pBA;
:
:
: #pragma argsused
: int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
: {
:
:
:         return 1;
: }
: //---------------------------------------------------------------------------
:
: void Volume_OnOff()
: {
:
:         if(m_pGB == NULL)
:                 return;// E_ABORT;
:
:         CComQIPtr<IBasicAudio> pBA(m_pGB);
:         if(!Volume__OnOff)
:         {
:                 pBA->put_Volume(VOLUME_SILENCE);
:                 Volume__OnOff=true;
:         }
:         else
:         {
:                 pBA->put_Volume(VOLUME_FULL);
:                 Volume__OnOff=false;
:         }
:
:         return;// S_OK;
: }
: ................
:

+ -

관련 글 리스트
20747 dll에서 전역변수가 작동을 안 하네요?? heartsim 3452 2002/08/12
20780     이런 실수를....@@;...감사.. heartsim 2100 2002/08/13
20779     Re:dll에서 전역변수가 작동을 안 하네요?? 얼큰 2530 2002/08/13
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.