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
[58678] Re:pas 파일을 CBuilder6에서 컴파일할 경우 dll 오류
장성호 [nasilso] 1685 읽음    2009-09-30 17:35
C++Builder에서  xxx.pas 파일을 프로젝트에 포함시켜서 사용하는것이 가능하지만

아래와 같이 외부 Dll을  pas에서 extern 해놓은경우에는 link에 문제가 있는것 같네요
(정확하게는 잘 모름)


음...

해결방법은
   1. 아래 pas 함수를 모두 C++Builder로 변환해서 사용합니다.
        pascal에 익숙하지 않으면 시간이 좀 걸릴것 같구..

  2. VC++용   h,cpp 파일을  C++Builder용으로 변환해서 씁니다.
      이방법 간단히 해봤는데 금방 되네요

      2.1  h/cpp 초반에 있는 #define문은 모두 삭제하고 , c++Builder-스타일로 변경
      2.2  몇가지 타입 변경
             AfxMessageBox  -> ShowMessage
             CString                -> String
             CWnd *               -> HWND
             Format                 -> sprintf
             m_pParent->PostMessage(WM_CLOSE);        ->  PostMessage(m_pParent,WM_CLOSE,0,0);
 
     2.3  http프로토콜로 서버에서 쿼리하는 함수( bool CPBCon::GetServerValue(String& theUrl))를
            IndyHttp로 변경


     위와같이 변경하고 C++BUilder프로젝트에 포함해서 컴파일하니 link에러가 없네요

      link에러가 없을수 밖에 없는것이
      VC++예제는 직접 loadlibrary하여 GetProcAddress로 함수address를 찾아서 호출하고 있네요

그럼..
   
초보 님이 쓰신 글 :
: 안녕하세요
:
: 프로그램베이에서 프로그램 등록용 dll 및 소스 파일을 제공하고 있는데
: 델파일7과 vc, vb용밖에 없습니다. 그래서
: 프로젝트에 upbcon.pas를 추가한 다음 컴파일을 하면 Unresolved external '_PBLogin@8' referenced from ...\upbcon.obj 등의 오류가 발생합니다.
: (해당 자료는 여기 있습니다 : http://www.programbay.co.kr/upload/module/manual.zip)
:
: upbcon.pas 소스는 다음과 같습니다
:
: unit Upbcon;
:
: interface
:
: uses
:   Windows, Messages, IdHTTP, ExtCtrls;
:
: type
:   my_Timer = class(TTimer)
:     //pb_Timer : TTimer;
:   private
:     procedure pbcon_Timer(Sender: TObject);
: end;
:
: function PbLogin(progid, title : pchar): Boolean;                          stdcall; external 'pbcon.dll' name '_PbLogin@8';
: function PbAutoLogin(progid, title : pchar; autologin : Integer): Boolean; stdcall; external 'pbcon.dll' name '_PbLogin_AutoLogin@12';
: function closeCB(func : Pointer) : Integer;                                stdcall; external 'pbcon.dll' name '_CloseCB@4';
: function UnloadDLL: Integer;                                               stdcall; external 'pbcon.dll' name 'Dll_Unload';
: function GetLoginID(id : Pointer): Integer;                                stdcall; external 'pbcon.dll' name '_GetLoginID@4';
: function isFreeUser: Integer;                                              stdcall; external 'pbcon.dll' name 'isFreeUser';
: function isAutoLogin: Integer;                                             stdcall; external 'pbcon.dll' name 'isAutoLogin';
: function SetAutoLogin(val : Integer) :  Integer;                           stdcall; external 'pbcon.dll' name '_SetAutoLogin@4';
: function GetEncCode(pdec : PChar; penc : Pointer): Integer;                stdcall; external 'pbcon.dll' name '_GetENCCode@8';
: function GetOption(opt : Pointer): Integer;                                stdcall; external 'pbcon.dll' name '_GetOption@4';
:
: function pbcon_Login (progid, title: pchar; autologin: Integer): Boolean;
: function pbcon_GetLoginID() : string;
: function pbcon_isFreeUser() : Integer;
: function pbcon_isAutoLogin() : Integer;
: function pbcon_SetAutoLogin(val : Integer) : Integer;
: function pbcon_GetEncCode(pdec : string) : string;
: function pbcon_RndString: String;
: function pbcon_CheckAuth(var pDec: string; var pEnc: string): Boolean;
: function pbcon_GetOption() : string;
:
: procedure pbcon_SetMainWnd(pHandle : Hwnd);
: procedure pbcon_ProjectEnd();
: procedure pbcon_Init();
: procedure pbcon_Unload();
: procedure KillProcess(hWindowHandle: HWND);
: //procedure pbcon_Timer(Sender: TObject);
:
: var
:   pb_MainFormHwnd : Hwnd;
:   pb_isUnloadfromDLL : Boolean;
:   pb_MsgAutoLogin : array[0..3] of string;
:   pb_MsgIsAutoLogin : array[0..1] of string;
:   pb_MsgIsFreeUser : array[0..1] of string;
:   pb_Timer : my_Timer;
:
: implementation
:
: procedure pbcon_Init();
: begin
:   pb_MsgAutoLogin[0] := '자동로그인 설정을 변경했습니다.';
:   pb_MsgAutoLogin[1] := '로그인시 비밀번호를 저장하지 않으면 자동로그인의 설정을 변경할 수 없습니다.';
:   pb_MsgAutoLogin[2] := '접속모듈을 추가할때 자동로그인 기능을 사용하도록 설정하셔야 합니다. (메뉴얼참고)';
:   pb_MsgAutoLogin[3] := '알수없는 오류로 자동로그인 설정에 실패했습니다.';
:
:   pb_MsgIsAutoLogin[0] := '자동로그인 사용';
:   pb_MsgIsAutoLogin[1] := '자동로그인 비사용';
:
:   pb_MsgIsFreeUser[0] := '정식 사용자';
:   pb_MsgIsFreeUser[1] := '체험판 사용자';
: end;
:
: function pbcon_Login(progid, title: pchar; autologin: Integer): Boolean;
: var
:   bResult1, bResult2 : Boolean;
:   lpDec, lpEnc : string;
:
: begin
:   pbcon_Init();
:   pb_isUnloadfromDLL := False;
:   if autologin = 0 then
:     bResult1 := PbLogin(progid, title)
:   else
:     bResult1 := PbAutoLogin(progid, title, 1);
:
:   bResult2 := False;
:   if bResult1 then
:   begin
:     lpDec := PChar(pbcon_RndString);
:     lpEnc := pbcon_GetEncCode(lpDec);
:     bResult2 := pbcon_CheckAuth(lpDec, lpEnc);
:   end;
:   if bResult1 and bResult2 then
:     closeCB(@pbcon_ProjectEnd);
:   Result := bResult1 and bResult2;
: end;
:
: procedure pbcon_SetMainWnd(pHandle : Hwnd);
: begin
:   pb_MainFormHwnd := pHandle;
: end;
:
: procedure pbcon_ProjectEnd();
: begin
:   pb_isUnloadfromDLL := True;
:  
:   pb_Timer := my_Timer.Create( nil );
:   pb_Timer.OnTimer := pb_Timer.pbcon_Timer;
:   pb_Timer.Enabled := False;
:   pb_Timer.Interval := 1000;
:   pb_Timer.Enabled := True;
:
: end;
:
: function pbcon_GetLoginID() : string;
: var
:     loginID : string;
:     bid : array[0..24] of char;
: begin
:     GetLoginID(@bid[0]);
:     loginID := bid;
:     Result := loginID;
: end;
:
: function pbcon_isFreeUser() : Integer;
: begin
:      Result := isFreeUser;
: end;
:
: function pbcon_isAutoLogin() : Integer;
: begin
:     Result := isAutoLogin;
: end;
:
: function pbcon_GetOption() : string;
: var
:     lpOpt : string;
:     bopt : array[0..24] of char;
: begin
:     GetOption(@bopt[0]);
:     lpOpt := bopt;
:     Result := lpOpt;
: end;
:
: function pbcon_SetAutoLogin(val : Integer) : Integer;
: begin
:     Result := SetAutoLogin(val);
: end;
:
: function pbcon_GetEncCode(pdec : string) : string;
: var
:    benc : array[0..2000] of char;
: begin
:    GetEncCode(PChar(pDec), @benc[0]);
:    Result := benc;
:
: end;
:
: function pbcon_RndString: String;
:   function RndChar: Char;
:   begin
:     Result := Char(  Random(Ord('Z') -  Ord('A') + 1) + Ord('A') );
:   end;
: var
:   i : Integer;
: begin
:   Result := '';
:   for i:=0 to Random(5)+5 do
:     Result := Result + RndChar
: end;
:
: function pbcon_CheckAuth(var pDec: string; var pEnc: string): Boolean;
: var
:   txt : string;
:   IdHTTP1 : TIdHTTP;
:   lpURL : string;
:   lpResult : Boolean;
:
: begin
:   Result := False;
:   try
:     IdHTTP1 := TIdHTTP.Create(nil);
:     try
:       lpURL := 'http://121.125.71.199/Auth/AuthQuery.pb';
:       lpURL := lpURL + '?dec=' + pDec;
:       lpURL := lpURL + '&enc=' + pEnc;
:       IdHTTP1.Port := 80;
:       txt := IdHTTP1.Get(lpURL);
:
:       if txt = 'True' then
:         lpResult := True
:       else
:         lpResult := False
:     finally
:       IdHTTP1.Free;
:     end;
:
:     Result := lpResult;
:   except
:     Exit;
:   end;
: end;
:
: procedure pbcon_Unload();
: begin
:   if pb_isUnloadfromDLL = False then
:     UnloadDLL();
: end;
:
: procedure KillProcess(hWindowHandle: HWND);
: var
:   hprocessID: INTEGER;
:   processHandle: THandle;
:   DWResult: DWORD;
: begin
:   SendMessageTimeout(hWindowHandle, WM_CLOSE, 0, 0,
:     SMTO_ABORTIFHUNG or SMTO_NORMAL, 5000, DWResult);
:   if isWindow(hWindowHandle) then
:   begin
:     // PostMessage(hWindowHandle, WM_QUIT, 0, 0);
:     { Get the process identifier for the window}
:     GetWindowThreadProcessID(hWindowHandle, @hprocessID);
:     if hprocessID <> 0 then
:     begin
:       { Get the process handle }
:       processHandle := OpenProcess(PROCESS_TERMINATE or PROCESS_QUERY_INFORMATION,
:         False, hprocessID);
:       if processHandle <> 0 then
:       begin
:         { Terminate the process }
:         TerminateProcess(processHandle, 0);
:         CloseHandle(ProcessHandle);
:       end;
:     end;
:   end;
: end;
:
: procedure my_Timer.pbcon_Timer(Sender: TObject);
: begin
:   pb_Timer.Enabled := False;
:   PostMessage(pb_MainFormHwnd, WM_QUIT, 0, 0);
: end;
:
: end.
:
:
: 여기서
: function PbLogin(progid, title : pchar): Boolean;                          stdcall; external 'pbcon.dll' name '_PbLogin@8';
: function PbAutoLogin(progid, title : pchar; autologin : Integer): Boolean; stdcall; external 'pbcon.dll' name '_PbLogin_AutoLogin@12';
: function closeCB(func : Pointer) : Integer;                                stdcall; external 'pbcon.dll' name '_CloseCB@4';
: function UnloadDLL: Integer;                                               stdcall; external 'pbcon.dll' name 'Dll_Unload';
: function GetLoginID(id : Pointer): Integer;                                stdcall; external 'pbcon.dll' name '_GetLoginID@4';
: function isFreeUser: Integer;                                              stdcall; external 'pbcon.dll' name 'isFreeUser';
: function isAutoLogin: Integer;                                             stdcall; external 'pbcon.dll' name 'isAutoLogin';
: function SetAutoLogin(val : Integer) :  Integer;                           stdcall; external 'pbcon.dll' name '_SetAutoLogin@4';
: function GetEncCode(pdec : PChar; penc : Pointer): Integer;                stdcall; external 'pbcon.dll' name '_GetENCCode@8';
: function GetOption(opt : Pointer): Integer;                                stdcall; external 'pbcon.dll' name '_GetOption@4';
:
: 이 부분에서 오류가 발생하는 것 같습니다 그래서
: implib pbcon.lib pbcon.dll을 통해 lib를 만들어 라이브러리를 추가한 후 해봐도 마찬가지입니다..
: stdcall을 cdecl 등으로 바꿔도 마찬가지구요..
: dll 파일 또한 라이브러리 및 include 경로에 모두 포함되어 있습니다.
:
: 어떻게 해결해야 하나요? 고수님들 도와주시면 감사하겠습니다 ㅠ

+ -

관련 글 리스트
58676 pas 파일을 CBuilder6에서 컴파일할 경우 dll 오류 초보 1644 2009/09/30
58678     Re:pas 파일을 CBuilder6에서 컴파일할 경우 dll 오류 장성호 1685 2009/09/30
58679         Re:Re:pas 파일을 CBuilder6에서 컴파일할 경우 dll 오류 초보 1283 2009/09/30
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.