EOSERV Forum > Programming > Converting null-terminated string pointer to WORD
Topic is locked.
Page: << 1 >>
Converting null-terminated string pointer to WORD
Author Message
Post #193989 Converting null-terminated string pointer to WORD

I need to convert a null-terminated string pointer (4 byte integer if i remember correctly) into a WORD (2 byte integer) in this function:

HWND hEdit = GetDlgItem(gui_plist_dialog, IDC_LIST1); // IDC_LIST1 is the list control within the dialog.

const char * name = character->name.c_str();

SendMessage(hEdit, LB_ADDSTRING, NULL, MAKELPARAM(&name, 0));


I'm wondering just how the hell I would even do such. o_o I don't see how a pointer could even be 2 bytes on a 32 bit system. So I guess the real question is, what am I misunderstanding about this function. .-.

The function is basically supposed to add strings to a list control on a gui I'm working on.


12 years, 6 days ago
Post #193990 Re: Converting null-terminated string pointer to WORD

hmm post more code, or at-least explain

what is gui_plist_dialog&IDC_LIST1

---
Remember when is not an organization nor a fucking group , it's simply an idea that we believe in
and live for.
The priority of Remember when should come before oxygen , as oxygen is cosmetic even life itself is
cosmetic,that's why offer our worthless lives to The "Remember when"
12 years, 6 days ago
Post #193991 Re: Converting null-terminated string pointer to WORD
weedindeed posted: (8th Jun 2013, 07:55 am)

hmm post more code, or at-least explain

what is gui_plist_dialog&IDC_LIST1


#define IDC_LIST1 9052

HWND gui_plist_dialog;


IDC_LIST1 is a reference to the list control within the dialog. Every gui entity needs an id so defines make it easier to organize instead of remembering the number.

And gui_plist_dialog is like a pointer to the window/dialog if i recall correctly.


I figured out that it needs to actually be an LPARAM and I finally got it compiling, but it's not showing on the list. That might be because I forgot to update the window after though. I'll check and see.

12 years, 6 days ago
Post #193992 Re: Converting null-terminated string pointer to WORD

std::string str=character->name;

char * writable = new char[str.size() + 1];

std::copy(str.begin(), str.end(), writable);

writable[str.size()] = '\0'; 


delete[] writable; //after you finish using it


I really don't know yet what you need to perform.

---
Remember when is not an organization nor a fucking group , it's simply an idea that we believe in
and live for.
The priority of Remember when should come before oxygen , as oxygen is cosmetic even life itself is
cosmetic,that's why offer our worthless lives to The "Remember when"
12 years, 6 days ago
Post #193993 Re: Converting null-terminated string pointer to WORD

I just used c_str() to convert it to null terminated o.o

I figured out the part I posted, now i'm not sure why it's not showing. T_T

Thanks for the help though.

12 years, 6 days ago
Post #194100 Re: Converting null-terminated string pointer to WORD

I got it working

//#include <TCHAR.H> or use const char szBuf[]

TCHAR szBuf[]="Charname";    //const TCHAR  szBuf[] =character->name.c_str(); 

LONG lResult;

lResult = SendMessage( hwndEdit, LB_ADDSTRING, sizeof( szBuf ) / sizeof( szBuf[0] ), (LPARAM)szBuf );

this should add a string in the listbox otherwise you're not getting the correct handler.
Also make sure the GUI application isn't used by another program.
Might not work if you are testing it on a debug build running from the environment you're using.

---
Remember when is not an organization nor a fucking group , it's simply an idea that we believe in
and live for.
The priority of Remember when should come before oxygen , as oxygen is cosmetic even life itself is
cosmetic,that's why offer our worthless lives to The "Remember when"
12 years, 3 days ago
Post #194104 Re: Converting null-terminated string pointer to WORD

I already got it working a few days back, now I just can't seem to keep the HWND handler to the dialog box holding the list to keep from going null. It's a global variable, so it shouldn't be going null after the scope ends. I don't know why it's doing this. .-.

These are the files that contain all the gui operations:

http://pastebin.com/WDVUU3VW

http://pastebin.com/MVRHX205

12 years, 3 days ago
Post #194125 Re: Converting null-terminated string pointer to WORD

So what you're saying is that when the window is created and the player list is updated for the first time after that you can't use the update function because the handler turns null.

There is a big chance that this isn't a variable problem but :


try declaring them somewhere else with extern. ( in the header maybe)
try making them pointers variables but this will mess up all of you're functions.


Also an advice,why not create a gui in visual studio and then just send messages to it.
if you want i could help you get into this way. 


---
Remember when is not an organization nor a fucking group , it's simply an idea that we believe in
and live for.
The priority of Remember when should come before oxygen , as oxygen is cosmetic even life itself is
cosmetic,that's why offer our worthless lives to The "Remember when"
12 years, 2 days ago
Post #194128 Re: Converting null-terminated string pointer to WORD

If I declare in the header, I will get a multiple definition error since my header is used in multiple files. I also want to make it in win32 for the learning experience. I've tried delclaring it with extern in other source files though, and there was no change. This is such a strange bug. @_@

Edit:

Ah, crap I know why now. http://msdn.microsoft.com/en-us/library/windows/desktop/ms632619(v=vs.85).aspx

I was calling it in wm_create and that runs when the window is requested and before it's created.

Using WM_NCCREATE seemed to keep it from returning null, but it's still not showing anything in the dialog box.

12 years, 2 days ago
Page: << 1 >>
Topic is locked.
EOSERV Forum > Programming > Converting null-terminated string pointer to WORD