본문 바로가기

프로그래밍/C-CPP

[번역] (dll) __stdcall 함수와 GetProcAddress

반응형

http://groups.google.com/group/microsoft.public.vc.language/browse_thread/thread/e5c9f986c51729dd

From: "Kürþat" <kursatthek...@gmail.com>
제목 : (dll) __stdcall 함수와 GetProcAddress
Subject: (dll) __stdcall functions and GetProcAddress
Date: Thu, 7 May 2009 00:28:54 +0300
Message-ID: <#1IeTEpzJHA.5032@TK2MSFTNGP05.phx.gbl>
Newsgroups: microsoft.public.vc.language

Hi,

아주 간단한 "int Add (int, int)" 함수를 익스포트 하는 간단한 dll을 만들었고,
LoadLibrary 와 GetProcAddress 를 이용해서 그 함수를 사용한다. 호출 컨벤션이
"cdecl" 일 때는 잘 되는데, "stdcall" 일 때에는 GetProcAddress 가 0을 리턴한
다. 익스포트된 목록을 보면 함수가 _Add@8 로 되어 있다. dll의 stdcall 함수들
에 동적으로 접근할 때 저런 복잡한 이름을 모르고 할 수는 없나? 내가 알기로는
윈도우 API 함수들도 일반적으로 stdcall 호출 규약을 따르는데, 우리 그 함수들
동적으로 ( LoadLibrary+GetProcAddress ) 복잡한 이름을 쓰지 않고 잘 사용할
수 있지 않나? 어떻게 하는거지?

미리 감사.

I have a very simple dll that exports a simple function  "int Add (int,
int)". I use the function from an executable using LoadLibrary and
GetProcAddress. When calling convention is "cdecl" so far so good but with
"stdcall" GetProcAddress returns 0. When I look at the export list I see the
function exported as _Add@8. Well, how can I dynamically address stdcall
functions from .dll's without knowing those strange (and I think not
reliable to depend on) names? AFAIK, windows API functions generally use
stdcall calling convention and we can address those functions dynamically
(using LoadLibrary+GetProcAddress) using their straight names, what is the
trick?

Thanks in advance.

----

From: "Bob Milton" <DocBob1...@newsgroup.nospam>
References: <#1IeTEpzJHA.5032@TK2MSFTNGP05.phx.gbl>
Subject: Re: (dll) __stdcall functions and GetProcAddress
Date: Wed, 6 May 2009 14:55:42 -0700
Message-ID: <eR2wnVpzJHA.1492@TK2MSFTNGP04.phx.gbl>
Newsgroups: microsoft.public.vc.language

    간단함 - .def 파일을 사용해. 그 파일 사용하면 임포트해서 사용하는 프로
그램들에게 보이는 이름을 명시적으로 지정할 수 있어. 익스포트 정의는 다음과
같이
    Add=_Add@8

이제 GetProcAddress 로 "Add"란 함수를 가져올 수 있어요.
    대부분의 MS Dll도 .def 파일과 빌드됩니다.

    Simple - use .def files. They allow specifying the name that the
importing program sees explicitly. So an export def might be
    Add=_Add@8

now you can GetProcAddress on "Add".
    Most of Microsofts Dlls were built with .def files (even MFC since it
exports no names at all!)

----

From: Ulrich Eckhardt <eckha...@satorlaser.com>
Newsgroups: microsoft.public.vc.language
Subject: Re: (dll) __stdcall functions and GetProcAddress
Date: Thu, 07 May 2009 09:35:11 +0200
Message-ID: <fifad6-136.ln1@satorlaser.homedns.org>
References: <#1IeTEpzJHA.5032@TK2MSFTNGP05.phx.gbl> <eR2wnVpzJHA.1492@TK2MSFTNGP04.phx.gbl>

Bob Milton wrote:
> [.def files] allow specifying the name that the
> importing program sees explicitly. So an export def might be
>     Add=_Add@8
>
> now you can GetProcAddress on "Add".

다음과 같이 간단하게도 됩니다.

  EXPORTS
    Add

"=_Add@8" 부분이 없어도 링커는 알아서 잘 해 줄 거에요.

Actually, that is more hassle than necessary. You can simply use this:

  EXPORTS
    Add

Even without the "=_Add@8" the linker will do The Right Thing(tm).

Uli

--
C++ FAQ: http://parashift.com/c++-faq-lite

Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

728x90