From: Tym on
I can only find this routine in C and need it in VB6 - can anyone
translate this please:

--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--

unsigned char Calc_checksum(char* sz, int nCount)
{
unsigned char cs; // Checksum
//Omit the $-character
for (i=1; i<Count; i++)
{
cs = cs ^((unsigned char)sz[i]);
}
return cs;
}

--8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<--



---


Tym

Please do not adjust your brain, there is a fault with reality

Email - Domain is valid - user is not - I'm sure you can work it out though!

However, there is an agressive spam trap here, so you'll get blacklisted until I
white list you. If you've emailed and asked for a reply and not got one - please
post a message in here and I'll re-check the black hole!

A plague of Jonathan Ross a thousand fold on the spammers!!
From: Mike D Sutton on
> I can only find this routine in C and need it in VB6 - can anyone
> translate this please:
<code snipped>

Try something like this:

'***
Private Function Calc_checksum( _
ByRef sz As String, ByVal nCount As Long) As Byte
Dim cs As Byte ' Checksum
Dim i As Long

' Omit the $-character
For i = 2 To nCount
cs = cs Xor Asc(Mid$(sz, i, 1))
Next i

Calc_checksum = cs
End Function
'***

It's a pretty lame checksum method though, if you're simply after a checksum then the ZLib library contains two methods
and there's an article on my site about how to use it. Alternatively have a look at the MD5 routine which is a very
good checksum method.
Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: EDais(a)mvps.org
WWW: Http://EDais.mvps.org/


From: Ted on
You know C ?? :-)
How about this one please ?

Wow64DisableWow64FsRedirection and Wow64RevertWow64FsRedirection
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#define _WIN32_WINNT 0x0501
#include <windows.h>

PVOID OldValue;
HANDLE hFile;

BOOL bRet = Wow64DisableWow64FsRedirection (&OldValue);

if (bRet == TRUE)
{
// Open a file

hFile = CreateFile(TEXT("c:\\windows\\system32\\notepad.exe"),
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);

// Restore the previous WOW64 file system redirection value.

Wow64RevertWow64FsRedirection (OldValue);
}

if( INVALID_HANDLE_VALUE != hFile )
{
// Use the file handle
}

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
'Also may be GetSystemWow64Directory

The GetSystemWow64Directory function retrieves the path of the system
directory used by WOW64. This directory is not present on 32-bit Windows.

UINT GetSystemWow64Directory(
LPTSTR lpBuffer,
UINT uSize
);

Parameters
lpBuffer
[out] Pointer to the buffer to receive the null-terminated string containing
the path. This path does not end with a backslash.
uSize
[in] Maximum size of the buffer, in TCHARs. This value should be set to
MAX_PATH.
Return Values
If the function succeeds, the return value is the length, in TCHARs, of the
string copied to the buffer, not including the terminating null character.
If the length is greater than the size of the buffer, the return value is
the size of the buffer required to hold the path.

If the function fails, the return value is zero. To get extended error
information, call GetLastError.

On 32-bit Windows, the function always fails, and the extended error is set
to ERROR_CALL_NOT_IMPLEMENTED.

Remarks
WOW64 uses the system directory to store shared 32-bit code on 64-bit
Windows. Most applications have no need to access this directory explicitly.


Requirements
Header Declared in Winbase.h; include Windows.h.
Library Link to Kernel32.lib.
DLL Requires Kernel32.dll.
Unicode Implemented as GetSystemWow64DirectoryW (Unicode) and
GetSystemWow64DirectoryA (ANSI).



From: Mike D Sutton on
> You know C ?? :-)
> How about this one please ?

This isn't a free code porting service..
I saw your previous thread on the subject and decided against providing a translation for it since I've never worked on
a 64-bit OS before and don't know the potential pitfalls of running VB code on it. For example your example uses UINT
as an input parameter and return value, however is this a 32-bit or 64-bit unsigned integer? If it's 64-bit then it's a
real pain to work with in VB since you would need to use a double/currency data type and convert the data every time you
read/write the values.
Here's a straight conversion of the code, I _don't_ expect it to work right off the bat but at least it gives you a
starting point:

'***
Private Declare Function Wow64DisableWow64FsRedirection _
Lib "Kernel32.dll" (ByRef OldValue As Long) As Long
Private Declare Function Wow64RevertWow64FsRedirection _
Lib "Kernel32.dll" (ByRef OldValue As Long) As Long
Private Decalre Function GetSystemWow64Directory Lib "Kernel32.dll" Alias _
"GetSystemWow64DirectoryA" (ByVal lpBuffer As String, ByVal uSize As Long) As Long
Private Declare Function CreateFile Lib "Kernel32.dll" Alias "CreateFileA" ( _
ByVal lpFileName As String, ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, ByRef lpSecurityAttributes As Any, _
ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "Kernel32.dll" (ByVal hObject As Long) As Long

Private Const GENERIC_READ As Long = &H80000000
Private Const FILE_SHARE_READ As Long = &H1
Private Const OPEN_EXISTING As Long = 3
Private Const FILE_ATTRIBUTE_NORMAL As Long = &H80
Private Const INVALID_HANDLE_VALUE As Long = -1

....

Dim OldValue As Long
Dim hFile As Long
Dim bRet As Long

bRet = Wow64DisableWow64FsRedirection(OldValue)

If (bRet) Then ' Open a file
hFile = CreateFile("c:\windows\system32\notepad.exe", GENERIC_READ, _
FILE_SHARE_READ, ByVal 0&, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0&)

' Restore the previous WOW64 file system redirection value.
Call Wow64RevertWow64FsRedirection(OldValue)
End If

If (hFile <> INVALID_HANDLE_VALUE) Then
' Use the file handle
End If

....

' Clean up the file handle once you're finished with it
Call CloseHandle(hFile)
'***

Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: EDais(a)mvps.org
WWW: Http://EDais.mvps.org/


From: Ted on
>however is this a 32-bit or 64-bit unsigned integer?

It is a 32 bit code, it suppose to disable 64 bit redirection.
32 bit applications get redirected when accessing the System32
folder to Syswow64 folder.
MS makes it confusing, they should have named System32
System64 and the Syswow64 (32 bit system directory) should
have been named System32.

> This isn't a free code porting service..

More than glad to pay

Thank you very much.

"Mike D Sutton" <EDais(a)mvps.org> wrote in message
news:ecz7X$AmFHA.2080(a)TK2MSFTNGP14.phx.gbl...
>> You know C ?? :-)
>> How about this one please ?
>
> This isn't a free code porting service..
> I saw your previous thread on the subject and decided against providing a
> translation for it since I've never worked on
> a 64-bit OS before and don't know the potential pitfalls of running VB
> code on it. For example your example uses UINT
> as an input parameter and return value, however is this a 32-bit or 64-bit
> unsigned integer? If it's 64-bit then it's a
> real pain to work with in VB since you would need to use a double/currency
> data type and convert the data every time you
> read/write the values.
> Here's a straight conversion of the code, I _don't_ expect it to work
> right off the bat but at least it gives you a
> starting point:
>
> '***
> Private Declare Function Wow64DisableWow64FsRedirection _
> Lib "Kernel32.dll" (ByRef OldValue As Long) As Long
> Private Declare Function Wow64RevertWow64FsRedirection _
> Lib "Kernel32.dll" (ByRef OldValue As Long) As Long
> Private Decalre Function GetSystemWow64Directory Lib "Kernel32.dll" Alias
> _
> "GetSystemWow64DirectoryA" (ByVal lpBuffer As String, ByVal uSize As
> Long) As Long
> Private Declare Function CreateFile Lib "Kernel32.dll" Alias "CreateFileA"
> ( _
> ByVal lpFileName As String, ByVal dwDesiredAccess As Long, _
> ByVal dwShareMode As Long, ByRef lpSecurityAttributes As Any, _
> ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As
> Long, _
> ByVal hTemplateFile As Long) As Long
> Private Declare Function CloseHandle Lib "Kernel32.dll" (ByVal hObject As
> Long) As Long
>
> Private Const GENERIC_READ As Long = &H80000000
> Private Const FILE_SHARE_READ As Long = &H1
> Private Const OPEN_EXISTING As Long = 3
> Private Const FILE_ATTRIBUTE_NORMAL As Long = &H80
> Private Const INVALID_HANDLE_VALUE As Long = -1
>
> ...
>
> Dim OldValue As Long
> Dim hFile As Long
> Dim bRet As Long
>
> bRet = Wow64DisableWow64FsRedirection(OldValue)
>
> If (bRet) Then ' Open a file
> hFile = CreateFile("c:\windows\system32\notepad.exe", GENERIC_READ, _
> FILE_SHARE_READ, ByVal 0&, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
> 0&)
>
> ' Restore the previous WOW64 file system redirection value.
> Call Wow64RevertWow64FsRedirection(OldValue)
> End If
>
> If (hFile <> INVALID_HANDLE_VALUE) Then
> ' Use the file handle
> End If
>
> ...
>
> ' Clean up the file handle once you're finished with it
> Call CloseHandle(hFile)
> '***
>
> Hope this helps,
>
> Mike
>
>
> - Microsoft Visual Basic MVP -
> E-Mail: EDais(a)mvps.org
> WWW: Http://EDais.mvps.org/
>
>