Re: Converting C to Delphi
From: Richard (rwskinnerATawesomenetDotnet)
Date: 09/12/04
- Next message: Richard: "Re: Converting C to Delphi"
- Previous message: Richard: "Re: Converting C to Delphi"
- In reply to: Rob Kennedy: "Re: Converting C to Delphi"
- Next in thread: Rob Kennedy: "Re: Converting C to Delphi"
- Reply: Rob Kennedy: "Re: Converting C to Delphi"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 12 Sep 2004 08:58:45 -0500
Okay Rob, it's all defined in a large file called winioctl.h which as the
macro and a million constants. Can this be imported into delphi or do I
have to manually enter it all?
"Rob Kennedy" <me3@privacy.net> wrote in message
news:2qiagiFvol9mU1@uni-berlin.de...
> Richard wrote:
> > I'm running into a little jam here. I have some of this converted but I
> > have no clue what to do with the rest of it.
> > Sorry, it appears to have lost it's format when I pasted it in here.
> > I get past the Createfile stuff okay, but the following section gets me
> > since I don't know C. How do I convert the following block of code?
See
> > below the dotted line for the full version. Please help, I'm lost!!!
>
> > #define FILE_DEVICE_LMSENSOR FILE_DEVICE_UNKNOWN
>
> That says that anywhere the text "FILE_DEVICE_LMSENSOR" appear in the
> code, it should be interpretted as though it was "FILE_DEVICE_UNKNOWN".
> (Sounds like an abuse of the "unknown" device, to me.)
>
> > #define IOCTL_LMSENSOR_GET_TEMP \
> > CTL_CODE( FILE_DEVICE_LMSENSOR, 0x900, METHOD_BUFFERED,
FILE_WRITE_ACCESS )
> > #define IOCTL_LMSENSOR_GET_VOLT \
> > CTL_CODE( FILE_DEVICE_LMSENSOR, 0x901, METHOD_BUFFERED,
FILE_WRITE_ACCESS )
>
> CTL_CODE is a macro. You'll need to find its definition somewhere in the
> other headers included in the one you posted. The macro will be defined
> to perform some operations on the parameters and resolve to a constant.
> Perform those calculations yourself and declare the constants with the
> values you calculate. If you found that the value was 10 (and it almost
> surely isn't), then you would declare it like this:
>
> const
> IOCtl_LMSensor_Get_Temp = 10;
>
> > ULONG temp[3]={0}, retSize;
>
> That's declaring two variables. One is temp, an array of three ULongs.
> The other is retSize, which is just a plain old ULong. The temp variable
> also gets initialized so all of its elements are 0.
>
> > if(!DeviceIoControl(hLmsensor,
> > IOCTL_LMSENSOR_GET_TEMP,
> > NULL,
> > 0,
> > temp,
> > sizeof(temp),
> > &retSize,
> > NULL))
> > {
>
> The first thing you do is look at the documentation for the
> DeviceIOControl function. It's a Win32 API function, which means that
> you should look at the MSDN Web site, or at the Platform SDK help file,
> if you have it.
>
> The first two parameters should be easy enough to understand. The third
> parameter above is NULL, but in Delphi, Null is an OleVariant constant,
> not a null-pointer constant. In Delphi, use the "nil" keyword instead.
> The fifth parameter is declared in C to be a pointer, and in C, an array
> can act a lot like a pointer, which is why temp works there. In would
> translate that to @temp[0] in Delphi. The seventh parameter is declared
> in C to be a pointer to a DWord, but Borland has declared it as a var
> DWord instead, so just pass retSize directly. The "!" operator in C is
> the Boolean negation operator, comparable to Delphi's "not" operator.
>
> if not DeviceIOControl(hLmsensor, IOCtl_LMSensor_Get_Temp, nil, 0,
> @temp[0], SizeOf(temp), retSize, nil) then begin
>
> > void CAdvLmsensorSampleDlg::OnButtonGetTemp()
> > {
> > // TODO: Add your control notification handler code here
> > HANDLE hLmsensor;
> > CWnd* wndTemp;
> > hLmsensor = CreateFile( "\\\\.\\AdvLmDev",
>
> In C, the "\" character has special meaning, sort of like "'" in Delphi.
> To include a literal backslash in a string, it gets doubled. Since
> backslash has no special meaning in Delphi, you need to un-double it.
>
> hLmsensor := CreateFile('\\.\AdvLmDev', ...
>
> > if ( hLmsensor == INVALID_HANDLE_VALUE )
> >
> > {
> >
> > UpdateWindowText(IDC_EDIT_CPU_TEMP, _T("N/A"));
>
> All the _T stuff can be ignored. It's there for Unicode support, but the
> code you posted doesn't use it consistently anyway.
>
> > // CPU Temperature
> > tempC = temp[1]/10;
> > displayStr.Format(_T("%6.1f ? C /%6.1f ? F"), tempC, 32 + tempC*9/5);
>
> Are you familiar with Delphi's Format function? If not, go check the
> help file. Also check the index for "format strings."
>
> --
> Rob
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
- Next message: Richard: "Re: Converting C to Delphi"
- Previous message: Richard: "Re: Converting C to Delphi"
- In reply to: Rob Kennedy: "Re: Converting C to Delphi"
- Next in thread: Rob Kennedy: "Re: Converting C to Delphi"
- Reply: Rob Kennedy: "Re: Converting C to Delphi"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]