Hangbot - Asimov Testgame

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Hangbot - Asimov Testgame

Post by Asimov » July 2nd, 2013, 8:25 pm

Hi all,

Well after successfully loading a picture from resources I am now trying to load text from a resource file. I have tried some code, which doesn't crash LOL, but I am not quite there yet heh heh.
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Hangbot - Asimov Testgame

Post by Asimov » July 2nd, 2013, 11:32 pm

Hi all,

Well I am officially stuck. Don't get me wrong I know how to load a text file from a file, no problem there, but I am totally stuck loading from my res or resource file. I thought compared to an image it would be easy. I have tried various incarnations of the following code.

Code: Select all

HGLOBAL     res_handle = hInstance;
    HRSRC       res;
    char *      res_data;
    DWORD       res_size;

    // NOTE: providing g_hInstance is important, NULL might not work
    res = FindResource(hInstance, MAKEINTRESOURCE(IDR_MOVIES), RT_RCDATA);
    if (!res)
        return;
    res_handle = LoadResource(hInstance, res);
    if (!res_handle)
        return;
    res_data = (char*)LockResource(res_handle);
    res_size = SizeofResource(NULL, res);
    /* you can now use the resource data */
and it pulls back gibberish everytime.

I will attach my resource file.

Also in the resource.h I have this

Code: Select all

#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif

#define IDR_BACKGROUND								1
#define IDR_MOVIES									2
IDR_BACKGROUND is my background image. IDR_MOVIES is my text file

If anyone could help me here I would be most grateful.
Attachments
hangbotRC.zip
(311.92 KiB) Downloaded 204 times
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Hangbot - Asimov Testgame

Post by LuX » July 3rd, 2013, 12:46 am

Odd... I managed to make a resource, send it to another .exe and store it there, then load the text resource from the other .exe. In short this is what I used for loading the text:

Code: Select all

	HRSRC hRes = FindResource(hInst, MAKEINTRESOURCE(THE_TEXT), L"TXT"); // <- make sure it's the type you specify it to be...
	HGLOBAL hMem = LoadResource(hInst, hRes);
	DWORD size = SizeofResource(hInst, hRes);
	char* resText = (char*)LockResource(hMem);
	char* text = (char*)malloc(size + 1);
	memcpy(text, resText, size);
	text[size] = 0;
Btw, just finished loading 3D models in directx. A cube and ball for now, I'll have to practice Blender a bit more before I can make more advanced models. Kinda fun actually.

Took a while to figure out uv texture mapping.

Hang on. Now that I look at my code it seems I might have had some problems too, I forget. It should at least work like this, so the above code, then:

Code: Select all

void* lockedRes = LockResource(hMem);

// Now use this for the first char, for example:
char firstChar = ((char*)lockedRes)[0];
ʕ •ᴥ•ʔ

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Hangbot - Asimov Testgame

Post by Asimov » July 3rd, 2013, 2:57 pm

Hi Lux,

Thanks. I will try this code after my tea, cos I am starving heh heh.
I have never tried blender, but I have seen some good stuff from it. I mainly use 3ds max and mudbox for modelling. Also photoshop, and illustrator for texturing.

If you ever decide to use 3d max, I have a lot of tutorials that might help you.

BTW my goal is to get to 3D eventually. As I want to port my 3D XNA game over, but it looks a tad daunting.
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Hangbot - Asimov Testgame

Post by Asimov » July 3rd, 2013, 4:57 pm

Hi Lux,

Well I am still stumped. At first the code worked without error, but didn't give me the result I was after. So I used a messagebox, and now it crashes LOL.

So I have attached the whole thing. You will know where the code is as it crashes in the right place LOL, but it is in the Dict.cpp.

I am thinking of putting about 20,000 words into the exe LOL, so I want to do it in a text file, rather than type them all into the program.

The only thing I changed to make it work was hIinst, as mine is called hInstance.

BTW the first word in the text file is "Shrek", so the character should bring back S, but it doesn't.
Attachments
09_Hangbot Textfile test.zip
(7.8 MiB) Downloaded 193 times
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Hangbot - Asimov Testgame

Post by LuX » July 3rd, 2013, 7:45 pm

The problem is you loaded it as "RC Data" and not "TXT". Do this: in Resource editor load the text file with "Import user resource" not "Import RC Data" and then it works. Remember to change the ID from "TEXT" to some number.

I tried it with the message box but the text won't show up. No worries tho; if you use something like "if ( firstChar == 'S' ) exit ( 0 );" it works closes the program as intended. If you change the 'S' to something else it wont exit. Simple and proves it did load properly.

In fact the "text" array should work as well so you can forget the lockedRes stuff. "if ( text[0] == 'S' ) exit ( 0 );"
ʕ •ᴥ•ʔ

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Hangbot - Asimov Testgame

Post by Asimov » July 3rd, 2013, 8:45 pm

Hi Lux,

I was starting to suspect it wasn't the program that was wrong. To be honest I don't really know what RC data is. All I know is that I have to do that with image files. Right gonna try what you said now.

If I can get one letter to read, perhaps I can work out how to read the rest LOL.

Thanks
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

Re: Hangbot - Asimov Testgame

Post by Asimov » July 3rd, 2013, 8:58 pm

Hi Lux,

Partial success, except that firstChar does not seem to hold the first character. However I put a break point in and read resText and indeed that was set to S.

Now all I gotta work out is how to get more than one character. I presume lockedRes holds the entire file of text, but I am not sure how to read it at present.

Anyway at least you got me on the right track.
Thanks.
Attachments
S.jpg
S.jpg (83.02 KiB) Viewed 3705 times
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

Shaki
Posts: 104
Joined: June 13th, 2012, 12:20 am

Re: Hangbot - Asimov Testgame

Post by Shaki » July 4th, 2013, 12:48 am

use whcar_t instead of char :).

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: Hangbot - Asimov Testgame

Post by LuisR14 » July 4th, 2013, 5:12 am

yea i'm pretty sure the resource functions are unicode-aware so yea use wchar_t :P
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat :mrgreen: --

Post Reply