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

델파이 Q&A
Delphi Programming Q&A
[8385] [질문] DLL 호출관련 Calling Convention에 대하여 델파이 호출
정희섭 [] 1553 읽음    2002-10-21 13:29
VC++에서 만든 dll을 호출시
CALLBACK 선언을 없애고(아래 예제 참고)
델파이에서

function EdrCenterText(hdc:HDC;prc:PRect;pString:PChar):boolean; cdecl; external 'EDRLIB.DLL';

라고 선언해야만 DLL 함수가 호출되거든요

cdecl선언만 호출되고 stdcall 인자를 넣으면 함수가 호출되지않는
이유를 몰라서 질문합니다.



////////////////헤더 선언부분 변경전///////////////////////
#ifdef __cplusplus
#define EXPORT extern "C" __declspec (dllexport)
#else
#define EXPORT __declspec (dllexport)
#endif

EXPORT BOOL CALLBACK EdrCenterTextA (HDC, PRECT, PCSTR) ;
EXPORT BOOL CALLBACK EdrCenterTextW (HDC, PRECT, PCWSTR) ;

#ifdef UNICODE
#define EdrCenterText EdrCenterTextW
#else
#define EdrCenterText EdrCenterTextA
#endif
///////////////////////////////////////////////////////////
////////////////헤더 선언부분 변경후///////////////////////
#ifdef __cplusplus
#define EXPORT extern "C" __declspec (dllexport)
#else
#define EXPORT __declspec (dllexport)
#endif

EXPORT BOOL  EdrCenterTextA (HDC, PRECT, PCSTR) ;
EXPORT BOOL  EdrCenterTextW (HDC, PRECT, PCWSTR) ;

#ifdef UNICODE
#define EdrCenterText EdrCenterTextW
#else
#define EdrCenterText EdrCenterTextA
#endif
///////////////////////////////////////////////////////////


When you declare a procedure or function, you can specify a calling convention using one of the directives register, pascal, cdecl, stdcall, and safecall. For example,

function MyFunction(X, Y: Real): Real; cdecl;
...

Calling conventions determine the order in which parameters are passed to the routine. They also affect the removal of parameters from the stack, the use of registers for passing parameters, and error and exception handling. The default calling convention is register.

The register and pascal conventions pass parameters from left to right; that is, the left most parameter is evaluated and passed first and the rightmost parameter is evaluated and passed last. The cdecl, stdcall, and safecall conventions pass parameters from right to left.
        For all conventions except cdecl, the procedure or function removes parameters from the stack upon returning. With the cdecl convention, the caller removes parameters from the stack when the call returns.

The register convention uses up to three CPU registers to pass parameters, while the other conventions pass all parameters on the stack.
        The safecall convention implements exception "firewalls." On Windows, this implements interprocess COM error notification.

The table below summarizes calling conventions.

Calling conventions
Directive        Parameter order        Clean-up        Passes parameters in registers?
register        Left-to-right        Routine        Yes
pascal        Left-to-right        Routine        No
cdecl        Right-to-left        Caller        No
stdcall        Right-to-left        Routine        No
safecall        Right-to-left        Routine        No
The default register convention is the most efficient, since it usually avoids creation of a stack frame. (Access methods for published properties must use register.) The cdecl convention is useful when you call functions from shared libraries written in C or C++, while stdcall and safecall are recommended, in general, for calls to external code. On Windows, the operating system APIs are stdcall and safecall. Other operating systems generally use cdecl. (Note that stdcall is more efficient than cdecl.)

The safecall convention must be used for declaring dual-interface methods. The pascal convention is maintained for backward compatibility. For more information on calling conventions, see Program control.
The directives near, far, and export refer to calling conventions in 16-bit Windows programming. They have no effect in 32-bit applications and are maintained for backward compatibility only.

+ -

관련 글 리스트
8385 [질문] DLL 호출관련 Calling Convention에 대하여 델파이 호출 정희섭 1553 2002/10/21
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.