Hey all, I'm trying to make a DLL that can be used in Pascal to enable multi-threading.

I've decided I want to export Threads in C++ to a DLL. Before I make DLL's I usually write the program first to test everything then I convert it to a DLL.

#include<windows.h>
#include<stdio.h>
#include<conio.h>
#include <iostream>


DWORD Thread(LPVOID lpParameter)
{

}

void FunctionToPass()
{
    //This function can be any type.. not just void.. and can have any amount of parameters.
}


int main()
{
    DWORD ThreadID = 1;
    HANDLE hThread = CreateThread(0, 0, Thread(*FunctionToPass()), 0, 0, &ThreadID);
}

The above does not do what I want it to do. I want it to be able to take in functions, and have the thread run them. It's actually my first time learning threads so I have no clue what I'm doing wrong. Codeblocks keeps telling me void not ignored as it ought to be.

Oh and would I actually be able to export this to a DLL? So that in any program, I can just create threads that take in functions?

void not ignored as it ought to be

because you are not passing the function to the thread. You are calling it (notice () in FunctionToPass() at line 21), then try to dereference the result (notice * there). Since FunctionToPass is void, the compiler complains.

Ok I've done the following yet I cannot get the thread to run the function :S
Any ideas?

#include<windows.h>
#include <iostream>


void FunctionToPass()
{
    //This function can be any type.. not just void..
    std::cout<<"meh";
}

DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
    //Run the function! ={
    void* parameter = (void*)lpParameter;
    parameter;
}


int main()
{
    DWORD ThreadID = 1;
    HANDLE hThread = CreateThread(NULL, 0, ThreadProc, (void*)FunctionToPass, 0, &ThreadID);
    std::cin.get();
}

So, you passed FunctionToPass to ThreadProc as a parameter, which is correct. Now you need to actually call it:

DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
    void (* function)() = (void (*)())lpParameter;
    function();
    return 0;
}
commented: Thanks a lot! +5
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.