www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How create Win32api Thread in Dlang?

reply Marcone <marcone email.com> writes:
This is C++ code:

#include <windows.h>

WINAPI DWORD threadFunc(LPVOID x) {
   while (true) {
     try {
       throw 1;
     } catch (...) {
     }
   }
   return 0;
}

int main(int argc, char *argv[]) {
   CreateThread(NULL, 0, threadFunc, NULL, 0, NULL);
   CreateThread(NULL, 0, threadFunc, NULL, 0, NULL);

   Sleep(1000);

   return 0;
}

How can I convert it to Dlang?
Sep 25 2020
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Saturday, 26 September 2020 at 03:08:56 UTC, Marcone wrote:
 #include <windows.h>
import core.sys.windows.windows
 WINAPI
extern(Windows)
 int main(int argc, char *argv[]) {
int main(string[] args)
   CreateThread(NULL, 0, threadFunc, NULL, 0, NULL);
CreateThread(null, 0, &threadFunc, null, 0, null); Maybe minor compile errors like required casts but this is really about it. You can almost literally copy/paste most C examples to D.
Sep 25 2020