I did a forum search but not found. This does not mean that nobody is using it but it may indicate that it is by no means a popular API.
In PowerBASIC I could use something like this:
Code: Select all
#COMPILE EXE "test.exe"
#DIM ALL
#INCLUDE "Win32API.inc"
Function PBmain
Dim Buffer As String
Local Result as Dword
Buffer = String$(131072, 0)
Result = CryptProtectMemory( ByVal StrPtr(Buffer), Len(Buffer), 0 )
If IsTrue Result Then Print "Success" Else Print "Failure"
Waitkey$
END FUNCTION
CryptProtectMemory is in PB's WinCrypt.inc but I don't need to know that as Win32API.inc is almost a 'catch all' include file. Sometimes we need to know which inc file is needed but not often.
With FreeBASIC I have to search the bi files for CryptProtectMemory. No big deal but a pain nonetheless.
This is my first attempt in FreeBASIC.
Code: Select all
#include once "windows.bi"
#include once "win/wincrypt.bi"
Dim Buffer( 1 To 131072) As Byte
Dim As Any Ptr ptrBaseBuffer = @Buffer(1)
Dim As Ulong Result
Result = CryptProtectMemory( Cast(LPVOID, ptrBaseBuffer), Ubound(Buffer), 0 )
If Result = TRUE Then Print "Success" Else Print "Failure"
Sleep
Ok, so I need a library. MSDN tells me that CryptProtectMemory is in Crypt32.dll. Another search and more pain.
So, I tried this:
Code: Select all
#include once "windows.bi"
#include once "win/wincrypt.bi"
#inclib "crypt32" ' Added
Dim Buffer( 1 To 131072) As Byte
Dim As Any Ptr ptrBaseBuffer = @Buffer(1)
Dim As Ulong Result
Result = CryptProtectMemory( ptrBaseBuffer, 131072, 0 )
If Result = TRUE Then Print "Success" Else Print "Failure"
Sleep
So, I loaded the binary of libcrypt32.dll.a into TextPad and searched for CryptProtectMemory. It was not there. CryptProtectMemory is declared in wincrypt.bi.
No import library then. Oh, well I will have to use my own declare.
Code: Select all
#include once "windows.bi"
Declare Function CryptProtectMemory Lib "Crypt32.dll" Alias "CryptProtectMemory" _
(byval pDataIn as LPVOID, byval cbDataIn as DWORD, byval dwFlags as DWORD) as WINBOOL
Dim Buffer( 1 To 131072) As Byte
Dim As Any Ptr ptrBaseBuffer = @Buffer(1)
Dim As Ulong Result
Result = CryptProtectMemory( Cast(LPVOID, ptrBaseBuffer), 131072, 0 )
If Result = TRUE Then Print "Success" Else Print "Failure"
Sleep
Way back in January I wrote a general Hash & HMAC routine which included many Windows APIs without all this none-sense.<smile>
CryptProtectMemory was introduced in Windows Vista so it is not a new API.
Clearly I have more jumping through hoops to do but I am scratching my head as to what to do next.
Usual question: What am I doing wrong now?