About explicit linking to DLL functions: 
Author Message
 About explicit linking to DLL functions:

Hi,all:
  typedef DWORD (TERMINATEPROC)(DWORD,DWORD);
  HINSTANCE hInstance;
  DWORD dwPID,dwRet;
  TERMINATEPROC* pFun;
  dwPID=reinterpret_cast<unsigned long>(&strPID);
  VERIFY(hInstance=::LoadLibrary("G:\\vc++\\EndProcess\\Debug\\EndProcess.d
ll"));
  VERIFY(pFun=(TERMINATEPROC*)::GetProcAddress(hInstance,"TerminateApp"));
  dwRet=(*pFun)(dwPID,100);
When debug to "VERIFY(pFun=(TERMINATEPROC*)::",produce "Debug Assertion
Failed",Could you offer any messages?


Fri, 18 Feb 2005 20:56:04 GMT  
 About explicit linking to DLL functions:

Quote:

>   VERIFY(pFun=(TERMINATEPROC*)::GetProcAddress(hInstance,"TerminateApp"

> Assertion Failed",Could you offer any messages?

Open the DLL with "Dependency Walker" (Visual Studio Tools) and look if the
Function "TerminateApp" exists !


--
Greetings
  Jochen



Fri, 18 Feb 2005 21:02:34 GMT  
 About explicit linking to DLL functions:


Quote:

>>   VERIFY(pFun=(TERMINATEPROC*)::GetProcAddress(hInstance,"TerminateApp
>>   "

>> Assertion Failed",Could you offer any messages?

> Open the DLL with "Dependency Walker" (Visual Studio Tools) and look
> if the Function "TerminateApp" exists !



Hi,Jochen Kalmbach
  Thank you.I open the DLL with "Dependency Walker",it shows



Fri, 18 Feb 2005 21:39:02 GMT  
 About explicit linking to DLL functions:

Quote:

>   Thank you.I open the DLL with "Dependency Walker",it shows



means:

--
Greetings
  Jochen



Fri, 18 Feb 2005 21:54:20 GMT  
 About explicit linking to DLL functions:


Quote:

>>   Thank you.I open the DLL with "Dependency Walker",it shows


> means:


Hi:
 I wrote in the DLL;
extern "C"__declspec(dllexport) DWORD WINAPI TerminateApp( DWORD dwPID,
DWORD dwTimeout )



Fri, 18 Feb 2005 22:25:26 GMT  
 About explicit linking to DLL functions:


Quote:



>>>   Thank you.I open the DLL with "Dependency Walker",it shows


>> means:

> Hi:
>  I wrote in the DLL;
> extern "C"__declspec(dllexport) DWORD WINAPI TerminateApp( DWORD dwPID,
> DWORD dwTimeout )


How to verify the pFun pointer is ok? If is the pFun value equal to "Entry
point"(In the "Dependency Walker")?
Thanks.


Fri, 18 Feb 2005 22:33:54 GMT  
 About explicit linking to DLL functions:


<snip>

Quote:
>  I wrote in the DLL;
> extern "C"__declspec(dllexport) DWORD WINAPI TerminateApp( DWORD dwPID,
> DWORD dwTimeout )


Because that is the name of the function in the export table.

One of the great myths is that extern "C" {} means no name
decoration. In fact, all it means is that any decoration of the
name or calling conventions used are consistent with any
decoration methods and calling conventions used by the
C compiler. To avoid name decoration altogether, use a
module definition file.

From the MSDN documentation:

"The form of decoration for a C function depends on
the calling convention used in its declaration, as
shown below.

__cdecl (the default) - Leading underscore (_)


bytes in the parameter list

__fastcall Same as __stdcall, but prepended by an at
sign instead of an underscore"

C++ functions also encode the types or their arguments
in the name.

Example from MSDN:

"void CALLTYPE test(void);

might come to anything in the table below depending
on what CALLTYPE is and what language you are using.
CALLTYPEs such as __cdecl, __fastcall, and __stdcall
can change the naming conventions for a function/variable.

Calling convention extern 'C' or .C file
------------------------
C naming convention (__cdecl):  _test



--------------------------

.CPP , .CXX or /TP
--------------------------



------------------------

Use extern 'C' when calling a C function from a C++ program.
Extern 'C' forces use of the C naming convention for
non-class C++ functions.

<snip>

There is currently no standard for C++ naming between
compiler vendors or even between different versions of a
compiler. Therefore linking object files compiled with other
compilers may not produce the same naming scheme
and thus causes unresolved externals."



Sat, 19 Feb 2005 01:21:49 GMT  
 About explicit linking to DLL functions:


Quote:



> <snip>
>>  I wrote in the DLL;
>> extern "C"__declspec(dllexport) DWORD WINAPI TerminateApp( DWORD dwPID,
>> DWORD dwTimeout )

> Because that is the name of the function in the export table.

> One of the great myths is that extern "C" {} means no name
> decoration. In fact, all it means is that any decoration of the
> name or calling conventions used are consistent with any
> decoration methods and calling conventions used by the
> C compiler. To avoid name decoration altogether, use a
> module definition file.

> From the MSDN documentation:

> "The form of decoration for a C function depends on
> the calling convention used in its declaration, as
> shown below.

> __cdecl (the default) - Leading underscore (_)

> __stdcall - Leading underscore (_) and a trailing at sign

> bytes in the parameter list

> __fastcall Same as __stdcall, but prepended by an at
> sign instead of an underscore"

> C++ functions also encode the types or their arguments
> in the name.

> Example from MSDN:

> "void CALLTYPE test(void);

> might come to anything in the table below depending
> on what CALLTYPE is and what language you are using.
> CALLTYPEs such as __cdecl, __fastcall, and __stdcall
> can change the naming conventions for a function/variable.

> Calling convention extern 'C' or .C file
> ------------------------
> C naming convention (__cdecl):  _test



> --------------------------

> .CPP , .CXX or /TP
> --------------------------



> ------------------------

> Use extern 'C' when calling a C function from a C++ program.
> Extern 'C' forces use of the C naming convention for
> non-class C++ functions.

> <snip>

> There is currently no standard for C++ naming between
> compiler vendors or even between different versions of a
> compiler. Therefore linking object files compiled with other
> compilers may not produce the same naming scheme
> and thus causes unresolved externals."

Hi,Ron Ruble:
 Could you say clearly?I'm a beginner.The function calls Win32 API in the
DLL.Which decoration does use?


Sat, 19 Feb 2005 09:48:15 GMT  
 About explicit linking to DLL functions:
Hi,all:
  Could you offer some samples?


Sat, 19 Feb 2005 10:26:14 GMT  
 About explicit linking to DLL functions:
hi

MSDN has lot of stuff on DLL's !!
like DLL's in Win32
DLL for Beginners etc etc !!

Enjoy
Govil

Quote:
>-----Original Message-----
>Hi,all:
>  Could you offer some samples?
>.



Sat, 19 Feb 2005 16:14:02 GMT  
 About explicit linking to DLL functions:


Quote:




> > <snip>
> >>  I wrote in the DLL;
> >> extern "C"__declspec(dllexport) DWORD WINAPI TerminateApp( DWORD dwPID,
> >> DWORD dwTimeout )


<snip>

Quote:
> Hi,Ron Ruble:
>  Could you say clearly?I'm a beginner.The function calls Win32 API in the
> DLL.Which decoration does use?

WINAPI is an alias for __stdcall, which, according to my

sign, followed by the number of bytes in the parameter
list"


__stdcall, 8 bytes in the parameter list.

The standard APIs do _not_ decorate the names of
API functions; MS uses module definition files to
control the generation of exported names and to
ensure that ordinal numbers are consistent between
releases.

The MSDN documentation has a section on using
DEF files.



Sat, 19 Feb 2005 21:17:01 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. DLL function calling problems (explicit - only knowing function name at runtime)

2. C++ 4.0 doesn't work like C++ 2.0 for function exports and explicit linking

3. Dll explicit link

4. How to use explicit link to DLL?

5. explicit linking dll's with classes

6. A question about explicit linking to DLL:

7. MFC Extension DLL: Explicit Linking

8. explicit vs implicit linking to DLL

9. Threads & Explicit Linked DLL weirdness

10. explicit linking of mfc extension dll

11. explicit linked dll:

12. Dll explicit link

 

 
Powered by phpBB® Forum Software