comp.lang.ada
 help / color / mirror / Atom feed
* Pointers, C, Win32 API
@ 2005-04-19 23:13 Steve
  2005-04-20  0:00 ` Stephen Leake
  0 siblings, 1 reply; 4+ messages in thread
From: Steve @ 2005-04-19 23:13 UTC (permalink / raw)


Hi,

I am fairly new to ADA and have a query.
I am writing a program in ADA to monitor a directory for any changes
using a notification API.

MSDN Samples have a solution called FWATCH and I am basing my code on
this. I understand the C code but I am having problems converting it to
ADA.

Firstly, the C code:

// this is the all purpose structure that contains
// the interesting directory information and provides
// the input buffer that is filled with file change data
typedef struct _DIRECTORY_INFO {
		HANDLE      hDir;
		TCHAR       lpszDirName[MAX_PATH];
		CHAR        lpBuffer[MAX_BUFFER];
		DWORD       dwBufLength;
		OVERLAPPED  Overlapped;
	} DIRECTORY_INFO, *PDIRECTORY_INFO, *LPDIRECTORY_INFO;

DIRECTORY_INFO  DirInfo;

...

    // Set up a key(directory info)
    hCompPort=CreateIoCompletionPort( DirInfo.hDir,
                                      hCompPort,
                                      (DWORD) &DirInfo,
                                       0);


    // Start watching the directory of interest
    ReadDirectoryChangesW( DirInfo.hDir,
                           DirInfo.lpBuffer,
                           MAX_BUFFER,
                           TRUE,
                           FILE_NOTIFY_CHANGE_LAST_WRITE,
                           &DirInfo.dwBufLength,
                           &DirInfo.Overlapped,
                           NULL);

----------------------------------------
Great, all is well. Now here is my attempt at the ADA version:

type DIRECTORY_INFO_T is record
	hDir         :  Win32.Winnt.HANDLE;
        lpszDirName  :	Win32.TCHAR;
        lpBuffer     :	Win32.CHAR;
        dwBufLength  :  Win32.DWORD;
        lpOverlapped :  Win32.Winbase.LPOVERLAPPED;
end record;

DirInfo : DIRECTORY_INFO_T;

...

     // Set up a key(directory info)
     hCompPort := Winbase.CreateIoCompletionPort(
                       FileHandle                => DirInfo.hDir,
                       ExistingCompletionPort    => hCompPort,
                       CompletionKey             => ?????,
                       NumberOfConcurrentThreads => 0);


In ADA how do I do what the 'C' example is doing:
--->    (DWORD) &DirInfo,

Cheers

Steve




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Pointers, C, Win32 API
  2005-04-19 23:13 Pointers, C, Win32 API Steve
@ 2005-04-20  0:00 ` Stephen Leake
  2005-04-20  2:44   ` Steve
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Leake @ 2005-04-20  0:00 UTC (permalink / raw)
  To: Steve; +Cc: comp.lang.ada

"Steve" <cybaflea@hotmail.com> writes:

>     // Set up a key(directory info)
>     hCompPort=CreateIoCompletionPort( DirInfo.hDir,
>                                       hCompPort,
>                                       (DWORD) &DirInfo,
>                                        0);
>
> ...
>
>      // Set up a key(directory info)
>      hCompPort := Winbase.CreateIoCompletionPort(
>                        FileHandle                => DirInfo.hDir,
>                        ExistingCompletionPort    => hCompPort,
>                        CompletionKey             => ?????,
>                        NumberOfConcurrentThreads => 0);
>
>
> In ADA how do I do what the 'C' example is doing:
> --->    (DWORD) &DirInfo,

I don't have Winbase installed, so I don't know what type
CompletionKey is expecting. Please post the C and Ada declarations of
CreateIOCompletionPort; then I might be able to help more.

In general (as you probably know), '(DWORD) &DirInfo' is taking the
address of DirInfo, and converting it to a 32 bit integer. The direct
equivalent in Ada would be To_Integer_32 (DirInfo'Address) (where
To_Integer_32 is an instantiation of Unchecked_Conversion), but that's
probably _not_ what you want here.

-- 
-- Stephe




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Pointers, C, Win32 API
  2005-04-20  0:00 ` Stephen Leake
@ 2005-04-20  2:44   ` Steve
  2005-04-20 23:29     ` Stephen Leake
  0 siblings, 1 reply; 4+ messages in thread
From: Steve @ 2005-04-20  2:44 UTC (permalink / raw)


Thanks Stephen.

Declarations of CreateIoCompletionPort:

ADA - Winbase:

    function CreateIoCompletionPort(
        FileHandle                           : Win32.Winnt.HANDLE;
        ExistingCompletionPort        : Win32.Winnt.HANDLE;
        CompletionKey                    : Win32.DWORD;
        NumberOfConcurrentThreads: Win32.DWORD)
                                   return Win32.Winnt.HANDLE;  --
winbase.h:1727

subtype DWORD       is ULONG;

------------------------------------------------------------------
C Declaration:

HANDLE CreateIoCompletionPort(
  HANDLE FileHandle,
  HANDLE ExistingCompletionPort,
  ULONG_PTR CompletionKey,
  DWORD NumberOfConcurrentThreads);


Steve




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Pointers, C, Win32 API
  2005-04-20  2:44   ` Steve
@ 2005-04-20 23:29     ` Stephen Leake
  0 siblings, 0 replies; 4+ messages in thread
From: Stephen Leake @ 2005-04-20 23:29 UTC (permalink / raw)
  To: Steve; +Cc: comp.lang.ada

"Steve" <cybaflea@hotmail.com> writes:

> Thanks Stephen.
>
> Declarations of CreateIoCompletionPort:
>
> ADA - Winbase:
>
>     function CreateIoCompletionPort(
>         FileHandle                           : Win32.Winnt.HANDLE;
>         ExistingCompletionPort        : Win32.Winnt.HANDLE;
>         CompletionKey                    : Win32.DWORD;
>         NumberOfConcurrentThreads: Win32.DWORD)
>                                    return Win32.Winnt.HANDLE;  --
> winbase.h:1727
>
> subtype DWORD       is ULONG;
>
> ------------------------------------------------------------------
> C Declaration:
>
> HANDLE CreateIoCompletionPort(
>   HANDLE FileHandle,
>   HANDLE ExistingCompletionPort,
>   ULONG_PTR CompletionKey,
>   DWORD NumberOfConcurrentThreads);

Ok, that didn't help much :). Now we need to look in the Win32
reference for the meaning of CompletionKey. Start at:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/windows_api_reference.asp

Apparently CompletionKey is returned to you in the completion notice,
so you can tell what file the notice is for. I didn't read the whole
page.

So just make up a number, and pass it in.

-- 
-- Stephe




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-04-20 23:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-19 23:13 Pointers, C, Win32 API Steve
2005-04-20  0:00 ` Stephen Leake
2005-04-20  2:44   ` Steve
2005-04-20 23:29     ` Stephen Leake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox