Page 1 of 1

Mapping C++ data types mentioned in MSDN library

Posted: Wed Feb 03, 2010 10:45 am
by magna
I`m trying to write a small app which allows to create declarations for DLL functions from a header file.

Currently I`m concentrating on the definitions of functions as you can find them in the MSDN Library (http://msdn.microsoft.com/en-us/library/) in order to create libraries for windows DLLs like kernel.dll, user32.dll, advapi32.dll and so on. These definitions look like:

LONG WINAPI RegCreateKey(
 __in      HKEY hKey,
 __in_opt  LPCTSTR lpSubKey,
 __out     PHKEY phkResult
);

Now I need to map the C++ data types to FNX-Basic data types. I got so far for now, but know nearly nothing about C++.

`===============================================================================
`==
`            FNX knows these types:
`            BOOLEAN, BYTE, DOUBLE, INTEGER, LONG, SHORT, SINGLE, STRING, WORD
FUNCTION ConvertDataType(strIn AS STRING) AS STRING

     SELECT CASE UCASE$(strIn)

           `=========================================================================
           ` BOOLEAN
           `=========================================================================

           CASE "BOOL":                                                            Result="BOOLEAN"

           `=========================================================================
           ` BYTE
           `=========================================================================

           CASE "BYTE":                                                            Result="BYTE"
           CASE "LPBYTE":                                                      Result="BYTE"

           `=========================================================================
           ` DOUBLE
           `=========================================================================

           ` a C double variable takes eight bytes

           `=========================================================================
           ` INTEGER
           `=========================================================================

           CASE "UINT":                                                            Result="INTEGER"

           ` DWORD: 4-Byte-Ganzzahl
           ` see http://msdn.microsoft.com/de-de/library/cc431203.aspx
           CASE "DWORD":                                                            Result="INTEGER"
           ` probably an integer
           CASE "LPDWORD":                                                      Result="INTEGER"
           ` integer as per example
           CASE "HKEY":                                                            Result="INTEGER"
           ` probably an integer
           CASE "PHKEY":                                                            Result="INTEGER"

           `=========================================================================
           ` LONG (aka INTEGER)
           `=========================================================================

           ` probably a long
           CASE "LONG":                                                            Result="LONG"
           ` probably a long
           CASE "PLONG":                                                            Result="LONG"

           `=========================================================================
           ` STRING
           `=========================================================================

           ` probably a string
           CASE "LPTSTR":                                                      Result="STRING"
           ` LPCTSTR: Long Pointer to a Constant null-Terminated String
           ` see http://acronyms.thefreedictionary.com/LPCTSTR
           CASE "LPCTSTR":                                                      Result="STRING"

           `=========================================================================
           ` UNKNOWN
           `=========================================================================

           `CASE "PVOID":                                                      Result=""
           `CASE "LPVOID":                                                      Result=""
           `CASE "LPCVOID":                                                Result=""
           `CASE "HANDLE":                                                      Result=""
           `CASE "LPSECURITY_ATTRIBUTES":      Result=""
           `CASE "PFILETIME":                                          Result=""
           `CASE "PVALENT":                                                Result=""
           `CASE "REGSAM":                                                      Result=""

           CASE strIn:                                                                  Result=strIn
                 Debug("data type `"+strIn+"` can not be converted")

     END SELECT

END FUNCTION

I assume that the C++ data types mentioned here are self defined (wrapper) types cause they are all uppercase while native C++ would be lowercase, right?

Can anyone help me to map the remaining types or give me a hint where I can find an overview of the data types which are used here?

Finally: what does "WINAPI" in the function header mean? I have no clue!

Mapping C++ data types mentioned in MSDN library

Posted: Thu Feb 04, 2010 7:00 pm
by fred
The data types are Windows data types, see http://msdn.microsoft.com/en-us/library/aa383751(VS.85).aspx

The L and LP are pointer types.
From the old help file: "If at the claim an address must pass on to become of a variable then happens that by means of the statement byaddress, for example: dim mystring as string byaddress."
So something like this: LPCTSTR lpExistingFileName
is used as: lpExistingFileName as string byaddress

WINAPI is just the way how windows calls the function, who responsible is for removing the parameters from stack, the function or who called the function.
http://www.programmersheaven.com/2/Calling-conventions

Mapping C++ data types mentioned in MSDN library

Posted: Thu Feb 04, 2010 9:34 pm
by magna
The overview of "Windows Data Types" (http://msdn.microsoft.com/en-us/library/aa383751(VS.85).aspx) was exactly what I was looking for. Thank you for this link!

Concerning calling conventions I also found "Using Win32 calling conventions" (http://unixwiz.net/techtips/win32-callconv.html) and "Reading C type declarations" (http://unixwiz.net/techtips/reading-cdecl.html).

My only question now ist how to map e.g. VOID.

Mapping C++ data types mentioned in MSDN library

Posted: Fri Feb 05, 2010 9:43 am
by fred
Glad to help :)
The type VOID  is defined as void.
void is an empty/type less datatype used for functions who returns nothing or for pointers with a unknown data type so the void *pointers can be used for all types, like char * and int * pointers.

See also http://crasseux.com/books/ctutorial/void.html

Fnxbasic has no pointers except the byaddress keyword and here a type must be used.


Mapping C++ data types mentioned in MSDN library

Posted: Fri Feb 05, 2010 11:25 pm
by magna
The link you stated last says: "A void pointer is a generic pointer; any pointer can be cast to a void pointer and back without any loss of information."

I think this makes it impossible to map it to a FNX data type. Nonetheless I got so far:

<edit>
oups ... any post is limited to 5500 chars, so I have to post my solution in the files forum ...

http://fnxbasic.com/yabb/YaBB.pl?num=1265412311/0#0

The relevant function is called ConvertDataType().