www.digitalmars.com         C & C++   DMDScript  

c++ - Linkage problem

reply MRatcliff <software netrh.com> writes:
I used implib to create a .lib file for psapi.dll. I also found a header file.

The header file contains an ifdef __cplusplus declaration so it appears the
linkage should have C semantics.

The .lib file shows, among other entry points, the following (using libunres):

_EnumProcessModules
_EnumProcessModulesEx
_EnumProcesses
_GetDeviceDriverBaseNameA
_GetDeviceDriverBaseNameW
The 'EnumProcesses' is the function I am calling in a test application.  When
it links I get the following error:

OPTLINK (R) for Win32  Release 8.00.5
Copyright (C) Digital Mars 1989-2009  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
.\Obj\tproclist.obj(tproclist)
 Error 42: Symbol Undefined _EnumProcesses 12

How can I get this to resolve corrrectly?
Nov 13 2010
parent reply Walter Bright <newshound2 digitalmars.com> writes:
MRatcliff wrote:
 I used implib to create a .lib file for psapi.dll. I also found a header file.
 
 The header file contains an ifdef __cplusplus declaration so it appears the
 linkage should have C semantics.
 
 The .lib file shows, among other entry points, the following (using libunres):
 
 _EnumProcessModules
 _EnumProcessModulesEx
 _EnumProcesses
 _GetDeviceDriverBaseNameA
 _GetDeviceDriverBaseNameW
 The 'EnumProcesses' is the function I am calling in a test application.  When
 it links I get the following error:
 
 OPTLINK (R) for Win32  Release 8.00.5
 Copyright (C) Digital Mars 1989-2009  All rights reserved.
 http://www.digitalmars.com/ctg/optlink.html
 .\Obj\tproclist.obj(tproclist)
  Error 42: Symbol Undefined _EnumProcesses 12
 
 How can I get this to resolve corrrectly?

The 12 means it is compiled using the stdcall calling convention, not the C++ calling convention.
Nov 26 2010
parent MRatcliff <software netrh.com> writes:
Thanks -

Problem resolved by removing the WINAPI macro from the header file.

BOOL WINAPI EnumProcesses(DWORD *,DWORD,DWORD *);

To

BOOL EnumProcesses(DWORD *,DWORD,DWORD *);
Nov 26 2010