Here is the code.
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
int _tmain(int argc, _TCHAR* argv[])
{
auto f = CreateFile(L"file.txt", GENERIC_READ, FILE_SHARE_READ, nullptr,
OPEN_EXISTING, FILE_FLAG_OVERLAPPED, nullptr);
struct overlapped_buffer
{
OVERLAPPED o;
char b[64];
};
overlapped_buffer ob = {};
ReadFileEx(f, ob.b, sizeof(ob.b), &ob.o, [] (DWORD e, DWORD c, OVERLAPPED * o)
{
if( ERROR_SUCCESS == e ) printf("Error");
else {
auto ob = reinterpret_cast<overlapped_buffer *>(o);
printf("> %.*s\n", c, ob->b);
}
} );
SleepEx( 1000, TRUE );
CloseHandle( f );
printf("read file");
return 0;
}
The Issue is that I dont know how to resolve the intellisense error.
2 IntelliSense: no suitable conversion function from "lambda []void (DWORD e, DWORD c, OVERLAPPED *o)->void" to "LPOVERLAPPED_COMPLETION_ROUTINE" exists c:\kombea\portaudiofastplayer\test_lambda\test_lambda.cpp 19 43 test_lambda
Am I able to create a lambda function and use it as a CALLBACK function in this case?
Works fine in Mingw 4.8.1 and VS2013..:
Created a file called "file.txt". Added "Hello World" to it and save it. I then ran the following and it prints "> Hello World".
In VS2010, the following compiles at least:
The SleepEx with parameter TRUE is causing it to throw.. I have no clue why..
Even this throws when it hits SleepEx, however both the above and the following have "Hello World" stored in the overlapped buffer..