tags:

views:

2550

answers:

6
+2  Q: 

what is pvoid

Can someone explain what pvoid is and how it is used in a function like so:

BOOL DoSomething ( PVOID pMemPhy )

+8  A: 

void pointer, same as

void *pMemPhy

aka "Pointer to something, but it's up to you to figure it out".

BOOL DoSomething ( PVOID pMemPhy )
{
    strcpy((char *)pMemPhy, "I love buffer overflows!");
    return TRUE;
}
geofftnz
+1  A: 

It sounds like it's just an alias (define or typedef) for void*. I have no idea why people think that would be better but I know some APIs like to use that in case the implementation of a type changes in future.

I know that early versions of windows used things like STDCALL as a prefix to many functions and the definition of STDCALL could change based on which version of Windows you compiled for. This is from memory (which is affected by alcohol after many years :-), so don't rely on this as gospel. It's basically correct but the details might be a little different.

paxdiablo
+1  A: 
typedef void * PVOID;

If you're question is what use is a void pointer? The most common use is when you're passing a pointer to memory that doesn't really care about type. free(), for example.

If a library exports a function that can take multiple pointer types, but wants to support languages like C that don't have funtion overloading, then void * works.

Die in Sente
+5  A: 

It's a void pointer -- a pointer to a memory address with no information about the type of the value that it is pointing to. For this reason, you must cast the pointer to a type such as (char *)pMemPhy or (int *)pMemPhy before using the pointer so that the compiler knows how much memory it's working with (1 byte for a char, 4 bytes for an int, etc.)

yjerem
@Jeremy Ruten,In this case, if it is a physical memory address, what should I cast it to?
It doesn't matter what kind of memory address it is (I'm not sure what you mean by "physical memory address"), just cast it to whatever type you want your function to treat it as. It depends on what the function wants to accomplish, but I think most of the time you would cast to (char *).
yjerem
This is an API function actually. According to description, this function opens a port on an interface card. There isn't much information available so I don't know what to make of the parameter "PVOID pMemPhy".
Oh, if all you're doing is calling that function (rather than implementing it), *you* don't need to do any casting. Just pass your pointer to the function and the function will take care of the rest. As for what the function expects you to pass to it, I can't help you with...
yjerem
+1  A: 

As others have said, it's equivalent to void *.

void pointers are often used in memory operations (memcpy, memset, etc...) since one doesn't want to assume the type of the data at the given address.

Pointers and void pointers are given a good treatment in this article from http://cplusplus.com.

Gordon Wilson
A: 

This and other mnemonic like BOOL, LPCTSTR have it origin with Windows, which BTW was developed before the existence of a C standard, and to not depend in a particular compiler it used its own types.

You can check the Old New Thing blog for more stories about to the Windows development history, and its oddities which will remain with us (http://blogs.msdn.com/oldnewthing).

Ismael