Solved

Need typedef's for a few win32 funcs

Posted on 2002-05-24
10
572 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
Comment Utility
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
Comment Utility
I don't know C/++
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
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
Comment Utility
I got that from someone else.
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:mortonsw
Comment Utility
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
Comment Utility
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
Comment Utility
BTW

strcat
memset

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

Expert Comment

by:jkr
Comment Utility
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
Comment Utility
i owe you 1
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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.

763 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

8 Experts available now in Live!

Get 1:1 Help Now