www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - threads in windows (header/linking problem)

reply Shane <Shane_member pathlink.com> writes:
Hi,
I have noticed that there are many windows api's that are not included by import
std.windows.windows. This isn't too much of a problem since I can write my own
code to declare the api functions I need, however, when trying to link my
program to the .lib files, the linker can't find the api functions!

For example, I am trying to write a program that uses threads through the
CreateThread api function.
I decleared the function like this:
extern (Windows) HANDLE CreateThread(int,int,int delegate(),int,int,int);
and also tried it like this:
extern (Windows) HANDLE CreateThread(int,int,int,int,int,int);

I compiled it like this:
dmd picsampler.d comm sampler graph gdi32.lib user32.lib kernel32.lib 
(comm, sampler, & graph are my own modules)

And I get this error message:
Error 42: Symbol Undefined __D7sampler7Sampler12CreateThreadWiiDWZiiiiZT3std1c7
windows7windows6HANDLE 28
--- errorlevel 1

CreateThread should be defined in kernel32.lib. Can anyone help? I have done
this with other api's and they have worked fine.
Oct 02 2004
parent Sjoerd van Leent <svanleent wanadoo.nl> writes:
Shane wrote:
 Hi,
 I have noticed that there are many windows api's that are not included by
import
 std.windows.windows. This isn't too much of a problem since I can write my own
 code to declare the api functions I need, however, when trying to link my
 program to the .lib files, the linker can't find the api functions!
 
 For example, I am trying to write a program that uses threads through the
 CreateThread api function.
 I decleared the function like this:
 extern (Windows) HANDLE CreateThread(int,int,int delegate(),int,int,int);
 and also tried it like this:
 extern (Windows) HANDLE CreateThread(int,int,int,int,int,int);
 
 I compiled it like this:
 dmd picsampler.d comm sampler graph gdi32.lib user32.lib kernel32.lib 
 (comm, sampler, & graph are my own modules)
 
 And I get this error message:
 Error 42: Symbol Undefined __D7sampler7Sampler12CreateThreadWiiDWZiiiiZT3std1c7
 windows7windows6HANDLE 28
 --- errorlevel 1
 
 CreateThread should be defined in kernel32.lib. Can anyone help? I have done
 this with other api's and they have worked fine.
 
 
I did: ----- begin createthread.d ----- module createthread; typedef void* winHandle; extern (Windows) winHandle CreateThread(int, int, int, int, int, int); int main(char[][] args) { winHandle pointer = CreateThread(0, 0, 0, 0, 0, 0); return cast(int)pointer; } ----- end createthread.d ----- and compiled it using standard DMD (dmd createthread.d) and it worked perfectly. (It did even run without a problem.) Regards, Sjoerd
Oct 03 2004