Home > Back-end >  Address: parameters to 3 from "const char [15]" into "LPVOID"
Address: parameters to 3 from "const char [15]" into "LPVOID"

Time:09-25

Environment: use VS2017
Error message:

1> -- -- -- -- -- - has started to regenerate: all projects: ConsoleApplication1, configuration: Debug Win32 -- -- -- -- -- --
1> Test. The CPP
1> E: \ \ v project lesson 26 \ consoleapplication1 \ consoleapplication1 \ test CPP (40) : error C2664: "BOOL DeviceIoControl (HANDLE, dwords LPVOID, dwords LPVOID, DWORD, LPDWORD, LPOVERLAPPED)" : cannot be parameters from "const char [15]" into "LPVOID"
1> E: \ \ v project lesson 26 \ consoleapplication1 \ consoleapplication1 \ test CPP (40) : note: conversion loss qualifier
1> Generating project has been completed "ConsoleApplication1 vcxproj" operations - failure,
==========all regenerated: zero success, failure, skip 0==========


Source:
DWORD dwRet
Char IoBuffer [1024]={0};
DeviceIoControl (hDevice, CTLBUFFERED, "this is way of buffer", strlen (" this is how the buffer ") + 1, IoBuffer, sizeof (IoBuffer), & amp; DwRet, NULL);
IoBuffer printf (" % s \ n ", IoBuffer);
The CloseHandle (hDevice);
Return 0;

CodePudding user response:

Because LPVOID essence is void *
But the const char [15] nature is const char *
Their const modifiers are not compatible,
If you are sure this kind of writing is no problem, you can manually remove const compulsory:

(char *) "this is how buffer"

Or

Const_cast & lt; Char * & gt; (" this is a buffer ")

CodePudding user response:

DWORD dwRet
Char IoBuffer [1024]={0};
Char STR [255]="this is the buffer way";
DeviceIoControl (hDevice, CTLBUFFERED, STR (void *), strlen (STR) + 1, IoBuffer, sizeof (IoBuffer), & amp; DwRet, NULL);
IoBuffer printf (" % s \ n ", IoBuffer);
The CloseHandle (hDevice);

CodePudding user response:

Constant strings of storage is not clear, should use a temporary stack space or heap space save, and then processing, as above reply
Should not be manually remove the constant string const attribute,
  • Related