gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Tool code question.

#5296 - Saj - Thu Apr 24, 2003 7:27 pm

Hey,
This may seem off-topic but it's not because I'm going to use it in a GBA Dev Tool.
(It's a Win32 App and I'm using VC++ to create it.)

Anyways, I'm trying to get this code to work. It's from a tutorial
(http://winprog.org/tutorial/)(App part 1 and part 2)
Code:
 Edited: A big slab of code was here but I removed it for the sake of not wasting forum space.


To simplify, These are the lines I'm having problems with :-

Code:
pszFileText = GlobalAlloc(GPTR, dwFileSize + 1); // line 29 - Error here!

Code:
pszText = GlobalAlloc(GPTR, dwBufferSize); // line 67 - Error here!

Code:
if(WriteFile(hFile, pszText, dwTextLength, &dwWritten, NULL)) // line 74 - Error here!


The errors I get are :-
Code:

C:\Projects\Win\win3\win3.cpp(29) : error C2440: '=' : cannot convert from 'void *' to 'char *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
C:\Projects\Win\win3\win3.cpp(67) : error C2440: '=' : cannot convert from 'void *' to 'char *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
C:\Projects\Win\win3\win3.cpp(74) : error C2664: 'WriteFile' : cannot convert parameter 4 from 'unsigned short *' to 'unsigned long *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.

I've tried to do the first 2 casts explicitly :-
Code:
pszText = (LPSTR)GlobalAlloc(GPTR, dwBufferSize);

Will this work? I can't test it because of the (line 74) 'WriteFile' Error. :(

Please hep me to do the casts or whatever else that may fix it...
Thanks.
_________________
---------------------------------------------------
Click here to give free food to starving animals.
--------------------------------------------------


Last edited by Saj on Mon Apr 28, 2003 9:32 am; edited 3 times in total

#5297 - Saj - Thu Apr 24, 2003 7:35 pm

Never mind. I fixed it by using a Double Word instead of a Word.
Thanks anyways....
_________________
---------------------------------------------------
Click here to give free food to starving animals.
--------------------------------------------------

#5333 - Sweex - Fri Apr 25, 2003 1:14 pm

No offense (really), but think about your code real hard before posting complete slabs of code on a forum. Makes you a better programmer IMHO...

#5448 - Saj - Mon Apr 28, 2003 9:33 am

point taken sweex.

I've removed the slab of code from the original message.
_________________
---------------------------------------------------
Click here to give free food to starving animals.
--------------------------------------------------