Solved

Need typedef's for a few win32 funcs

Posted on 2002-05-24
10
577 Views
Last Modified: 2008-02-01
I need typedef's for the following win32 funcs (ANSI) as vanilla as possible since the code may be compiled on a variety of C/++ compilers:

Example:
========
typedef void (__stdcall *LPFUNCGETLOCALTIME)LPSYSTEMTIME);
LPFUNCGETLOCALTIME ptrGetLocalTime;

Need typedef's for:
===================
GetLocalTime (DONE)
GetWindowsDirectory
GetPrivateProfileStruct
WritePrivateProfileStruct
RegCreateKeyEx
RegOpenKeyEx
RegQueryValueEx
RegSetValueEx
RegCloseKey
CreateFile
ReadFile
WriteFile
SetFilePointer
CloseHandle
strcat
memset
0
Comment
Question by:mortonsw
  • 6
  • 4
10 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 7033251
You can easily do that yourself - it basically is

typedef <rettype> ( <callconv> *THENAME) (<parameter list>);

where <callconv> is WINAPI...
0
 
LVL 1

Author Comment

by:mortonsw
ID: 7033382
I don't know C/++
0
 
LVL 86

Expert Comment

by:jkr
ID: 7033475
That is no rocket science - look at what you already have:

typedef void (__stdcall *LPFUNCGETLOCALTIME)(LPSYSTEMTIME);


The original declaration is

void __stdcall GetSystemTime(
  LPSYSTEMTIME lpSystemTime  
);


See what I mean?
0
 
LVL 1

Author Comment

by:mortonsw
ID: 7034153
I got that from someone else.
0
 
LVL 86

Expert Comment

by:jkr
ID: 7034554
i know. I just want to point out the method on how to do this by showing you the similarities - you'll learn more this way...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:mortonsw
ID: 7034891
Just trying to convert some asm to c as quickly as possible. checked .h's for quicky but in MS format and I need typedef's in std C ready for primetime since code will be used across of variety of C/++ compilers and needed the most general method of definition. (increased points to 300 for the hassle)
0
 
LVL 86

Accepted Solution

by:
jkr earned 300 total points
ID: 7034907
OK, if you insist:

#include <windows.h>

typedef UINT ( __stdcall *FPTR_GetWindowsDirectory)(
  LPTSTR lpBuffer,  // address of buffer for Windows directory
  UINT uSize        // size of directory buffer
);

typedef BOOL ( __stdcall *FPTR_GetPrivateProfileStruct)(
  LPCTSTR,  // address of section name
  LPCTSTR,      // address of key name
  LPVOID,      // address of return buffer
  UINT,     // size of return buffer
  LPCTSTR        // address of initialization filename
);

typedef BOOL ( __stdcall *FPTR_WritePrivateProfileStruct)(
  LPCTSTR,
                    // pointer to section name
  LPCTSTR,  // pointer to key name
  LPVOID,  // pointer to buffer that contains data to add
  UINT, // size, in bytes, of the buffer
  LPCTSTR    // pointer to initialization filename
);
 
typedef LONG ( __stdcall *FPTR_RegCreateKeyEx)(
  HKEY,                // handle to an open key
  LPCTSTR,         // address of subkey name
  DWORD,           // reserved
  LPTSTR,           // address of class string
  DWORD,          // special options flag
  REGSAM,        // desired security access
  LPSECURITY_ATTRIBUTES,
                            // address of key security structure
  PHKEY,          // address of buffer for opened handle
  LPDWORD   // address of disposition value buffer
);

typedef LONG ( __stdcall *FPTR_RegOpenKeyEx)(
  HKEY,         // handle to open key
  LPCTSTR,  // address of name of subkey to open
  DWORD,   // reserved
  REGSAM, // security access mask
  PHKEY    // address of handle to open key
);

typedef LONG ( __stdcall *FPTR_RegQueryValueEx)(
  HKEY,           // handle to key to query
  LPTSTR,  // address of name of value to query
  LPDWORD,  // reserved
  LPDWORD,      // address of buffer for value type
  LPBYTE,       // address of data buffer
  LPDWORD     // address of data buffer size
);
 
typedef LONG ( __stdcall *FPTR_RegSetValueEx)(
  HKEY,           // handle to key to set value for
  LPCTSTR, // name of the value to set
  DWORD,      // reserved
  DWORD,        // flag for value type
  CONST BYTE *,  // address of value data
  DWORD         // size of value data
);

typedef LONG ( __stdcall *FPTR_RegCloseKey)(
  HKEY    // handle to key to close
);
 
typedef HANDLE ( __stdcall *FPTR_CreateFile)(
  LPCTSTR ,          // pointer to name of the file
  DWORD ,       // access (read-write) mode
  DWORD,           // share mode
  LPSECURITY_ATTRIBUTES,
                               // pointer to security attributes
  DWORD,  // how to create
  DWORD,  // file attributes
  HANDLE         // handle to file with attributes to
                               // copy
);

typedef BOOL ( __stdcall *FPTR_ReadFile)(
  HANDLE,                // handle of file to read
  LPVOID,             // pointer to buffer that receives data
  DWORD,  // number of bytes to read
  LPDWORD, // pointer to number of bytes read
  LPOVERLAPPED    // pointer to structure for data
);

typedef BOOL ( __stdcall *FPTR_WriteFile)(
  HANDLE ,                    // handle to file to write to
  LPCVOID ,                // pointer to data to write to file
  DWORD ,     // number of bytes to write
  LPDWORD ,  // pointer to number of bytes written
  LPOVERLAPPED         // pointer to structure for overlapped I/O
);

typedef DWORD ( __stdcall *FPTR_SetFilePointer)(
  HANDLE ,          // handle of file
  LONG ,  // number of bytes to move file pointer
  PLONG ,
                         // pointer to high-order DWORD of
                         // distance to move
  DWORD      // how to move
);

typedef BOOL ( __stdcall *FPTR_CloseHandle)(
  HANDLE    // handle to object to close
);
0
 
LVL 86

Expert Comment

by:jkr
ID: 7034909
BTW

strcat
memset

are available throght the CRT, dynamically loading them will be difficult...
0
 
LVL 86

Expert Comment

by:jkr
ID: 7034912
Just in case you insist on the LP* notation:

#include <windows.h>

typedef UINT ( __stdcall *LPGETWINDOWSDIRECTORY)(
  LPTSTR lpBuffer,  // address of buffer for Windows directory
  UINT uSize        // size of directory buffer
);

typedef BOOL ( __stdcall *LPGETPRIVATEPROFILESTRUCT)(
  LPCTSTR,  // address of section name
  LPCTSTR,      // address of key name
  LPVOID,      // address of return buffer
  UINT,     // size of return buffer
  LPCTSTR        // address of initialization filename
);

typedef BOOL ( __stdcall *LPWRITEPRIVATEPROFILESTRUCT)(
  LPCTSTR,
                    // pointer to section name
  LPCTSTR,  // pointer to key name
  LPVOID,  // pointer to buffer that contains data to add
  UINT, // size, in bytes, of the buffer
  LPCTSTR    // pointer to initialization filename
);
 
typedef LONG ( __stdcall *LPREGCREATEKEYEX)(
  HKEY,                // handle to an open key
  LPCTSTR,         // address of subkey name
  DWORD,           // reserved
  LPTSTR,           // address of class string
  DWORD,          // special options flag
  REGSAM,        // desired security access
  LPSECURITY_ATTRIBUTES,
                            // address of key security structure
  PHKEY,          // address of buffer for opened handle
  LPDWORD   // address of disposition value buffer
);

typedef LONG ( __stdcall *LPREGOPENKEYEX)(
  HKEY,         // handle to open key
  LPCTSTR,  // address of name of subkey to open
  DWORD,   // reserved
  REGSAM, // security access mask
  PHKEY    // address of handle to open key
);

typedef LONG ( __stdcall *LPREGQUERYVALUEEX)(
  HKEY,           // handle to key to query
  LPTSTR,  // address of name of value to query
  LPDWORD,  // reserved
  LPDWORD,      // address of buffer for value type
  LPBYTE,       // address of data buffer
  LPDWORD     // address of data buffer size
);
 
typedef LONG ( __stdcall *LPREGSETVALUEEX)(
  HKEY,           // handle to key to set value for
  LPCTSTR, // name of the value to set
  DWORD,      // reserved
  DWORD,        // flag for value type
  CONST BYTE *,  // address of value data
  DWORD         // size of value data
);

typedef LONG ( __stdcall *LPREGCLOSEKEY)(
  HKEY    // handle to key to close
);
 
typedef HANDLE ( __stdcall *LPCREATEFILE)(
  LPCTSTR ,          // pointer to name of the file
  DWORD ,       // access (read-write) mode
  DWORD,           // share mode
  LPSECURITY_ATTRIBUTES,
                               // pointer to security attributes
  DWORD,  // how to create
  DWORD,  // file attributes
  HANDLE         // handle to file with attributes to
                               // copy
);

typedef BOOL ( __stdcall *LPREADFILE)(
  HANDLE,                // handle of file to read
  LPVOID,             // pointer to buffer that receives data
  DWORD,  // number of bytes to read
  LPDWORD, // pointer to number of bytes read
  LPOVERLAPPED    // pointer to structure for data
);

typedef BOOL ( __stdcall *LPWRITEFILE)(
  HANDLE ,                    // handle to file to write to
  LPCVOID ,                // pointer to data to write to file
  DWORD ,     // number of bytes to write
  LPDWORD ,  // pointer to number of bytes written
  LPOVERLAPPED         // pointer to structure for overlapped I/O
);

typedef DWORD ( __stdcall *LPSETFILEPOINTER)(
  HANDLE ,          // handle of file
  LONG ,  // number of bytes to move file pointer
  PLONG ,
                         // pointer to high-order DWORD of
                         // distance to move
  DWORD      // how to move
);

typedef BOOL ( __stdcall *LPCLOSEHANDLE)(
  HANDLE    // handle to object to close
);

:o)
0
 
LVL 1

Author Comment

by:mortonsw
ID: 7035033
i owe you 1
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now