tapio / rlutil

C and C++ utilities for cross-platform console roguelike game creation.
http://tapio.github.com/rlutil/
229 stars 42 forks source link

Error in rlutil.h #33

Closed ghost closed 5 years ago

ghost commented 8 years ago

I'm getting an error at line 584 "WriteConsoleOutputCharacter(hConsoleOutput, str, len, csbi.dwCursorPosition, &numberOfCharsWritten);". Error shown in photo attached. image

ghost commented 8 years ago

lil halp please

refi64 commented 8 years ago

Are you compiling your program in Unicode mode? Try setting this option to "Not set".

ghost commented 8 years ago

Tried it, only got rid of the second error

refi64 commented 8 years ago

You only posted one error...

ghost commented 8 years ago

No I mean the second line in the image

nabijaczleweli commented 8 years ago

Wergh, install Gentoo.

nabijaczleweli commented 8 years ago

@BohemianRahpGod There's only one line in the picture

ghost commented 8 years ago

... there are two lines there

ghost commented 8 years ago

I'm thinking I might have setup wrong, to 'install' rlutil do I just drag the rlutil.h to the project directory with the other headers?

nabijaczleweli commented 8 years ago

There's one, wrapped, line in the picture.

nabijaczleweli commented 8 years ago

You did the setup wrong: to complete it, you must sacrifice an infant of age three to five to Krampus, our benevolent lord and saviour.

ghost commented 8 years ago

ok brb

ghost commented 8 years ago

okay the baby is dead but I'm still getting errors

nabijaczleweli commented 8 years ago

Well then, uninstall Windows and install Gentoo. Or try it with GCC on Windows (works for me).

ghost commented 8 years ago

But really how did I 'install' rlutil correctly?

nabijaczleweli commented 8 years ago

rlutil is a single-header header-only library. You put it anywhere your cimploler can find it and it works.

ghost commented 8 years ago

So what do you think the issue is if it's installed correctly

nabijaczleweli commented 8 years ago

Wrong LPCWSTR typedef, which probably means your Unicodeness macros are messed up

ghost commented 8 years ago

whut

ghost commented 8 years ago

Can you tell me what to check and what they should be?

nabijaczleweli commented 8 years ago

http://stackoverflow.com/questions/1319461/how-do-i-turn-off-unicode-in-a-vc-project

ghost commented 8 years ago

I'll look at that thanks

refi64 commented 8 years ago

Isn't that basically what I already said...

nabijaczleweli commented 8 years ago

It is, but I pasted the first result from Google

Gibgezr commented 8 years ago

Just change this line in the header file from: WriteConsoleOutputCharacter(hConsoleOutput, str, len, csbi.dwCursorPosition, &numberOfCharsWritten);

...to: WriteConsoleOutputCharacter(hConsoleOutput, (LPCWSTR)str, len, csbi.dwCursorPosition, &numberOfCharsWritten);

MangaD commented 8 years ago

How about using WriteConsoleOutputCharacterA instead of WriteConsoleOutputCharacter ?

zlyfer commented 8 years ago

How about using WriteConsoleOutputCharacterA instead of WriteConsoleOutputCharacter ?

Works perfectly! Thank you, MangaD!

MangaD commented 8 years ago

@Gibgezr

The function 'WriteConsoleOutputCharacter' calls either 'WriteConsoleOutputCharacterA' or 'WriteConsoleOutputCharacterW' depending on whether the preprocessor symbol UNICODE is defined. So your solution won't work if the ANSI version of the function is called. More info on this here: https://msdn.microsoft.com/en-us/library/windows/desktop/ff381407%28v=vs.85%29.aspx

So the solution would be using the 'WriteConsoleOutputCharacterA' function directly I believe. Otherwise you could use 'WriteConsoleOutputCharacterW' and do the conversion as you did... :)

xeekworx commented 7 years ago

This should work with or without UNICODE set. The fix is simple. Very annoying. I need to decide what to do and if I'm going to have to just make my own fork. Any update on if this will be fixed?

The simplest solution is just to use the proper version of the api call that uses multibyte, 'WriteConsoleOutputCharacterA' if you insist on using std::string regardless of the UNICODE being defined.

judooochp commented 6 years ago

Here's how I did it, with a little help from Stack Overflow: / line 578 / unsigned int len = str_.size(); *_wchar_t fixStr = new wchart[len]; for (int i = 0; i < len; i++) { fixStr[i] = str[i]; }**

else // __cplusplus

RLUTIL_INLINE void setString(RLUTIL_STRING_T str) {
    unsigned int len = strlen(str);

endif // __cplusplus

if defined(_WIN32) && !defined(RLUTIL_USE_ANSI)

    HANDLE hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    DWORD numberOfCharsWritten;
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    GetConsoleScreenBufferInfo(hConsoleOutput, &csbi);
    WriteConsoleOutputCharacter(hConsoleOutput, **_fixStr_**, len, csbi.dwCursorPosition, &numberOfCharsWritten);
judooochp commented 6 years ago

And then I read everyone else's comments, changed it to WriteConsoleOutputCharacterA() and went on about my merry life.