TPU ChatChat on IRC
Internet Relay Chat?
Java Applet client
Who's on IRC?
char* = void*
Posted by Brok3n_Link [send private reply] at September 26, 2002, 11:53:35 PM hi all
getting an error on compile of a winsock program in C
uses stdio, no windows or anything fancy
szBuffer = hMem
= does not convert void* to char*
this worked fine when i had it using a win32 interface.... but does this when i' trying to convert it to console appfor use with dos.....
Posted by buzgub [send private reply] at September 27, 2002, 12:03:40 AM I suspect that szBuffer is of type char*, whereas hMem is of type void*. Your compiler does not, for some reason, like the automatic conversion between the two types - You should be able to fix it by putting in a cast to type char*.
However, you should also think about what goes into hMem - is a void* an appropriate type, or would char* be more sensible. You might want to change that instead of just using a cast.
Posted by CViper [send private reply] at September 27, 2002, 04:48:40 AM hMem sounds like an instance of an HANDLE (h prefix). You sure it points to a buffer of characters?
Posted by Brok3n_Link [send private reply] at September 27, 2002, 07:02:15 AM hMem is a HANDLE
hMem = GlobalAlloc( GHND, 32780 );
szBuffer = GlobalLock( hMem );
HANDLE is a type of void*, but as i said before, it works fine when i had the app in a window, but i'm converting it to a dos driendly, and it doesn't....
Posted by buzgub [send private reply] at September 27, 2002, 08:08:18 AM You should bear in mind that a console program != a dos program - console programs can access the win32 api, whereas dos programs (in normality) can not.
According to MSDN, GlobalLock actually returns hMem (eventually). What is your reason for calling GlobalLock? It seems to me to be unneccesary. What type is szBuffer? You can probably cast the return value of GlobalLock to the type of szBuffer, and the error should vanish. However, please do answer the other questions I've posed.
Posted by Neumann [send private reply] at September 27, 2002, 08:10:57 AM Assigning a handle to a string (sz) doesn't make sense to me, even in Windows...
You are doing, what, szBuffer = hHem, when you previously assigned szBuffer to the location point by hMem using GlobalLock...
... I really don't understand what you are trying to do. Perhaps a cast [szBuffer = (char *)hMem], would do...
Posted by CViper [send private reply] at September 28, 2002, 10:23:28 AM you probably should use GlobalAlloc( GPTR, 32780 ). that way GlobalAlloc() always (even on older OS version) returns a pointer (eg. no need to call GlobalLock()).
The way with handles was used previously to allow some memory management. Now that every app has it's virtual address space, that managment can be done anyway.
Posted by Brok3n_Link [send private reply] at September 29, 2002, 06:19:01 AM ok, some clarification...
I was trying to set fixed length char*, but I havn't used C++ for ages... thus i'm a little rusty
thanks cViper, with the removing of GlobalLock, which removed the Memory Handle problem.
Following this, i got an 9 errors and warning, unresolved externals WSACleanup() etc.
I solved this by adding the Wsock32.lb to the link pibrary options in Project>Settings
Thought it worth mentioning, cya all and thanx for you help.
Register as a new user