Thunking a 32-bit HANDLE to a 64-bit HANDLE

Currently I am converting a 32-bit WDM driver to a 64-bit KMDF driver that 
will continue to work with our 32-bit DLL and our customer's 32-bit 
applications.

The sample code for thunking 32-bit items shows the following

        Buffer->Handle = (HANDLE)Buffer32->Handle;

see: http://msdn.microsoft.com/en-us/library/aa489604.aspx

Buffer32->Handle is declared as UINT32 Handle

The driver compiler issues error number C4312 for this cast.  The code that 
I have adopted (to get it to compile) is:

        handlerInputs.hEvent = (HANDLE) (ULONG_PTR) 
p_handlerInputs32->hEvent; //thunk 32-bit handle to driver handle

MY CONCERN is that I am not certain that making a 32-bit HANDLE 64-bit by 
adding zeros in front is sufficient for the Kernel to know what I am talking 
about when I pass it this number.

I guess I would like a strong reference on conversion of Windows OS data 
types from a 32-bit process to a 64-bit driver.

I have several more delicate conversions that I must do in the next two 
weeks to finish the WDM 32-bit to KMDF 64-bit porting and start unit testing.

Once again, thanks in advance.


-- 
Mr. Fixit needs your help! - John Bond
0
Utf
1/8/2010 8:32:02 PM
development.device.drivers 941 articles. 0 followers. Follow

3 Replies
1898 Views

Similar Articles

[PageSpeed] 53

> MY CONCERN is that I am not certain that making a 32-bit HANDLE 64-bit by
> adding zeros in front is sufficient for the Kernel to know what I am 
> talking
> about when I pass it this number.

This is fine and the way that it needs to be done, there's a Windows 
provided ULongToHandle macro that does exactly this:

#define ULongToHandle( ul ) ((HANDLE)(ULONG_PTR) (ul) )

Since the application is only 32bits you don't have to worry about putting 
anything other than zeroes in the high DWORD. Note that the same is true for 
32bit user mode pointers as well.

-scott

-- 
Scott Noone
Consulting Associate
OSR Open Systems Resources, Inc.
http://www.osronline.com


"John Bond" <johnbond@newsgroup.nospam> wrote in message 
news:A2CCCD9E-EB79-4204-99CC-922E9FA84233@microsoft.com...
> Currently I am converting a 32-bit WDM driver to a 64-bit KMDF driver that
> will continue to work with our 32-bit DLL and our customer's 32-bit
> applications.
>
> The sample code for thunking 32-bit items shows the following
>
>        Buffer->Handle = (HANDLE)Buffer32->Handle;
>
> see: http://msdn.microsoft.com/en-us/library/aa489604.aspx
>
> Buffer32->Handle is declared as UINT32 Handle
>
> The driver compiler issues error number C4312 for this cast.  The code 
> that
> I have adopted (to get it to compile) is:
>
>        handlerInputs.hEvent = (HANDLE) (ULONG_PTR)
> p_handlerInputs32->hEvent; //thunk 32-bit handle to driver handle
>
> MY CONCERN is that I am not certain that making a 32-bit HANDLE 64-bit by
> adding zeros in front is sufficient for the Kernel to know what I am 
> talking
> about when I pass it this number.
>
> I guess I would like a strong reference on conversion of Windows OS data
> types from a 32-bit process to a 64-bit driver.
>
> I have several more delicate conversions that I must do in the next two
> weeks to finish the WDM 32-bit to KMDF 64-bit porting and start unit 
> testing.
>
> Once again, thanks in advance.
>
>
> -- 
> Mr. Fixit needs your help! - John Bond 


0
Scott
1/8/2010 8:39:07 PM
John,

      There is a macro defined in basetsd.h to do exactly this:

#define ULongToHandle( ul ) ((HANDLE)(ULONG_PTR) (ul) )


-- 
Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply



"John Bond" <johnbond@newsgroup.nospam> wrote in message 
news:A2CCCD9E-EB79-4204-99CC-922E9FA84233@microsoft.com...
> Currently I am converting a 32-bit WDM driver to a 64-bit KMDF driver that
> will continue to work with our 32-bit DLL and our customer's 32-bit
> applications.
>
> The sample code for thunking 32-bit items shows the following
>
>        Buffer->Handle = (HANDLE)Buffer32->Handle;
>
> see: http://msdn.microsoft.com/en-us/library/aa489604.aspx
>
> Buffer32->Handle is declared as UINT32 Handle
>
> The driver compiler issues error number C4312 for this cast.  The code 
> that
> I have adopted (to get it to compile) is:
>
>        handlerInputs.hEvent = (HANDLE) (ULONG_PTR)
> p_handlerInputs32->hEvent; //thunk 32-bit handle to driver handle
>
> MY CONCERN is that I am not certain that making a 32-bit HANDLE 64-bit by
> adding zeros in front is sufficient for the Kernel to know what I am 
> talking
> about when I pass it this number.
>
> I guess I would like a strong reference on conversion of Windows OS data
> types from a 32-bit process to a 64-bit driver.
>
> I have several more delicate conversions that I must do in the next two
> weeks to finish the WDM 32-bit to KMDF 64-bit porting and start unit 
> testing.
>
> Once again, thanks in advance.
>
>
> -- 
> Mr. Fixit needs your help! - John Bond
>
> __________ Information from ESET NOD32 Antivirus, version of virus 
> signature database 4755 (20100108) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
> 



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4755 (20100108) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




0
Don
1/8/2010 8:43:02 PM
also make sure you are evaluating this handle and converting it into an 
object pointer in EvtIoInCallerContext.  if you do this in any of the other 
normal io processing callbacks, you may be in the wrong process context

d

-- 

This posting is provided "AS IS" with no warranties, and confers no rights.


"Don Burn" <burn@stopspam.windrvr.com> wrote in message 
news:#dCMuMKkKHA.2164@TK2MSFTNGP02.phx.gbl...
> John,
>
>      There is a macro defined in basetsd.h to do exactly this:
>
> #define ULongToHandle( ul ) ((HANDLE)(ULONG_PTR) (ul) )
>
>
> -- 
> Don Burn (MVP, Windows DKD)
> Windows Filesystem and Driver Consulting
> Website: http://www.windrvr.com
> Blog: http://msmvps.com/blogs/WinDrvr
> Remove StopSpam to reply
>
>
>
> "John Bond" <johnbond@newsgroup.nospam> wrote in message 
> news:A2CCCD9E-EB79-4204-99CC-922E9FA84233@microsoft.com...
>> Currently I am converting a 32-bit WDM driver to a 64-bit KMDF driver 
>> that
>> will continue to work with our 32-bit DLL and our customer's 32-bit
>> applications.
>>
>> The sample code for thunking 32-bit items shows the following
>>
>>        Buffer->Handle = (HANDLE)Buffer32->Handle;
>>
>> see: http://msdn.microsoft.com/en-us/library/aa489604.aspx
>>
>> Buffer32->Handle is declared as UINT32 Handle
>>
>> The driver compiler issues error number C4312 for this cast.  The code 
>> that
>> I have adopted (to get it to compile) is:
>>
>>        handlerInputs.hEvent = (HANDLE) (ULONG_PTR)
>> p_handlerInputs32->hEvent; //thunk 32-bit handle to driver handle
>>
>> MY CONCERN is that I am not certain that making a 32-bit HANDLE 64-bit by
>> adding zeros in front is sufficient for the Kernel to know what I am 
>> talking
>> about when I pass it this number.
>>
>> I guess I would like a strong reference on conversion of Windows OS data
>> types from a 32-bit process to a 64-bit driver.
>>
>> I have several more delicate conversions that I must do in the next two
>> weeks to finish the WDM 32-bit to KMDF 64-bit porting and start unit 
>> testing.
>>
>> Once again, thanks in advance.
>>
>>
>> -- 
>> Mr. Fixit needs your help! - John Bond
>>
>> __________ Information from ESET NOD32 Antivirus, version of virus 
>> signature database 4755 (20100108) __________
>>
>> The message was checked by ESET NOD32 Antivirus.
>>
>> http://www.eset.com
>>
>>
>>
>
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus 
> signature database 4755 (20100108) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
> 
0
Doron
1/11/2010 6:50:59 PM
Reply:

Similar Artilces:

64 bit versions of Excel
Are there 64 bit versions of Excel 2003 or 2007? If so, is there a way to tell if it is 64 bit via vba? Bob Flanagan Bob, I believe that Excel 2010 is the first version that offers 64 bit. HTH, Bernie MS Excel MVP "Robert Flanagan" <nospam@nospam.net> wrote in message news:Oo9rHYEcKHA.2184@TK2MSFTNGP04.phx.gbl... > Are there 64 bit versions of Excel 2003 or 2007? If so, is there a way to > tell if it is 64 bit via vba? > > Bob Flanagan > ...

Vista 64 Critical Updates Without Internet Connection?
I bought a refurbished computer for a customer and we're having problems detecting a Netgear WN111v2 USB wireless adapter. The first thing I think is update Vista 64 Business but there's no Internet connection on the machine. Is there a way to get all of the Vista 64 critical (and related) updates downloaded to my local dev machine then burned to a disk I can then install manually? I'm paging through the test.catalog.update.microsoft.com website at the moment but haven't done this before so confirmation may help me out. Hillbilly wrote: > I bought a refurbi...

How many entries can Excel handle!?
I have close to 1000 entries in my Excel spreadsheet, and am trying to figure out why entries are coming up missing. I often do custom sorts. This may be when entries get tossed out? You are no where near the limit. Check out the help file article "Excel limits and specifications". There must be something else going on. -- Best Regards, Luke M "Rebecca Sage" <RebeccaSage@discussions.microsoft.com> wrote in message news:4241294E-484E-4A8A-9304-0E0C45E643A3@microsoft.com... >I have close to 1000 entries in my Excel spreadsheet, and am trying to ...

Handle recurring interest deposit?
Hi. I receive a CD monthly interest check which is direct deposited to my investment account. Is there any way in Money 2007 to set this up as a recurring deposit? None of the existing "scheduled transaction" options (bill, deposit, transfer, investment purchase) have all the correct fields. Thanks much. -- Rick Are you looking to schedule an Investment transaction for an Investment Account for Interest paid to a Cash account? You'd like to think that Money, having had Investments for 14 or 15 versions now, would have tumbled to the requirement to schedule this kind of ...

I have a column of 32 numbers,
some negative, some positive. They are paired. I have 16 pair. I neeId help with a formula that will give me the difference between the two numbers. 4 -11 I need a total of 15 -10 2 I need a total of 12. Thanks in advance for any assistance. Assuming your data starts in A1, put this in B2: =3DIF(MOD(ROW(A1),2)=3D0,"",ABS(A2-A1)) and copy down as far as required. Hope this helps. Pete On Dec 2, 3:31=A0pm, Skip <ssum...@live.com> wrote: > some negative, some positive. =A0They are paired. I have 16 pair. I > neeId he...

Handling #VALUE?
Sample Code: ------------------------------------------ =IF(SEARCH("Taxable",RC[3])=1, TRUE,FALSE) ------------------------------------------ If "Taxable" is found, no prob: result= "True". OTOH, if "Taxable" not found, SEARCH (just like the documentation says....) returns #VALUE. Question: How do I trap for #VALUE in the IF() statement and convert it to "FALSE" -- PeteCresswell > Question: How do I trap for #VALUE I'm thinking it's something with ERROR.TYPE, but I can't make it work. e.g. =IF(ERROR.TYPE((SEARC...

to retrieve the handle of child window
Hello, I am facing the problem in retrieving the handle of child window in MDI application. I want to pass the handle of child window in one function. and I am calling that function in view file. thge function name is VideOpen(HWND , RECT).This function I am defining in One file called video.cpp and calling that function in ProjectView.cpp.For that I want handle of child window to pass as argument. Waiting for your favourable respose. Thanking you. > I am facing the problem in retrieving the handle of child window > in MDI application. I want to pass the handle of child ...

ie8 for Windows 7, 64 bit
What version of ie8 are you suppose to download? Tried vista 64 bit and received error message, wrong product version Why isn't there a download for windows 7? Win7 64-bit (like all previous 64-bit versions of Windows) includes IE8 64-bit and IE8 32-bit. IE 64-bit is the default. ActiveX Controls are not allowed in IE 64-bit so if you need to access a page dependent on ActiveX (e.g., any page with Flash content), open an instance of IE 32-bit to access the page. (No, there isn't a 64-bit version of Flash, at least not yet.) 32-bit and 64-bit Windows: frequently ...

Is MS_CRM 1.2 supported on Windows 2003 x64 bit?
My customer is buying 64 bit servers and asked if MS-CRM is supported on this architecture. Thank you for any help ------=_NextPart_0001_6FC91A45 Content-Type: text/plain Content-Transfer-Encoding: 7bit Hi Scott~ CRM is not supported on 64 bit servers as of yet. The reason for this is that .net Framework 1.1 will not run on a 64 bit server and CRM needs .net 1.1 in order to run. Warm Regards, Shawn Nulph | Microsoft CRM | Microsoft Business Solutions Microsoft Online Partner Support When responding to posts, please "Reply to Group" via your newsreader so that others may le...

keyboard messages handling
hi, i have developed a program with a keyboard hook ,which will get all the keyboard messages. its works fine for notepad. when i press a key,it will collect by the my hook effectively. That means when i press "r" , my hook collects the keystroke and get the information. prints on edit box "r". It has done in notepad. But in the MSWord ,when i press "r" more than 1 message are genarating and collected my hook. almost 6 messages. it has been with the MS Word. Why it hapens and what is the solution for this? please tell me how can g...

How to handle 401k Account?
I have a 401k account. Each paycheck has an automatic deduction, a lump sum that is taken out and put into my 401k account. Each time I record my paycheck in Money, I use the itemized deduction form that shows Before and After Tax Deductions. I record the 401k deduction as a Before Tax Deduction - it is listed as a Transfer to Janney Montgomery Scott (my broker). I had set up JMS as a 401k account in money. Here's the problem: in reality, JMS divides that lump sum into several investment transactions and I don't know how to handle it. I have been going to the website of my...

Windows Handle Map problem using COleControl and COleControlModule.
Not sure where to start, so let me just start with the ASSERT. In VS2005, we get an assert while attempting to run an MFC SDI app. Not just any MFC SDI app though. In it's view, we attach an OCX that emulates its own SDI. We then have an CHTLMView that sits in this OCX. While attempting to bring up the app (and this CHTMLView inside the OCX inside the EXE MFC View, we get an ASSERT doing handle map lookups because AFX_MANAGE_STATE isn't getting called. I'm thinking this should get called for us by the framework, but it's not, so I suspect we aren't tying all this...

IE8 32 and 64 bit
I am tired of IE8-32 firing up with "Internet Explorer has stopped responding" on my W7x64 laptop (Event ID 1002 in "Windows Log - Application". NB why nothing under "Applications and Services Logs - Internet Explorer"?). This happens every day, often more than once. Although I have FF and Opera, I thought I'd try IE8-64. Not had a "Stopped responding" message, but can't stop "This website wants to install the following add-on 'Adobe Flash Player Installer' from 'Adobe Systems Incorporated'. If you trust the...

Handling F1 key
Hi all, When i press F1 key, the window automatically call its own Help. But i wnat to handle F1 for different purpose. can u plz suggest me how to do that. for example, when user press F1 one dialog will pop up. i have tried using OnChar function but still it take the window help. thanks in advance. bye abhimanyu Do not change what users are used to. You will only confuse them. The standard in Windows is that F1 calls help. "Abhimanyu" <anonymous@discussions.microsoft.com> wrote in message news:1270c01c3c067$b396b9f0$a601280a@phx.gbl... > Hi all, > > When i...

Reinvestment handling vs 'Cap Gain' followed by a 'BUY'
an FYI - I'm gonna contact Fidelity to see if I can change it. ( Unless someone can tell me " been there , done that" ) My register Year-end info shows download info of 'Cap Gain' followed by a 'BUY' vs 'ReinvLTCapGain'. Any way to prevent this ( other than me manually changing the download info) ? It DOES make a difference when calulating return on investment, Cost basis, Gain etc. So pay attention to correct the Fidelity downloads.( Not sure of other brokers) Details: (or skip to next paragraph ) I'll make up some numbers ... rounded off. ...

Question on Paging File on 64 Bit Server
We have a 64Bit Server. SQL Server 2005 SP3 CU4 is installed. There are 3 instances. The Maximum Server Memory for I1 is set at 16GB, I2 at 30GB, and I3 at 16GB. The rule use to be that the paging file should be set 1.5 times. Thus, the paging file would be set at 96GB. However, 96GB for a paging file seems a little high. We have our paging file defined on our E Drive. The E Drive has 67GB. Currently our paging file is set with an initial size of 25GB and a maximum size of 30GB. I am not sure that this is set correctly. On some web pages some people suggest setting no ...

Sizing handles on my chart titles don't work!
I can SEE the sizing handles when I click on the text box, but when I run the mouse over them, I don't get the double-headed arrow. I can't resize the chart title, or either of the axis titles. Strangely, I CAN resize the legend box. I have tried re-making the chart through the Wizard - I've also tried other charts in other files. I can't resize any of the title boxes! Help! Select the chart title and change the font size. "Nicole" <Nicole@discussions.microsoft.com> wrote in message news:F57E90C1-F158-4EBA-8DFB-3E21888CAAA4@microsoft.com... >I can SEE...

printing error handling issue? (when clicking cancel get 2501 error)
I have a report that when it is closed the DoCmd RunCommand acCmdPrint occurs ... but of course if the user clicks cancel, it gives me a 2501 error. How & where do I put code to surpress this error. I would just the close even to run the DoCmd RunCommand acCmdPrint and if cancel is selected just continue to close the report? TIA, _Bigred I understand that I have to do this, I actually don't understand HOW to do it, and where to put code to accomplish this?? 1) What code do I use? 2) Where do I put the code? Thanks, _Bigred "Duane Hookom" <duanehookom@NO_...

W2K3 SP1 32 bit and E2K3 SP2 on 64 bit architecture
Will Windows Server 2003 SP1 x32 Enterprise Eidtion and E2K3 SP2 Enterprise Edition run on 64 bit servers? If so, will it run without problems? We have opportunity to replace our Exchange 32 bit servers with 64 bit servers. We know E2K3 won't run on W2K3 x64, so that means installing W2K3 x32. We would send the 32 bit servers to branch offices that would have been getting the 64 bit servers as file servers. I had an epiphemy thinking about Exchange 12 but want to check if any issues. E2K3 is the only app running on the server. Thanks! jremmc No issues, x32 Windows Server and Ex...

error LNK2001: unresolved external symbol _capCreateCaptureWindowA@32
Hi, I got this mesage error. It seems like it can't find the reference capCreateCaptureWindow, which is a member functios of the vfw.lib. I did put the #include <vfw.h> header, Any suggestions? thanks in advance >Hi, I got this mesage error. It seems like it can't find the reference >capCreateCaptureWindow, which is a member functios of the vfw.lib. >I did put the #include <vfw.h> header, Martin, Add the .lib file to the list of libraries linked in your project's linker properties. Dave Add Vfw32.lib to the list of object modules to link to. -- Che...

Windows update installation problem under Windows 7 64 bit
This morning I noticed a message in the Action Center saying that there had been a "Windows Update installation problem" dated two days ago. A Windows update did not install properly, it said. I checked my system and application logs for the past week and found no error messages. I checked Windows Update history and I did an update for Internet Explorer 8 on 1/23, two days earlier, that it said completed successfully. I do see there is an Internet Explorer 8 update to be installed.still and am assuming that must be *again*? So I am confused. Do I have a problem or not? How do...

Handling Windows Messages In An MFC App
We can use the PeekMessage function in a polling fashion to handle Windows messages to an MFC app. I was wondering if there was a more efficient way to do this using threads and events. What I envision is that my MFC app creates a thread which is suspended until Windows sends the app a message. Then once the message comes in, the thread wakes up, handles the message and then goes to sleep again. Can somebody tell me if this is possible and point to a link which explains how to code this? >We can use the PeekMessage function in a polling fashion to handle Windows >messages to a...

How to get the process handle by a window handle which run in the process.
Thanks! GetWindowThreadProcessId Bill Gates wrote: > Thanks! Thanks:> ...

excel 2000 #32
Row 1 has prices of product. Row 2, 3, etc....have quantity required for each poroduct. At end of each row, need to have amount show. Example: (B2*A1)+(B3*A2)+(B4*A3)+............=amount What formula do I use so that I do not have a long formula? do you really mean for B2 to be paired with A1 if so use =sumproduct(A1:A10,B2:B11) (if you have 10 items) in the columns are to stay together =Sumproduct(A1:A10,B1:B10) change the ranges as needed. "dtaylor" wrote: > Row 1 has prices of product. Row 2, 3, etc....have quantity required for each > poroduct. At end of each row,...

how to handle submenus
hello, i am putting an icon in systray. when we the right click the icon, then we get a popmenu. i want a submenu in that popmenu,when i click an menu item? regards, koti "koti" <rkr.koti@gmail.com> wrote in message news:OUq3aroDFHA.612@TK2MSFTNGP15.phx.gbl... > > hello, > i am putting an icon in systray. when we the right click the icon, > then we get a popmenu. i want a submenu in that popmenu,when i click an &...