Solved

Need typedef's for a few win32 funcs

Posted on 2002-05-24
10
583 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

770 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