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

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
}

Related

Really impossible to make package with Theos

I really don't manage to "make package" with Theos for a Tweak made by me, so I copied the "unlockchanger" example on the web (here https://github.com/codyd51/Theos-Examples/tree/master/unlockchanger ) and tried to do "make package". I get these errors:
iPhone-di-Gabriele:/var/mobile/unlockchanger root# make package
/var/mobile/unlockchanger/theos/makefiles/targets/Darwin-arm/iphone.mk:43: Targeting iOS 4.0 and higher is not supported with iphone-gcc. Forcing clang.
/var/mobile/unlockchanger/theos/makefiles/targets/Darwin-arm/iphone.mk:53: Deploying to iOS 3.0 while building for 6.0 will generate armv7-only binaries.
Making all for tweak UnlockChanger...
Preprocessing Tweak.xm...
Compiling Tweak.xm...
In file included from Tweak.xm:3:
/var/mobile/unlockchanger/theos/include/substrate.h:57:20: error: unknown type name 'pid_t'
bool MSHookProcess(pid_t pid, const char *library);
^
/var/mobile/unlockchanger/theos/include/substrate.h:69:1: error: unknown type name 'IMP'
IMP MSHookMessage(Class _class, SEL sel, IMP imp, const char *prefix _default(NULL));
^
/var/mobile/unlockchanger/theos/include/substrate.h:69:42: error: unknown type name 'IMP'
IMP MSHookMessage(Class _class, SEL sel, IMP imp, const char *prefix _default(NULL));
^
/var/mobile/unlockchanger/theos/include/substrate.h:69:79: error: use of undeclared identifier 'NULL'
IMP MSHookMessage(Class _class, SEL sel, IMP imp, const char *prefix _default(NULL));
^
/var/mobile/unlockchanger/theos/include/substrate.h:48:27: note: expanded from macro '_default'
#define _default(value) = value
^
/var/mobile/unlockchanger/theos/include/substrate.h:71:45: error: unknown type name 'IMP'
void MSHookMessageEx(Class _class, SEL sel, IMP imp, IMP *result);
^
/var/mobile/unlockchanger/theos/include/substrate.h:71:54: error: unknown type name 'IMP'
void MSHookMessageEx(Class _class, SEL sel, IMP imp, IMP *result);
^
/var/mobile/unlockchanger/theos/include/substrate.h:125:92: error: use of undeclared identifier 'NULL'
static inline Type_ *MSHookMessage(Class _class, SEL sel, Type_ *imp, const char *prefix = NULL) {
^
/var/mobile/unlockchanger/theos/include/substrate.h:126:82: error: unknown type name 'IMP'
return reinterpret_cast<Type_ *>(MSHookMessage(_class, sel, reinterpret_cast<IMP>(imp), prefix));
^
/var/mobile/unlockchanger/theos/include/substrate.h:132:58: error: unknown type name 'IMP'
return MSHookMessageEx(_class, sel, reinterpret_cast<IMP>(imp), reinterpret_cast<IMP *>(result));
^
/var/mobile/unlockchanger/theos/include/substrate.h:132:86: error: unknown type name 'IMP'
return MSHookMessageEx(_class, sel, reinterpret_cast<IMP>(imp), reinterpret_cast<IMP *>(result));
^
/var/mobile/unlockchanger/theos/include/substrate.h:137:5: error: use of undeclared identifier 'Ivar'
Ivar ivar(class_getInstanceVariable(object_getClass(self), name));
^
/var/mobile/unlockchanger/theos/include/substrate.h:138:19: error: use of undeclared identifier 'ivar'
void *pointer(ivar == NULL ? NULL : reinterpret_cast<char *>(self) + ivar_getOffset(ivar));
^
/var/mobile/unlockchanger/theos/include/substrate.h:138:27: error: use of undeclared identifier 'NULL'
void *pointer(ivar == NULL ? NULL : reinterpret_cast<char *>(self) + ivar_getOffset(ivar));
^
/var/mobile/unlockchanger/theos/include/substrate.h:138:34: error: use of undeclared identifier 'NULL'
void *pointer(ivar == NULL ? NULL : reinterpret_cast<char *>(self) + ivar_getOffset(ivar));
^
/var/mobile/unlockchanger/theos/include/substrate.h:138:89: error: use of undeclared identifier 'ivar'
void *pointer(ivar == NULL ? NULL : reinterpret_cast<char *>(self) + ivar_getOffset(ivar));
^
/var/mobile/unlockchanger/theos/include/substrate.h:294:71: error: use of undeclared identifier 'NULL'
return MSHookFunction(symbol, replace, reinterpret_cast<Type_ **>(NULL));
^
/var/mobile/unlockchanger/theos/include/substrate.h:298:85: error: use of undeclared identifier 'NULL'
static inline void MSHookSymbol(Type_ *&value, const char *name, MSImageRef image = NULL) {
^
/var/mobile/unlockchanger/theos/include/substrate.h:303:86: error: use of undeclared identifier 'NULL'
static inline void MSHookFunction(const char *name, Type_ *replace, Type_ **result = NULL) {
^
/var/mobile/unlockchanger/theos/include/substrate.h:310:104: error: use of undeclared identifier 'NULL'
static inline void MSHookFunction(MSImageRef image, const char *name, Type_ *replace, Type_ **result = NULL) {
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [obj/Tweak.xm.7838be1a.o] Error 1
make[1]: *** [internal-library-all_] Error 2
make: *** [UnlockChanger.all.tweak.variables] Error 2
Some detail:
I'm on iOS8.1, with an iPhone 5. Everything installed from Cydia
..and on Windows 8.1 with WinSCP and PuTTY
I've installed Theos, Perl.. everything (Also "BigBoss recommended packages")
I had to install also LLVM+Clang because make didn't find a "clang++" command
I've tried to dump classes, instead of taking them from the web
I've updated substrate.h in /include/ and libsubstrate.dylib in /lib/
If I try to "make package" on my tweak for SpringBoard, where in Tweak.xm I do:
#import <SpringBoard/Springboard.h>
I get these errors:
iPhone-di-Gabriele:/var/mobile/mytweak root# make package
/var/mobile/mytweak/theos/makefiles/targets/Darwin-arm/iphone.mk:43: Targeting iOS 4.0 and higher is not supported with iphone-gcc. Forcing clang.
/var/mobile/mytweak/theos/makefiles/targets/Darwin-arm/iphone.mk:53: Deploying to iOS 3.0 while building for 6.0 will generate armv7-only binaries.
Making all for tweak mytweak...
Preprocessing Tweak.xm...
Compiling Tweak.xm...
In file included from Tweak.xm:1:
/var/mobile/mytweak/theos/include/SpringBoard.h:33:19: error: field has incomplete type 'struct CGSize'
struct CGSize size;
^
/var/mobile/mytweak/theos/include/SpringBoard.h:33:12: note: forward declaration of 'CGSize'
struct CGSize size;
^
/var/mobile/mytweak/theos/include/SpringBoard.h:229:34: error: cannot find protocol declaration for 'NSObject'
#protocol APSConnectionDelegate <NSObject>
^
/var/mobile/mytweak/theos/include/SpringBoard.h:233:37: error: cannot find protocol declaration for 'NSObject'
#protocol AVExternalDeviceDelegate <NSObject>
^
/var/mobile/mytweak/theos/include/SpringBoard.h:236:27: error: cannot find protocol declaration for
'BBSectionIdentity'
#protocol BBDataProvider <BBSectionIdentity>
^
/var/mobile/mytweak/theos/include/SpringBoard.h:240:31: error: cannot find protocol declaration for 'NSObject'
#protocol BBObserverDelegate <NSObject>
^
/var/mobile/mytweak/theos/include/SpringBoard.h:246:30: error: cannot find protocol declaration for 'NSObject'
#protocol BBSectionIdentity <NSObject>
^
/var/mobile/mytweak/theos/include/SpringBoard.h:250:41: error: cannot find protocol declaration for 'NSObject'
#protocol BSSettingDescriptionProvider <NSObject>
^
/var/mobile/mytweak/theos/include/SpringBoard.h:255:34: error: cannot find protocol declaration for 'NSObject'
#protocol BSTransactionObserver <NSObject>
^
/var/mobile/mytweak/theos/include/SpringBoard.h:258:31: error: cannot find protocol declaration for 'NSObject'
#protocol BSWatchdogDelegate <NSObject>
^
/var/mobile/mytweak/theos/include/SpringBoard.h:261:38: error: cannot find protocol declaration for 'NSObject'
#protocol CLLocationManagerDelegate <NSObject>
^
/var/mobile/mytweak/theos/include/SpringBoard.h:264:41: error: cannot find protocol declaration for 'NSObject'
#protocol FBApplicationLibraryObserver <NSObject>
^
/var/mobile/mytweak/theos/include/SpringBoard.h:267:45: error: cannot find protocol declaration for 'NSObject'
#protocol FBApplicationPlaceholderObserver <NSObject>
^
/var/mobile/mytweak/theos/include/SpringBoard.h:270:41: error: cannot find protocol declaration for
'FBProcessObserver'
#protocol FBApplicationProcessObserver <FBProcessObserver>
^
/var/mobile/mytweak/theos/include/SpringBoard.h:276:37: error: cannot find protocol declaration for 'NSObject'
#protocol FBDisplayManagerObserver <NSObject>
^
/var/mobile/mytweak/theos/include/SpringBoard.h:279:37: error: cannot find protocol declaration for 'NSObject'
#protocol FBProcessManagerObserver <NSObject>
^
/var/mobile/mytweak/theos/include/SpringBoard.h:284:30: error: cannot find protocol declaration for 'NSObject'
#protocol FBProcessObserver <NSObject>
^
/var/mobile/mytweak/theos/include/SpringBoard.h:287:35: error: cannot find protocol declaration for 'NSObject'
#protocol FBSceneManagerDelegate <NSObject>
^
/var/mobile/mytweak/theos/include/SpringBoard.h:293:35: error: cannot find protocol declaration for 'NSObject'
#protocol FBSceneManagerObserver <NSObject>
^
/var/mobile/mytweak/theos/include/SpringBoard.h:302:46: error: cannot find protocol declaration for 'NSObject'
#protocol FBSynchronizedTransactionDelegate <NSObject>
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [obj/Tweak.xm.0ad6af3a.o] Error 1
make[1]: *** [internal-library-all_] Error 2
make: *** [mytweak.all.tweak.variables] Error 2
I really don't know where is the mistake, I really tried everything, also "make -i" but it doesn't create the dylib file!
Also using my dumped headers, for SpringBoard, I get:
iPhone-di-Gabriele:/var/mobile/test root# make package
/var/mobile/test/theos/makefiles/targets/Darwin-arm/iphone.mk:43: Targeting iOS 4.0 and higher is not supported with iphone-gcc. Forcing clang.
/var/mobile/test/theos/makefiles/targets/Darwin-arm/iphone.mk:53: Deploying to iOS 3.0 while building for 6.0 will generate armv7-only binaries.
Making all for tweak test...
Preprocessing Tweak.xm...
Compiling Tweak.xm...
In file included from Tweak.xm:1:
In file included from /var/mobile/test/theos/include/SpringBoard/SpringBoard.h:9:
In file included from /var/mobile/test/theos/include/SpringBoard/SBBannerContainerViewController.h:8:
In file included from /var/mobile/test/theos/include/SpringBoard/UIViewControllerAnimatedTransitioning.h:8:
In file included from /var/mobile/test/theos/include/SpringBoard/NSObject.h:8:
/var/mobile/test/theos/include/SpringBoard/SpringBoard-Structs.h:26:2: error:
unknown type name 'BOOL'
BOOL _field1;
^
/var/mobile/test/theos/include/SpringBoard/SpringBoard-Structs.h:27:2: error:
unknown type name 'BOOL'
BOOL _field2;
^
/var/mobile/test/theos/include/SpringBoard/SpringBoard-Structs.h:28:2: error:
unknown type name 'BOOL'
BOOL _field3;
^
/var/mobile/test/theos/include/SpringBoard/SpringBoard-Structs.h:29:2: error:
unknown type name 'BOOL'
BOOL _field4;
^
/var/mobile/test/theos/include/SpringBoard/SpringBoard-Structs.h:30:2: error:
unknown type name 'BOOL'
BOOL _field5;
^
/var/mobile/test/theos/include/SpringBoard/SpringBoard-Structs.h:66:2: error:
unknown type name 'BOOL'
BOOL itemIsEnabled[25];
^
/var/mobile/test/theos/include/SpringBoard/SpringBoard-Structs.h:67:2: error:
unknown type name 'BOOL'
BOOL timeString[64];
^
/var/mobile/test/theos/include/SpringBoard/SpringBoard-Structs.h:70:2: error:
unknown type name 'BOOL'
BOOL serviceString[100];
^
/var/mobile/test/theos/include/SpringBoard/SpringBoard-Structs.h:71:2: error:
unknown type name 'BOOL'
BOOL serviceCrossfadeString[100];
^
/var/mobile/test/theos/include/SpringBoard/SpringBoard-Structs.h:72:2: error:
unknown type name 'BOOL'
BOOL serviceImages[2][100];
^
/var/mobile/test/theos/include/SpringBoard/SpringBoard-Structs.h:73:2: error:
unknown type name 'BOOL'
BOOL operatorDirectory[1024];
^
/var/mobile/test/theos/include/SpringBoard/SpringBoard-Structs.h:80:2: error:
unknown type name 'BOOL'
BOOL batteryDetailString[150];
^
/var/mobile/test/theos/include/SpringBoard/SpringBoard-Structs.h:86:2: error:
unknown type name 'BOOL'
BOOL activityDisplayId[256];
^
/var/mobile/test/theos/include/SpringBoard/SpringBoard-Structs.h:102:2: error:
unknown type name 'BOOL'
BOOL _field3[4088];
^
/var/mobile/test/theos/include/SpringBoard/SpringBoard-Structs.h:116:2: error:
unknown type name 'BOOL'
BOOL __opaque[40];
^
/var/mobile/test/theos/include/SpringBoard/SpringBoard-Structs.h:162:2: error:
unknown type name 'BOOL'
BOOL valid;
^
/var/mobile/test/theos/include/SpringBoard/SpringBoard-Structs.h:179:2: error:
unknown type name 'BOOL'
BOOL isValid;
^
In file included from Tweak.xm:1:
In file included from /var/mobile/test/theos/include/SpringBoard/SpringBoard.h:9:
In file included from /var/mobile/test/theos/include/SpringBoard/SBBannerContainerViewController.h:8:
In file included from /var/mobile/test/theos/include/SpringBoard/UIViewControllerAnimatedTransitioning.h:8:
/var/mobile/test/theos/include/SpringBoard/NSObject.h:10:1: error: redefinition
of 'NSString' as different kind of symbol
#class NSString;
^
/var/mobile/test/theos/include/SpringBoard/SpringBoard-Structs.h:135:3: note:
previous definition is here
} NSString;
^
In file included from Tweak.xm:1:
In file included from /var/mobile/test/theos/include/SpringBoard/SpringBoard.h:9:
In file included from /var/mobile/test/theos/include/SpringBoard/SBBannerContainerViewController.h:8:
In file included from /var/mobile/test/theos/include/SpringBoard/UIViewControllerAnimatedTransitioning.h:8:
/var/mobile/test/theos/include/SpringBoard/NSObject.h:24:3: error: expected a
type
-(BOOL)respondsToSelector:(SEL)selector;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [obj/Tweak.xm.56f06e0e.o] Error 1
make[1]: *** [internal-library-all_] Error 2
make: *** [test.all.tweak.variables] Error 2
Thank you to everyone who wants to help me.
If you get these errors, make sure you have not extracted, or copied SDK folder (iPhoneOSX.X.sdk) on Windows, because in this way you will lose every (symbolic) link between sdk's files. So manage and organize your sdk folder on Mac OS, iOS or Linux (but I didn't tried on this one).
Good Luck!

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

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);

Compilation errors when changing from winsock.h to winsock2.h

I am working on a project where I have to support IPv6 addressing scheme. This requires me to replace winsock.h with winsock2.h to make IP-version independent calls. Initially, I faced redefinition related errors which I could remove by employing solutions available online (placing #include <winsock2.h> before #include <windows.h>; including #define_WINSOCKAPI_). However, I am still getting errors like:
2>../include\obsocket.h(171) : error C2143: syntax error : missing '}' before 'constant'
2>../include\obsocket.h(171) : error C2059: syntax error : 'constant'
2>../include\obsocket.h(171) : error C2143: syntax error : missing ';' before '}'
2>../include\obsocket.h(171) : error C2238: unexpected token(s) preceding ';'
2>../include\obsocket.h(173) : error C2065: 'ShutdownType' : undeclared identifier
2>../include\obsocket.h(177) : error C2146: syntax error : missing ';' before identifier 'GetDescriptor'
2>../include\obsocket.h(177) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
2>../include\obsocket.h(177) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
2>../include\obsocket.h(177) : error C2065: '_sock' : undeclared identifier
2>../include\obsocket.h(179) : error C2065: '_timeout' : undeclared identifier
2>../include\obsocket.h(180) : error C2065: '_use_blocking_calls' : undeclared identifier
2>../include\obsocket.h(181) : error C2065: '_req_pending' : undeclared identifier
2>../include\obsocket.h(185) : error C2270: 'ToString' : modifiers not allowed on nonmember functions
2>../include\obsocket.h(187) : error C2059: syntax error : 'private'
2>../include\obsocket.h(189) : error C2146: syntax error : missing ';' before identifier '_sock'
2>../include\obsocket.h(189) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
2>../include\obsocket.h(189) : error C2086: 'int SOCK_TYPE' : redefinition
2>../include\obsocket.h(177) : see declaration of 'SOCK_TYPE'
2>../include\obsocket.h(189) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
2>../include\obsocket.h(189) : error C2371: '_sock' : redefinition; different basic types
2>../include\obsocket.h(199) : error C2371: '_use_blocking_calls' : redefinition; different basic types
2>../include\obsocket.h(200) : error C2371: '_timeout' : redefinition; different basic types
2>../include\obsocket.h(201) : error C2371: '_req_pending' : redefinition; different basic types
2>../include\obsocket.h(203) : error C2146: syntax error : missing ')' before identifier 'sock'
2>../include\obsocket.h(203) : error C2146: syntax error : missing ';' before identifier 'sock'
2>../include\obsocket.h(203) : error C2371: 'SOCK_TYPE' : redefinition; different basic types
I've made sure that winsock.h is not getting included anywhere during the build (by enabling show includes during the build).
Here is the code for obsocket.h:
#ifndef _obsocket_h
#define _obsocket_h
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
//#include <winsock.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#endif
class ObSocket {
public:
#ifdef _WIN32
typedef SOCKET SOCK_TYPE;
#else
typedef int SOCK_TYPE;
#endif
ObSocket();
~ObSocket();
enum ShutdownType { SD_INCOMING = 0, SD_OUTGOING = 1, SD_BOTH = 2 };
ObStatus Shutdown(ShutdownType);
ObStatus Close();
bool IsValid();
SOCK_TYPE GetDescriptor() { return _sock; }
void NonBlocking(int timeout);
inline int GetTimeout( ) { return _timeout; }
inline bool IsBlocking( ) { return _use_blocking_calls; }
inline int IncPendingReq(int i = 1) { _req_pending += i; return _req_pending; }
inline int DecPendingReq(int i = 1) { _req_pending -= i; return _req_pending; }
inline int GetPendingReq( ) { return _req_pending; }
ObString& ToString(ObString& strClass) const;
private:
SOCK_TYPE _sock;
ObInetAddress _addr;
char _my_addr[20];
in_port_t _my_port;
char _remote_addr[20];
in_port_t _remote_port;
bool _use_blocking_calls;
int _timeout;
int _req_pending;
ObSocket(SOCK_TYPE sock);
void SetAddr(sockaddr_in& inAddr, const ObInetAddress& addr, in_port_t port);
void ReallocFileDescriptor();
ObSocket(const ObSocket&);
ObSocket& operator=(const ObSocket&);
static void Initialize();
static void Finalize();
};
Can anyone help in pointing out what could be going wrong?

Gl3w compilation errors: invalid conversion from 'PROC ... to void*'

Setting up gl3w in my computer: 2 errors that I have no idea how to resolve are being thrown:
Function that's built by Gl3w script which has the errors:
static void *get_proc(const char *proc) - line 19
{
void *res;
res = wglGetProcAddress(proc); - line 23, first error
if (!res)
res = GetProcAddress(libgl, proc); - line 25, second error
return res;
}
Build errors:
||=== LearnOPG, Debug ===|
C:\CodeBlocks\LearnOPG\gl3w.c||In function 'void* get_proc(const char*)':|
C:\CodeBlocks\LearnOPG\gl3w.c|23|error: invalid conversion from 'PROC {aka int (__attribute__((__stdcall__)) *)()}' to 'void*' [-fpermissive]|
C:\CodeBlocks\LearnOPG\gl3w.c|25|error: invalid conversion from 'FARPROC {aka int (__attribute__((__stdcall__)) *)()}' to 'void*' [-fpermissive]|
||=== Build finished: 2 errors, 0 warnings (0 minutes, 0 seconds) ===|
Some compilers/platforms are less picky than others. Implicitly converting function pointers to void* and back is not guaranteed to be possible by C or C++. But GL3W's code expects it to work; obviously, it was not tested with more strict compilers/platforms.
You should probably file a bug report on it with the GL3W people. Granted, it doesn't seem to be being actively worked on, but they might fix it.

error C2146 and C4430

First: sorry my bad English =((
Sencond:
here's my code in "Global.h":
#pragma once
class GlobalVariable
{
public:
GlobalVariable(void);
~GlobalVariable(void);
//------------------------------------------------
public:
double pixelWidth; // do rong cua 1 pixel tren Viewport
double pixelHeigh; // do cao cua 1 pixel tren Viewport
public:
Point oldPoint, tempPoint;
Circle oldCir, tempCir;
DaGiac oldDaGiac, tempDaGiac;
Color oldObjColor,tempObjColor, OxyColor;
};
class Point
{
public:
Point(void);
~Point(void);
double x,y; // toạ độ (x,y)
};
class Color
{
public:
Color(void);
~Color(void);
double R,G,B; // màu (R,G,B)
};
class DaGiac
{
public:
DaGiac(void);
~DaGiac(void);
int numOfPeak; //so' dinh?
Point peakArr[10]; // ve da giac canh so dinh toi da la 10
};
class Circle
{
public:
Circle(void);
~Circle(void);
Point centre;
double radius;
};
and I have some eror :(
------ Build started: Project: GAS, Configuration: Debug Win32 ------
Compiling...
GlobalVariable.cpp
e:\documents\bin\gas_project\globalvariable.h(15) : error C2146: syntax error : missing ';' before identifier 'oldPoint'
e:\documents\bin\gas_project\globalvariable.h(15) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(15) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(15) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(16) : error C2146: syntax error : missing ';' before identifier 'oldCir'
e:\documents\bin\gas_project\globalvariable.h(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(17) : error C2146: syntax error : missing ';' before identifier 'oldDaGiac'
e:\documents\bin\gas_project\globalvariable.h(17) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(17) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(17) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(18) : error C2146: syntax error : missing ';' before identifier 'oldObjColor'
e:\documents\bin\gas_project\globalvariable.h(18) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(18) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(18) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
e:\documents\bin\gas_project\globalvariable.h(18) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Build log was saved at "file://e:\Documents\BIN\GAS_Project\Debug\BuildLog.htm"
GAS - 17 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
But after I delete the GlobalVariable class! Only class Point, Color, DaGiac, Circle exist! It has no eror!
Tell me why? And how to corect that error ? Please =((
The compiler can't "see" the other classes, because they're defined after the GlobalVariable class. Move the whole GlobalVariable class to the bottom of the file so that all of the classes it depends on will be defined when it needs them.

Resources