The define of NTSYSAPI in ntdef.h is __declspec(dllimport). I want to know what kind of variable or functions we can use NTSYSAPI to import to our program. Thank you very much.
On 20-Mar-2012 04:52, daedae11 wrote:
The define of NTSYSAPI in ntdef.h is __declspec(dllimport). I want to
know what kind of variable or functions we can use NTSYSAPI to import to
our program. Thank you very much.
Look in ntddk.h for examples of using NTSYSAPI.
Drivers are DLLs, they are dynamically linked to various kernel exports,
like normal DLLs do.
Hope this helps.
–pa
Any function for which __declspec(dllimport) makes sense. Did you RTFM on
what dllimport does?
I would never use it for a variable; Best Practice is that no variable
local to a dll is ever visible outside it. Such state is owned by and
managed by the dll and you use setter/getter pairs to abstract the concept
from the implementation. Better still, no variable in a dll is other than
const (or pseudo-const, such as initialized once in DllMain and only read,
never written, thereafter). Best Practice suggests that a dll maintain as
little state in variables as possible, otherwise multithread use of the
dll requires either amazing effort on the part of the dll writer to keep
everything consistent, or multithreaded use of the dll results in
catastrophic failure in the dll’s clients. Keep transient state in a
struct/class which is usually an opaque type outside the dll and is either
obtained by caaling some kind of “create object” call to the dll or
allocated by the caller, which violates the “opaque” goal. Note that it
is the client of the dll who is responsible for never allowing the same
object to be passed in concurrently by two different threads.
dllimport and dllexport come in pairs. see my essay on “the ultimate dll
header file” on my mvp tips site, www.flounder.com/mvp_tips.htm.
joe
The define of NTSYSAPI in ntdef.h is __declspec(dllimport). I want to know
what kind of variable or functions we can use NTSYSAPI to import to our
program. Thank you very much.NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminarsTo unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
I have read the ntddk.h . However, If I use NTSYSAPI to declare a variable, how should I deploy the driver from which I import this variable?
Thank you.
At 2012-03-20 11:18:26,“Pavel A” wrote:
>On 20-Mar-2012 04:52, daedae11 wrote:
>> The define of NTSYSAPI in ntdef.h is __declspec(dllimport). I want to
>> know what kind of variable or functions we can use NTSYSAPI to import to
>> our program. Thank you very much.
>
>Look in ntddk.h for examples of using NTSYSAPI.
>Drivers are DLLs, they are dynamically linked to various kernel exports,
>like normal DLLs do.
>
>Hope this helps.
>–pa
>
>
>
>—
>NTDEV is sponsored by OSR
>
>For our schedule of WDF, WDM, debugging and other seminars visit:
>http://www.osr.com/seminars
>
>To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
“daedae11” wrote in message news:xxxxx@ntdev…
> I have read the ntddk.h . However, If I use NTSYSAPI to declare a
> variable, how should I deploy the driver from which I import this
> variable?
Don’t use NTSYSAPI macro to export things from your stuff.
It would be confusing. Just write __declspec(dllimport), and look in MSDN
how to use it
(or see the article of Mr. Newcomer).
– pa
> At 2012-03-20 11:18:26,“Pavel A” wrote:
>>On 20-Mar-2012 04:52, daedae11 wrote:
>>> The define of NTSYSAPI in ntdef.h is__declspec(dllimport). I want to
>>> know what kind of variable or functions we can use NTSYSAPI to import to
>>> our program. Thank you very much.
>>
>>Look in ntddk.h for examples of using NTSYSAPI.
>>Drivers are DLLs, they are dynamically linked to various kernel exports,
>>like normal DLLs do.
>>
>>Hope this helps.
>>–pa
>>
> It would be confusing. Just write __declspec(dllimport), and look in MSDN
.DEF file is by far better, since __declspec has issues with decorated names.
–
Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com
daedae11 wrote:
I have read the ntddk.h . However, If I use NTSYSAPI to declare a
variable, how should I deploy the driver from which I import this
variable?
DLL imports in kernel mode work exactly the same as DLL imports in user
mode. You are looking for magic where there is none.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
You would not. See my earlier response. A dll should never export a
variable. This is bad practice.
Rule 1: Never export variables from DLLs
Rule 2: If you think you need to export a variable, consult Rule 1
Note this is closely related to two other rules:
Rule 3: Usage of static variables in a DLL should be limited to const and
write-once variables
Rule 4: If you think you need a variable to hold state, consult Rule 3
There are exceedingly rare exceptions to Rule 3, but in over two decades
of Windows programming, I’ve never seen the need to violate Rule 1.
DLLs that have state are next to impossible to use in multithreaded
systems. In application space, there is the notion of “thread local”
variables, which is an ugly hack to accomplish what careful programming
should accomplish: per-thread state. In the last twelve years of
programming DLLs, I have never found a need to violate Rule 3. I have had
to deal with DLLs that do, and It Ain’t Pretty. When I have the DLL
source I rewrite it; when I don’t, I have to do external synchronization
to protect the DLL.
Don’t do it. Don’t ask “How do I do this?” because there is little, if
any, point to doing it. It will result in something whose correctness is
problematical, and whose maintenance is impossible.
Why do you think you need to export a variable?
joe
I have read the ntddk.h . However, If I use NTSYSAPI to declare a
variable, how should I deploy the driver from which I import this
variable?
Thank you.At 2012-03-20 11:18:26,“Pavel A” wrote:
>>On 20-Mar-2012 04:52, daedae11 wrote:
>>> The define of NTSYSAPI in ntdef.h is __declspec(dllimport). I want to
>>> know what kind of variable or functions we can use NTSYSAPI to import
>>> to
>>> our program. Thank you very much.
>>
>>Look in ntddk.h for examples of using NTSYSAPI.
>>Drivers are DLLs, they are dynamically linked to various kernel exports,
>>like normal DLLs do.
>>
>>Hope this helps.
>>–pa
>>
>>
>>
>>—
>>NTDEV is sponsored by OSR
>>
>>For our schedule of WDF, WDM, debugging and other seminars visit:
>>http://www.osr.com/seminars
>>
>>To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
I’m sorry I didn’t express my thought clearly. I just want to know how to use a sys dll. And now , I’ve got it from others. Thank you very much. I won’t export a vairable.
At 2012-03-21 13:36:16,xxxxx@flounder.com wrote:
You would not. See my earlier response. A dll should never export a
variable. This is bad practice.Rule 1: Never export variables from DLLs
Rule 2: If you think you need to export a variable, consult Rule 1Note this is closely related to two other rules:
Rule 3: Usage of static variables in a DLL should be limited to const and
write-once variables
Rule 4: If you think you need a variable to hold state, consult Rule 3There are exceedingly rare exceptions to Rule 3, but in over two decades
of Windows programming, I’ve never seen the need to violate Rule 1.DLLs that have state are next to impossible to use in multithreaded
systems. In application space, there is the notion of “thread local”
variables, which is an ugly hack to accomplish what careful programming
should accomplish: per-thread state. In the last twelve years of
programming DLLs, I have never found a need to violate Rule 3. I have had
to deal with DLLs that do, and It Ain’t Pretty. When I have the DLL
source I rewrite it; when I don’t, I have to do external synchronization
to protect the DLL.Don’t do it. Don’t ask “How do I do this?” because there is little, if
any, point to doing it. It will result in something whose correctness is
problematical, and whose maintenance is impossible.Why do you think you need to export a variable?
joe> I have read the ntddk.h . However, If I use NTSYSAPI to declare a
> variable, how should I deploy the driver from which I import this
> variable?
> Thank you.
>
>
>
>
> At 2012-03-20 11:18:26,“Pavel A” wrote:
>>>On 20-Mar-2012 04:52, daedae11 wrote:
>>>> The define of NTSYSAPI in ntdef.h is __declspec(dllimport). I want to
>>>> know what kind of variable or functions we can use NTSYSAPI to import
>>>> to
>>>> our program. Thank you very much.
>>>
>>>Look in ntddk.h for examples of using NTSYSAPI.
>>>Drivers are DLLs, they are dynamically linked to various kernel exports,
>>>like normal DLLs do.
>>>
>>>Hope this helps.
>>>–pa
>>>
>>>
>>>
>>>—
>>>NTDEV is sponsored by OSR
>>>
>>>For our schedule of WDF, WDM, debugging and other seminars visit:
>>>http://www.osr.com/seminars
>>>
>>>To unsubscribe, visit the List Server section of OSR Online at
>>> http://www.osronline.com/page.cfm?name=ListServer
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>
>
>
>—
>NTDEV is sponsored by OSR
>
>For our schedule of WDF, WDM, debugging and other seminars visit:
>http://www.osr.com/seminars
>
>To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
> Rule 3: Usage of static variables in a DLL should be limited to const and
write-once variables
Lock-protected singletone in a DLL is OK
–
Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com
Most people seem to be clueless about concepts like multithreading. So
they just toss in all kinds of variables, arguing that “If I set this
static variable, I don’t have to pass it in as a parameter, and all the
functions that need it can just read it”. I’ve had to fix their code
before I could even do the job I was supposed to do. Your explanation,
below, is perfectly correct, and would mean absolutely nothing to them.
Their comprehension is that limited. They can understand Rule 3. Not the
rationale behind it, but they can follow it.
Sometimes you just have to dumb it all down.
What is really scary is when you take one of these far-below-average
programmers and put them to writing drivers. They program using the same
sloppy idioms. I’ve been called in to consult on some of this trash, and
it never makes the client happy when you say “There’s nothing wrong with
this code that a total rewrite couldn’t fix” followd by 6-10 pages of the
errors in the driver.
joe
> Rule 3: Usage of static variables in a DLL should be limited to const
> and
> write-once variablesLock-protected singletone in a DLL is OK
–
Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminarsTo unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
On 22-Mar-2012 03:54, xxxxx@flounder.com wrote:
…
Their comprehension is that limited. They can understand Rule 3. Not the
rationale behind it, but they can follow it.Sometimes you just have to dumb it all down.
http://blogs.tedneward.com/2012/03/21/Unlearn+Young+Programmer.aspx
The old folks are no good, the young folks are no good. Anyone’s left?
– pa
> What is really scary is when you take one of these far-below-average
programmers and put them to writing drivers.
I agree.
–
Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com
On 22-Mar-2012 17:27, Maxim S. Shatskih wrote:
> What is really scary is when you take one of these far-below-average
> programmers and put them to writing drivers.I agree.
Agree to what? These programmers are usually *not* below average.
It’s because the driver development for Windows requires some medieval
skillz that they don’t learn in schools.
(remember that old Russian joke about senior and junior sh%thouse cleaners?)
– pa
Actually, being a po’lil ol’ southern Baptist fella, I’ve never heard that one. It wouldn’t have anything to do with shithouse lawyers would it?
Gary Little
H (952) 223-1349
C (952) 454-4629
xxxxx@comcast.net
On Mar 22, 2012, at 10:47 AM, Pavel A wrote:
On 22-Mar-2012 17:27, Maxim S. Shatskih wrote:
>> What is really scary is when you take one of these far-below-average
>> programmers and put them to writing drivers.
>
> I agree.Agree to what? These programmers are usually *not* below average.
It’s because the driver development for Windows requires some medieval skillz that they don’t learn in schools.
(remember that old Russian joke about senior and junior sh%thouse cleaners?)– pa
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
> It’s because the driver development for Windows requires some medieval
skillz that they don’t learn in schools.
Multithreading is medieval?
(remember that old Russian joke about senior and junior sh%thouse cleaners?)
“go on educating, my son, or you will still be a bucket-carrying helper for the rest of your life!”
Traditionally driver developmers are considered to be good developers and not some website coders.
–
Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com
The problem is that driver developers are thought of as “second” class developers by anyone outside of the driver community, which includes most managers and project developers, who assume that kernel and driver development can be done by any dumbshit walking in off of the street. They also tend to assume driver development takes 0 time and resources, hence providing the driver developer the shitty end of the stick as far as time and resources, and then get upset when the driver causes the schedule to slip.
Gary Little
H (952) 223-1349
C (952) 454-4629
xxxxx@comcast.net
On Mar 22, 2012, at 10:58 AM, Maxim S. Shatskih wrote:
> It’s because the driver development for Windows requires some medieval
> skillz that they don’t learn in schools.Multithreading is medieval?
> (remember that old Russian joke about senior and junior sh%thouse cleaners?)
“go on educating, my son, or you will still be a bucket-carrying helper for the rest of your life!”
Traditionally driver developmers are considered to be good developers and not some website coders.
–
Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminarsTo unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
Gary,
Truly there are a bunch of idiotic managers and headhunters out
there. I recently had a call, where I was asked if drivers were written
in C or C++ versus “more advanced languages”, and I said yes. When the
discussion got around to my rates, the manager went ballistic with the
statement “there are plenty of $25/hour C programmers”!
Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
“Gary Little” wrote in message news:xxxxx@ntdev:
> The problem is that driver developers are thought of as “second” class developers by anyone outside of the driver community, which includes most managers and project developers, who assume that kernel and driver development can be done by any dumbshit walking in off of the street. They also tend to assume driver development takes 0 time and resources, hence providing the driver developer the shitty end of the stick as far as time and resources, and then get upset when the driver causes the schedule to slip.
>
> Gary Little
> H (952) 223-1349
> C (952) 454-4629
> xxxxx@comcast.net
>
> DLLs that have state are next to impossible to use in multithreaded systems.
Which is simply not true - if it was, the very concept of OS design as we know it would be infeasible. In order to realize it all you have to do is to think of a kernel as of a library that export functions. Therefore, the only question left is how you implement things. If you directly expose them to the rest of the world…well, sorry, but this is the problem that results only from your faulty design/implementation
In application space, there is the notion of “thread local” variables, which is an ugly hack to accomplish
what careful programming should accomplish: per-thread state.
Actually, what you need in order to make your DLL usable in multithreaded environment is not “per-thread state” but per-object one. The most reasonable way to do is to make your DLL exports return/take references that are meaningless to anyone but DLL itself, and make it use them as means of locating library-scope objects with the internal state/structure that is known only to DLL itself, i.e. do thing pretty much the same way kernel does when it returns descriptors to UM apps. If you do it this way no one, apart from DLL’s code, will have a direct access to these objects - they will be truly owned by your DLL, which means that, as far as global variables in multithreaded environment are concerned, your DLL will become an entire app in its own right. Simple, ugh…
Anton Bassov
> Truly there are a bunch of idiotic managers and headhunters out there. I recently had a call,
where I was asked if drivers were written in C or C++ versus “more advanced languages”, and
I said yes.
I just wonder how it may be specific to hiring driver writers…
Sorry, but these are HR people who are supposed be dumb by the very definition - otherwise they would work elsewhere. Let me tell you a couple of true interview stories
Story 1.
Q. What is your experience with Oracle?
A. None - I am specialized in SQL Server
Q. What about PL/SQL?
This is concerning the requirement that applicant should be “familiar with SQL Server and/or with Oracle and PL/SQL” (which happens to be Oracle-specific SQL flavor)
Story 2
Q. Have you worked with TCP? And what about IP?
This is concerning the requirement that the applicant should be “familiar with TCP/IP” ( no, don’t get me
wrong - the interviewer does not mean the differences between network and transport layers in OSI model)
When the discussion got around to my rates, the manager went ballistic with the
statement “there are plenty of $25/hour C programmers”!
No mentioning of rates on OSR lists…
Anton Bassov