www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Linker doesn't find a Win32 API function

reply Niko Korhonen <niktheblak hotmail.com> writes:
I'm trying to use the SetFilePointerEx function from Win32 API in a 
piece of D software, like this:

<code>
extern (Windows)
{
   BOOL SetFilePointerEx(
     HANDLE hFile,
     long distanceToMove,
     long* newFilePointer,
     DWORD moveMethod);
}
</code>

According to Win32 API specs from MSDN such a function exists, but the 
linker gives an error when trying to compile the program:

Error 42: Symbol Undefined _SetFilePointerEx 20

I'm guessing the KERNEL32.LIB in the DMC package doesn't include the 
more recent (W2k+) Win32 API functions.

What can I do here? Do I need to make a custom KERNEL32.LIB for my 
project? And if I do, how do I do that?

-- 
Niko Korhonen
SW Developer
Aug 10 2005
next sibling parent "ElfQT" <dethjunk yahoo.com> writes:
I don't know if that's the ultimate solution, but
IMPORTS section in .def file works.

Eg.
EXETYPE NT
SUBSYSTEM WINDOWS
IMPORTS
_Direct3DCreate9 4=d3d9.Direct3DCreate9

You need
_SetFilePointerEx 20=<Dmudule>.SetFilePointerEx

ElfQT


"Niko Korhonen" <niktheblak hotmail.com> wrote in message
news:ddcsnp$2p2v$1 digitaldaemon.com...
 I'm trying to use the SetFilePointerEx function from Win32 API in a
 piece of D software, like this:

 <code>
 extern (Windows)
 {
    BOOL SetFilePointerEx(
      HANDLE hFile,
      long distanceToMove,
      long* newFilePointer,
      DWORD moveMethod);
 }
 </code>

 According to Win32 API specs from MSDN such a function exists, but the
 linker gives an error when trying to compile the program:

 Error 42: Symbol Undefined _SetFilePointerEx 20

 I'm guessing the KERNEL32.LIB in the DMC package doesn't include the
 more recent (W2k+) Win32 API functions.

 What can I do here? Do I need to make a custom KERNEL32.LIB for my
 project? And if I do, how do I do that?

 -- 
 Niko Korhonen
 SW Developer

Aug 10 2005
prev sibling parent reply "Shawn Liu" <liuxuhong.cn gmail.com> writes:
Yes. make a custom KERNEL32.LIB

// file your_kernel32.def
LIBRARY 'KERNEL32.DLL'
EXPORTS
_SetFilePointerEx 20 = SetFilePointerEx
// end of file your_kernel32.def

run in the command line:
implib.exe  your_kernel32.lib  your_kernel32.def

then link with your_kernel32.lib and the kernel32.lib  comes with DMC

implib.exe is "Digital Mars Import Library Manager".
It comes with DMC or can be download from D page
ftp://ftp.digitalmars.com/bup.zip







"Niko Korhonen" <niktheblak hotmail.com> 
??????:ddcsnp$2p2v$1 digitaldaemon.com...
 I'm trying to use the SetFilePointerEx function from Win32 API in a piece 
 of D software, like this:

 <code>
 extern (Windows)
 {
   BOOL SetFilePointerEx(
     HANDLE hFile,
     long distanceToMove,
     long* newFilePointer,
     DWORD moveMethod);
 }
 </code>

 According to Win32 API specs from MSDN such a function exists, but the 
 linker gives an error when trying to compile the program:

 Error 42: Symbol Undefined _SetFilePointerEx 20

 I'm guessing the KERNEL32.LIB in the DMC package doesn't include the more 
 recent (W2k+) Win32 API functions.

 What can I do here? Do I need to make a custom KERNEL32.LIB for my 
 project? And if I do, how do I do that?

 -- 
 Niko Korhonen
 SW Developer 

Aug 10 2005
parent reply "Shawn Liu" <liuxuhong.cn gmail.com> writes:
BTW, it should be

_SetFilePointerEx 16

since D's long is a 64 bit variable, while long in WIN32 is 32 bit
change the declaration as

extern (Windows)
{
   BOOL SetFilePointerEx(
     HANDLE hFile,
     int distanceToMove,
     int* newFilePointer,
     DWORD moveMethod);
}




"Shawn Liu" <liuxuhong.cn gmail.com> wrote:ddd8qv$8p9$1 digitaldaemon.com...
 Yes. make a custom KERNEL32.LIB

 // file your_kernel32.def
 LIBRARY 'KERNEL32.DLL'
 EXPORTS
 _SetFilePointerEx 20 = SetFilePointerEx
 // end of file your_kernel32.def

 run in the command line:
 implib.exe  your_kernel32.lib  your_kernel32.def

 then link with your_kernel32.lib and the kernel32.lib  comes with DMC

 implib.exe is "Digital Mars Import Library Manager".
 It comes with DMC or can be download from D page
 ftp://ftp.digitalmars.com/bup.zip







 "Niko Korhonen" <niktheblak hotmail.com> 
 ??????:ddcsnp$2p2v$1 digitaldaemon.com...
 I'm trying to use the SetFilePointerEx function from Win32 API in a piece 
 of D software, like this:

 <code>
 extern (Windows)
 {
   BOOL SetFilePointerEx(
     HANDLE hFile,
     long distanceToMove,
     long* newFilePointer,
     DWORD moveMethod);
 }
 </code>

 According to Win32 API specs from MSDN such a function exists, but the 
 linker gives an error when trying to compile the program:

 Error 42: Symbol Undefined _SetFilePointerEx 20

 I'm guessing the KERNEL32.LIB in the DMC package doesn't include the more 
 recent (W2k+) Win32 API functions.

 What can I do here? Do I need to make a custom KERNEL32.LIB for my 
 project? And if I do, how do I do that?

 -- 
 Niko Korhonen
 SW Developer


Aug 10 2005
parent "Shawn Liu" <liuxuhong.cn gmail.com> writes:
_SetFilePointerEx 20  is right.

I checked MSDN again. LARGE_INTEGER is 64 bit.
Sorry for my carelessness.


 "Niko Korhonen" <niktheblak hotmail.com> 
 ??????:ddcsnp$2p2v$1 digitaldaemon.com...
 I'm trying to use the SetFilePointerEx function from Win32 API in a 
 piece of D software, like this:

 <code>
 extern (Windows)
 {
   BOOL SetFilePointerEx(
     HANDLE hFile,
     long distanceToMove,
     long* newFilePointer,
     DWORD moveMethod);
 }
 </code>

 According to Win32 API specs from MSDN such a function exists, but the 
 linker gives an error when trying to compile the program:

 Error 42: Symbol Undefined _SetFilePointerEx 20

 I'm guessing the KERNEL32.LIB in the DMC package doesn't include the 
 more recent (W2k+) Win32 API functions.

 What can I do here? Do I need to make a custom KERNEL32.LIB for my 
 project? And if I do, how do I do that?

 -- 
 Niko Korhonen
 SW Developer



Aug 10 2005