C2664 Cannot convert parameter 1 from 'int' to 'hwnd' - winapi

Im trying to make a simple program for a old pocketpc application.
Want it to get the time and show it when i use the pushbutton.
With the code below, i get two compiler errors:
error C2664: 'SetWindowTextW' : cannot convert parameter 1 from 'int' to 'HWND' Line: 201
error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [7]' to 'LPCWSTR' Line: 233
Ive tried to search, seems to be a common misunderstanding this, but i cant see an explanation that fits..
_strdate( dateStr);
SetWindowText(1003, dateStr);
Also this:
hwndLabel = CreateWindow("STATIC","Time",
WS_VISIBLE | WS_CHILD | SS_RIGHT,
10,200,75,35,hWnd,NULL,1003,NULL);
Edit:
After Xearinox suggestions, i get three new faults.
These:
error C2664: '_wstrdate' : cannot convert parameter 1 from 'char [9]' to 'wchar_t *' 199
error C2664: 'SetDlgItemTextW' : cannot convert parameter 3 from 'char [9]' to 'LPCWSTR' 201
error C2440: '=' : cannot convert from 'HWND' to 'int' 233
if i remove (HMENU) from the static, i get another last error:
error C2664: 'CreateWindowExW' : cannot convert parameter 10 from 'int' to 'HMENU' 233

First parameter of SetWindowText is hwnd, not control identifier.
Try this:
SetDlgItemTextW(hWnd, 1003, dateStr);
Use this for retrieve date:
WCHAR dateStr[256] = {0};
_wstrdate(dateStr);
Also use wide string parameters for CreateWindow:
hwndLabel = CreateWindowW(L"STATIC",L"Time",
WS_VISIBLE | WS_CHILD | SS_RIGHT,
10,200,75,35,hWnd, (HMENU)1003, NULL, NULL);

Related

Swoole make failed ubuntu16.04

I am trying to install SWOOLE on my Ubuntu-16.04
I tried this sudo pecl install swoole
But am getting a long list of errors(Skipped some lines)
In file included from /tmp/pear/temp/swoole/php_swoole.h:156:0,
from /tmp/pear/temp/swoole/swoole.c:16:
/tmp/pear/temp/swoole/php7_wrapper.h: In function 'sw_zend_is_callable':
/tmp/pear/temp/swoole/php7_wrapper.h:238:5: error: unknown type name 'zend_string'
zend_string *key = NULL;
^
/tmp/pear/temp/swoole/php7_wrapper.h:239:5: warning: passing argument 3 of 'zend_is_callable' from incompatible pointer type [enabled by default]
int ret = zend_is_callable(cb, a, &key);
^
In file included from /usr/include/php5/main/php.h:39:0,
from /tmp/pear/temp/swoole/php_swoole.h:25,
from /tmp/pear/temp/swoole/swoole.c:16:
/usr/include/php5/Zend/zend_API.h:301:20: note: expected 'char **' but argument is of type 'int **'
ZEND_API zend_bool zend_is_callable(zval *callable, uint check_flags, char **callable_name TSRMLS_DC);
^
In file included from /usr/include/php5/Zend/zend.h:252:0,
from /usr/include/php5/main/php.h:35,
from /tmp/pear/temp/swoole/php_swoole.h:25,
from /tmp/pear/temp/swoole/swoole.c:16:
/tmp/pear/temp/swoole/php7_wrapper.h:240:29: error: request for member 'val' in something not a structure or union
char *tmp = estrndup(key->val, key->len);
^
/usr/include/php5/Zend/zend_alloc.h:78:44: note: in definition of macro 'estrndup'
#define estrndup(s, length) _estrndup((s), (length) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
^
/tmp/pear/temp/swoole/php7_wrapper.h:240:39: error: request for member 'len' in something not a structure or union
char *tmp = estrndup(key->val, key->len);
^
/usr/include/php5/Zend/zend_alloc.h:78:49: note: in definition of macro 'estrndup'
#define estrndup(s, length) _estrndup((s), (length) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
^
In file included from /tmp/pear/temp/swoole/php_swoole.h:156:0,
from /tmp/pear/temp/swoole/swoole.c:16:
/tmp/pear/temp/swoole/php7_wrapper.h: In function 'sw_zend_is_callable_ex':
/tmp/pear/temp/swoole/php7_wrapper.h:248:5: error: unknown type name 'zend_string'
zend_string *key = NULL;
^
/tmp/pear/temp/swoole/php7_wrapper.h:249:5: warning: passing argument 4 of 'zend_is_callable_ex' from incompatible pointer type [enabled by default]
int ret = zend_is_callable_ex(callable, NULL, check_flags, &key, fcc, error);
make: *** [swoole.lo] Error 1
ERROR: `make' failed
I have also tried this
cd swoole-src
./configure
make
Which is also giving the similar errors.
How to solve this? thanks in advance!
EDIT : Added the first Generated ERRORS too

WApplication::bind() usage in combination with Wt::WServer::post

I want to bind a callback, which will be called by a thread outside the Wt event loop.
So obviously I want to use Wt::WServer::post, but I don't get how WApplication::bind should be used, since it's a nonstatic function.
First attempt was this:
auto loaded_callback = [](const decltype(Wt::WApplication::sessionId) &session){
Wt::WServer::post(session,
Wt::WApplication::bind(&table_model::member_func),)
};
Which of course didn't work because bind is nonstatic. However my next attempt
auto object_protect_bind =
Wt::WApplication::instance()->bind(&order_aggregate_table_model::load_future_in_map);
failed with a shitload of compiler errors
Error 153 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int \boost\function\function_template.hpp 922 1 MDDB_Web
Error 156 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int \boost\function\function_template.hpp 926 1 MDDB_Web
Error 160 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int \boost\function\function_template.hpp 927 1 MDDB_Web
Error 150 error C2903: 'apply' : symbol is neither a class template nor a function template \boost\function\function_template.hpp 922 1 MDDB_Web
Error 162 error C2825: 'manager_type': must be a class or namespace when followed by '::' \boost\function\function_template.hpp 934 1 MDDB_Web
Error 154 error C2653: 'handler_type' : is not a class or namespace name \boost\function\function_template.hpp 926 1 MDDB_Web
Error 158 error C2653: 'handler_type' : is not a class or namespace name \boost\function\function_template.hpp 927 1 MDDB_Web
Error 164 error C2275: 'manager_type' : illegal use of this type as an expression \boost\function\function_template.hpp 934 1 MDDB_Web
Error 165 error C2146: syntax error : missing '}' before identifier 'manage' \boost\function\function_template.hpp 934 1 MDDB_Web
Error 159 error C2146: syntax error : missing ';' before identifier 'manager_type' \boost\function\function_template.hpp 927 1 MDDB_Web
Error 155 error C2146: syntax error : missing ';' before identifier 'invoker_type' \boost\function\function_template.hpp 926 1 MDDB_Web
Error 152 error C2143: syntax error : missing ';' before '<' \boost\function\function_template.hpp 922 1 MDDB_Web
Error 163 error C2039: 'manage' : is not a member of '`global namespace'' \boost\function\function_template.hpp 934 1 MDDB_Web
Error 151 error C2039: 'apply' : is not a member of 'boost::detail::function::get_invoker0' \boost\function\function_template.hpp 922 1 MDDB_Web
Error 166 error C1903: unable to recover from previous error(s); stopping compilation \boost\function\function_template.hpp 934 1 MDDB_Web
while the overall solution I had in mind was:
auto sessionId = Wt::WApplication::instance()->sessionId();
auto server_ptr = Wt::WServer::instance();
auto object_protect_bind = Wt::WApplication::instance()->bind(&order_aggregate_table_model::load_future_in_map);
auto inner_bind = std::bind(object_protect_bind, this);
auto loaded_callback = []
(Wt::WServer* server,
const std::string &session,
boost::function<void()> widget_bind)
-> void {
server->post(session, widget_bind, boost::function<void()>());
};
this->data_future =
std::async(std::launch::async,
table_model::load_quiet_a_bunch_of_data,
query, database, std::bind(loaded_callback, server_ptr, sessionId, inner_bind));
Wt::WTimer::singleShot(20 * 1000, this, &table_model::load_future_in_map);
Any suggestions?
Thanks to Koen Deforche in the official forum, the problem was:
Wt::WApplication::bind is supposed to take the already binded method, not the method itself.
Also there is a surprising (for me at least) template detail when using lambdas, so for the sake of an example, my solution for a callback, used by a data loading thread, is:
static std::map<decltype(views::measurements_grouped_by_orders::order_number),
order_value>
order_aggregate_table_model::async_load_order_values(
const odb::query<views::measurements_grouped_by_orders> &query,
std::shared_ptr<odb::database> mddb,
std::function<void(void)> callback) {...
if (callback){ callback(); }
return map;
}
void order_aggregate_table_model::get_data(const odb::query<views::measurements_grouped_by_orders> &query){
auto sessionId = Wt::WApplication::instance()->sessionId();
auto server_ptr = Wt::WServer::instance();
auto object_protect_bind =
Wt::WApplication::instance()->bind(/*Wt::WApplication::bind
handles the case that
the widget might already been destroyed*/
std::bind(&order_aggregate_table_model::load_future_in_map,this));
auto loaded_callback = []
(Wt::WServer* server,
const std::string &session,
std::function<void()> widget_bind)
-> void {
server->post(session, widget_bind, boost::function<void()>());
//Wt::Server::post handles the case when the session is already been destroyed
};
std::function<void()> final_callback = //Because of template quirks had to stick the type
std::bind(loaded_callback, server_ptr, sessionId, object_protect_bind);
this->order_aggregate_map_future =
std::async(std::launch::async,
order_aggregate_table_model::async_load_order_values,
query, this->mddb, final_callback);
Wt::WTimer::singleShot(30 * 1000, this,
&order_aggregate_table_model::load_future_in_map); //For the case that the async loader crashed
}

cannot convert parameter from 'PCHAR' to 'LPCWSTR'

I have defined the pointer size_Drive as :
PCHAR size_Drive ;
then i used the function lstrlen :
size_Drive += (lstrlen(size_Drive) + 1) ; (line 28)
but it gives me the following ERROR :
1>c:\users\hp.hp-pc\documents\visual studio 2008\projects\getvolumeinfo\getvolumeinfo\getvolumeinfo.cpp(28) : error C2664: 'lstrlenW' : cannot convert parameter 1 from 'PCHAR' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
PCHAR is a typedef for char whereas LPCWSTR is a typedef for const wchar_t*, and in a Unicode build lstrlen is a macro for the Unicode function lstrlenW.
You should call lstrlenA specifically to use the ANSI function.

Error 4 error C2440: 'initializing' : cannot convert from 'void *' to 'char *'

I tried to compile this and got mistakes such as:
Error 4 error C2440: 'initializing' : cannot convert from 'void *' to 'char *'
This code is taken from here. Why doesn't it work?
DWORD dwRead=0;
char *lpData = (VOID*)GlobalAlloc(GMEM_FIXED, MAX_READ),
You appear to be compiling with a C++ compiler, so you'll need an explicit cast:
char *lpData = (char *)GlobalAlloc(GMEM_FIXED, MAX_READ);

MFC CString to int

using this code i get an error at atoi's conversion from CString to int:
int nrCentrala; CString idCentrala;
GetDlgItem(IDC_EDIT_IDCENTRALA)->GetWindowText(idCentrala);
nrCentrala = atoi(&idCentrala);
where IDC_EDIT_IDCENTRALA is an edit control.
Error 7 error C2664: 'atoi' : cannot convert parameter 1 from 'CString *' to 'const char *'
CString provides an overloaded operator for LPCTSTR. Also, use _tstoi instead, just in case you're compiling with Unicode libraries, e.g.
nrCentrala = _tstoi(idCentrala);
You pass pointer to CString (CString* type) instead of const char* which is expected by atoi(). Correct call is nrCentrala = atoi(idCentrala.GetString());

Resources