what is PVOID ??

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.)
link
| improve this answer
answered 
Jan 30 '09 at 1:27
Jeremy Ruten
26.4k

35
95
@Jeremy Ruten, In this case, if it is a physical memory address, what should I cast it to? – 
llang 
Jan 30 '09 at 1:35
 
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 *). –  Jeremy Ruten 
Jan 30 '09 at 1:37
 
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". – 
llang 
Jan 30 '09 at 1:47
 
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... –  Jeremy Ruten 
Jan 30 '09 at 2:02
 
up vote
1 down vote
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.
link
| improve this answer
answered 
Jan 30 '09 at 1:25
paxdiablo
167k
십구
212
518
 
feedback
up vote
1 down vote
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.
link
| improve this answer
answered 
Jan 30 '09 at 1:27
Die in Sente
2,682

십팔
 
feedback
up vote
1 down vote
As others have said, it's equivalent to  void * . void  pointers are often used in memory operations ( memcpymemset , 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.
link
| improve this answer
answered 
Jan 30 '09 at 1:32
Gordon Wilson
7,287

24
43
 
feedback
up vote
0 down vote
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).

좋은 웹페이지 즐겨찾기