Hangbot - Asimov Testgame
Re: Hangbot - Asimov Testgame
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.
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
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
Re: Hangbot - Asimov Testgame
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.
and it pulls back gibberish everytime.
I will attach my resource file.
Also in the resource.h I have this
IDR_BACKGROUND is my background image. IDR_MOVIES is my text file
If anyone could help me here I would be most grateful.
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 */
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
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
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
Re: Hangbot - Asimov Testgame
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:
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
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;
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];
ʕ •ᴥ•ʔ
Re: Hangbot - Asimov Testgame
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.
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
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
Re: Hangbot - Asimov Testgame
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.
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
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
Re: Hangbot - Asimov Testgame
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 );"
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 );"
ʕ •ᴥ•ʔ
Re: Hangbot - Asimov Testgame
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
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
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
Re: Hangbot - Asimov Testgame
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.
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 (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
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
Re: Hangbot - Asimov Testgame
use whcar_t instead of char .
Re: Hangbot - Asimov Testgame
yea i'm pretty sure the resource functions are unicode-aware so yea use wchar_t
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 --
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 --