Using C++ in drivers

Little OT, but I think it’s appropriate.

I’m implementing transparent encryption filter, and would like to
use a C++ crypto library (Crypto++ namely).
Has anyone used C++ in their drivers before? I ask this, because I a
few unresolved external errors (namely CxxFrameHandler and similar),
that are C++ specific, and I don’t know how to use these in Kernel mode.

CrtDll.lib exports these, but this is a UM library (if I try to link
with it, I get unresolved external for Sleep and GetVersion APIs:-)
I’d rather not use some 3rd party library, but I’m open for
suggestions.


Kind regards, Dejan M. www.alfasp.com
E-mail: xxxxx@alfasp.com ICQ#: 56570367
Alfa File Monitor - File monitoring library for Win32 developers.
Alfa File Protector - File protection and hiding library for Win32
developers.
Alfa Registry Monitor - Registry monitoring library for Win32
developers.
Alfa Registry Protector - Registry protection library for Win32
developers.


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

I use .cpp files in my driver, but only for the benefit of basic C++
features such as enhanced type-checking and inline functions. I’ve
written drivers in the past that made extensive use of C++ classes, but
came to the conclusion that C++ classes aren’t very convenient without
C++ exceptions (which you cannot use in drivers without some serious
hacking). If you insist on going this route anyways, there are various
newsgroup postings describing how to code up all of the weird directives
and library functions that you’ll need.

  • Nicholas Ryan

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-ntfsd-
xxxxx@lists.osr.com] On Behalf Of Dejan Maksimovic
Sent: Thursday, January 31, 2002 6:41 PM
To: File Systems Developers
Subject: [ntfsd] Using C++ in drivers

Little OT, but I think it’s appropriate.

I’m implementing transparent encryption filter, and would like to
use a C++ crypto library (Crypto++ namely).
Has anyone used C++ in their drivers before? I ask this, because I
a
few unresolved external errors (namely CxxFrameHandler and similar),
that are C++ specific, and I don’t know how to use these in Kernel
mode.

CrtDll.lib exports these, but this is a UM library (if I try to
link
with it, I get unresolved external for Sleep and GetVersion APIs:-)
I’d rather not use some 3rd party library, but I’m open for
suggestions.


Kind regards, Dejan M. www.alfasp.com
E-mail: xxxxx@alfasp.com ICQ#: 56570367
Alfa File Monitor - File monitoring library for Win32 developers.
Alfa File Protector - File protection and hiding library for Win32
developers.
Alfa Registry Monitor - Registry monitoring library for Win32
developers.
Alfa Registry Protector - Registry protection library for Win32
developers.


You are currently subscribed to ntfsd as: xxxxx@secretseal.com
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

It looks like your library uses exceptions, and as far as I know, nobody
has ported the msft C++ runtime support for exceptions into the kernel.
This looks like a non-starter to me.

=====================
Mark Roddy
Windows XP/2000/NT Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com
xxxxx@hollistech.com
For Windows Device Driver Training: see www.azius.com


You are currently subscribed to ntfsd as: xxxxx@hollistech.com To
unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

I also get unresolved external for “void __cdecl operator delete…”
I think I can get away from exceptions by just commenting try-catch and
throw calls, but what do I do about delete?

Regards, Dejan.

Mark Roddy wrote:

It looks like your library uses exceptions, and as far as I know, nobody
has ported the msft C++ runtime support for exceptions into the kernel.
This looks like a non-starter to me.

=====================
Mark Roddy
Windows XP/2000/NT Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com
xxxxx@hollistech.com
For Windows Device Driver Training: see www.azius.com


You are currently subscribed to ntfsd as: xxxxx@hollistech.com To
unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntfsd as: xxxxx@alfasp.com
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


Kind regards, Dejan M. www.alfasp.com
E-mail: xxxxx@alfasp.com ICQ#: 56570367
Alfa File Monitor - File monitoring library for Win32 developers.
Alfa File Protector - File protection and hiding library for Win32
developers.
Alfa Registry Monitor - Registry monitoring library for Win32 developers.
Alfa Registry Protector - Registry protection library for Win32 developers.


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Did you have problem with unresolved external for delete operator (I get
these, too:-)

Nicholas Ryan wrote:

I use .cpp files in my driver, but only for the benefit of basic C++
features such as enhanced type-checking and inline functions. I’ve
written drivers in the past that made extensive use of C++ classes, but
came to the conclusion that C++ classes aren’t very convenient without
C++ exceptions (which you cannot use in drivers without some serious
hacking). If you insist on going this route anyways, there are various
newsgroup postings describing how to code up all of the weird directives
and library functions that you’ll need.

  • Nicholas Ryan

> -----Original Message-----
> From: xxxxx@lists.osr.com [mailto:bounce-ntfsd-
> xxxxx@lists.osr.com] On Behalf Of Dejan Maksimovic
> Sent: Thursday, January 31, 2002 6:41 PM
> To: File Systems Developers
> Subject: [ntfsd] Using C++ in drivers
>
>
> Little OT, but I think it’s appropriate.
>
> I’m implementing transparent encryption filter, and would like to
> use a C++ crypto library (Crypto++ namely).
> Has anyone used C++ in their drivers before? I ask this, because I
a
> few unresolved external errors (namely CxxFrameHandler and similar),
> that are C++ specific, and I don’t know how to use these in Kernel
mode.
>
> CrtDll.lib exports these, but this is a UM library (if I try to
link
> with it, I get unresolved external for Sleep and GetVersion APIs:-)
> I’d rather not use some 3rd party library, but I’m open for
> suggestions.
>
> –
> Kind regards, Dejan M. www.alfasp.com
> E-mail: xxxxx@alfasp.com ICQ#: 56570367
> Alfa File Monitor - File monitoring library for Win32 developers.
> Alfa File Protector - File protection and hiding library for Win32
> developers.
> Alfa Registry Monitor - Registry monitoring library for Win32
> developers.
> Alfa Registry Protector - Registry protection library for Win32
> developers.
>
>
>
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@secretseal.com
> To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntfsd as: xxxxx@alfasp.com
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


Kind regards, Dejan M. www.alfasp.com
E-mail: xxxxx@alfasp.com ICQ#: 56570367
Alfa File Monitor - File monitoring library for Win32 developers.
Alfa File Protector - File protection and hiding library for Win32
developers.
Alfa Registry Monitor - Registry monitoring library for Win32 developers.
Alfa Registry Protector - Registry protection library for Win32 developers.


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

You have to roll your own new and delete. Not too hard, just steal the
declarations from various CRT header files and stick in ExAllocate* and
ExFreePool in the appropriate places.

  • Nicholas Ryan

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-ntfsd-
xxxxx@lists.osr.com] On Behalf Of Dejan Maksimovic
Sent: Thursday, January 31, 2002 8:04 PM
To: File Systems Developers
Subject: [ntfsd] RE: Using C++ in drivers

Did you have problem with unresolved external for delete operator
(I
get
these, too:-)

Nicholas Ryan wrote:

> I use .cpp files in my driver, but only for the benefit of basic C++
> features such as enhanced type-checking and inline functions. I’ve
> written drivers in the past that made extensive use of C++ classes,
but
> came to the conclusion that C++ classes aren’t very convenient
without
> C++ exceptions (which you cannot use in drivers without some serious
> hacking). If you insist on going this route anyways, there are
various
> newsgroup postings describing how to code up all of the weird
directives
> and library functions that you’ll need.
>
> - Nicholas Ryan
>
> > -----Original Message-----
> > From: xxxxx@lists.osr.com [mailto:bounce-ntfsd-
> > xxxxx@lists.osr.com] On Behalf Of Dejan Maksimovic
> > Sent: Thursday, January 31, 2002 6:41 PM
> > To: File Systems Developers
> > Subject: [ntfsd] Using C++ in drivers
> >
> >
> > Little OT, but I think it’s appropriate.
> >
> > I’m implementing transparent encryption filter, and would like
to
> > use a C++ crypto library (Crypto++ namely).
> > Has anyone used C++ in their drivers before? I ask this,
because I
> a
> > few unresolved external errors (namely CxxFrameHandler and
similar),
> > that are C++ specific, and I don’t know how to use these in Kernel
> mode.
> >
> > CrtDll.lib exports these, but this is a UM library (if I try
to
> link
> > with it, I get unresolved external for Sleep and GetVersion
APIs:-)
> > I’d rather not use some 3rd party library, but I’m open for
> > suggestions.
> >
> > –
> > Kind regards, Dejan M. www.alfasp.com
> > E-mail: xxxxx@alfasp.com ICQ#: 56570367
> > Alfa File Monitor - File monitoring library for Win32 developers.
> > Alfa File Protector - File protection and hiding library for Win32
> > developers.
> > Alfa Registry Monitor - Registry monitoring library for Win32
> > developers.
> > Alfa Registry Protector - Registry protection library for Win32
> > developers.
> >
> >
> >
> >
> >
> > —
> > You are currently subscribed to ntfsd as: xxxxx@secretseal.com
> > To unsubscribe send a blank email to
leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
> —
> You are currently subscribed to ntfsd as: xxxxx@alfasp.com
> To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


Kind regards, Dejan M. www.alfasp.com
E-mail: xxxxx@alfasp.com ICQ#: 56570367
Alfa File Monitor - File monitoring library for Win32 developers.
Alfa File Protector - File protection and hiding library for Win32
developers.
Alfa Registry Monitor - Registry monitoring library for Win32
developers.
Alfa Registry Protector - Registry protection library for Win32
developers.


You are currently subscribed to ntfsd as: xxxxx@secretseal.com
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

You could download my c++ kernel runtime library (source included.) It
covers global new and delete and initialization (ctor/dtor calling) of
global objects.

However I have a major problem with “I can get away from exceptions by
just commenting out…”. You can’t. These are error paths that have to
be handled. You have to re-write the library to be exception free.

=====================
Mark Roddy
Windows XP/2000/NT Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com
xxxxx@hollistech.com
For Windows Device Driver Training: see www.azius.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Dejan Maksimovic
Sent: Thursday, January 31, 2002 11:03 PM
To: File Systems Developers
Subject: [ntfsd] RE: Using C++ in drivers

I also get unresolved external for “void __cdecl operator delete…”
I think I can get away from exceptions by just commenting try-catch
and throw calls, but what do I do about delete?

Regards, Dejan.


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

> came to the conclusion that C++ classes aren’t very convenient without

C++ exceptions

I don’t see this at all. Only uses (I can think of) where lack of exceptions might feel inconvenient are for reporting errors from constructors, destructors and overloaded operators (which of course have no return code). Constructor failure is easily handled by defining an is_valid() method which caller must test. (And I would generally avoid copy constructors in drivers, to prevent “surprise” creation of temporary objects.) Destructors are typically written so as not to fail (so that invalid or partially constructed objects can be discarded). And operator overloads generally don’t belong in drivers (but, if needed, can be written to fail “gracefully”).

More to the point, the WinDK driver library (http://www.bsquare.com/products/devtools/windk/) generates C++ kernel drivers and supports exceptions. Product manual is a free download.

– Chris

----- Original Message -----
From: “Nicholas Ryan”
To: “File Systems Developers”
Sent: Thursday, January 31, 2002 6:54 PM
Subject: [ntfsd] RE: Using C++ in drivers

> I use .cpp files in my driver, but only for the benefit of basic C++
> features such as enhanced type-checking and inline functions. I’ve
> written drivers in the past that made extensive use of C++ classes, but
> came to the conclusion that C++ classes aren’t very convenient without
> C++ exceptions (which you cannot use in drivers without some serious
> hacking). If you insist on going this route anyways, there are various
> newsgroup postings describing how to code up all of the weird directives
> and library functions that you’ll need.
>
> - Nicholas Ryan
>
> > -----Original Message-----
> > From: xxxxx@lists.osr.com [mailto:bounce-ntfsd-
> > xxxxx@lists.osr.com] On Behalf Of Dejan Maksimovic
> > Sent: Thursday, January 31, 2002 6:41 PM
> > To: File Systems Developers
> > Subject: [ntfsd] Using C++ in drivers
> >
> >
> > Little OT, but I think it’s appropriate.
> >
> > I’m implementing transparent encryption filter, and would like to
> > use a C++ crypto library (Crypto++ namely).
> > Has anyone used C++ in their drivers before? I ask this, because I
> a
> > few unresolved external errors (namely CxxFrameHandler and similar),
> > that are C++ specific, and I don’t know how to use these in Kernel
> mode.
> >
> > CrtDll.lib exports these, but this is a UM library (if I try to
> link
> > with it, I get unresolved external for Sleep and GetVersion APIs:-)
> > I’d rather not use some 3rd party library, but I’m open for
> > suggestions.
> >
> > –
> > Kind regards, Dejan M. www.alfasp.com
> > E-mail: xxxxx@alfasp.com ICQ#: 56570367
> > Alfa File Monitor - File monitoring library for Win32 developers.
> > Alfa File Protector - File protection and hiding library for Win32
> > developers.
> > Alfa Registry Monitor - Registry monitoring library for Win32
> > developers.
> > Alfa Registry Protector - Registry protection library for Win32
> > developers.
> >
> >
> >
> >
> >
> > —
> > You are currently subscribed to ntfsd as: xxxxx@secretseal.com
> > To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@acm.org
> To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

> I don’t see this at all. Only uses (I can think of) where lack of

exceptions might feel inconvenient are for reporting errors from
constructors, destructors and overloaded operators (which of course
have
no return code).

Exactly. Part of the attraction of C++ for me was being able to write
code like:

CString s1, s2(“foo”), s3(“bar”);

s1 = s2 + “whatever” + s3;

Instead of like:

CString s1, s2(“foo”), s3(“bar”);

if (!s2.is_valid())
return s2.get_error();

if (!s3.is_valid())
return s3.get_error();

s1 = s2;

if (!s1.is_valid())
return s1.get_error();

and so on…

But if your library can support kernel-mode C++ exceptions, more power
to you.

Constructor failure is easily handled by defining an

is_valid() method which caller must test. (And I would generally
avoid
copy constructors in drivers, to prevent “surprise” creation of
temporary
objects.) Destructors are typically written so as not to fail (so
that
invalid or partially constructed objects can be discarded). And
operator
overloads generally don’t belong in drivers (but, if needed, can be
written to fail “gracefully”).

More to the point, the WinDK driver library
(http://www.bsquare.com/products/devtools/windk/) generates C++ kernel
drivers and supports exceptions. Product manual is a free download.

– Chris

----- Original Message -----
From: “Nicholas Ryan”
> To: “File Systems Developers”
> Sent: Thursday, January 31, 2002 6:54 PM
> Subject: [ntfsd] RE: Using C++ in drivers
>
>
> > I use .cpp files in my driver, but only for the benefit of basic C++
> > features such as enhanced type-checking and inline functions. I’ve
> > written drivers in the past that made extensive use of C++ classes,
but
> > came to the conclusion that C++ classes aren’t very convenient
without
> > C++ exceptions (which you cannot use in drivers without some serious
> > hacking). If you insist on going this route anyways, there are
various
> > newsgroup postings describing how to code up all of the weird
directives
> > and library functions that you’ll need.
> >
> > - Nicholas Ryan
> >
> > > -----Original Message-----
> > > From: xxxxx@lists.osr.com [mailto:bounce-ntfsd-
> > > xxxxx@lists.osr.com] On Behalf Of Dejan Maksimovic
> > > Sent: Thursday, January 31, 2002 6:41 PM
> > > To: File Systems Developers
> > > Subject: [ntfsd] Using C++ in drivers
> > >
> > >
> > > Little OT, but I think it’s appropriate.
> > >
> > > I’m implementing transparent encryption filter, and would like
to
> > > use a C++ crypto library (Crypto++ namely).
> > > Has anyone used C++ in their drivers before? I ask this,
because I
> > a
> > > few unresolved external errors (namely CxxFrameHandler and
similar),
> > > that are C++ specific, and I don’t know how to use these in Kernel
> > mode.
> > >
> > > CrtDll.lib exports these, but this is a UM library (if I try
to
> > link
> > > with it, I get unresolved external for Sleep and GetVersion
APIs:-)
> > > I’d rather not use some 3rd party library, but I’m open for
> > > suggestions.
> > >
> > > –
> > > Kind regards, Dejan M. www.alfasp.com
> > > E-mail: xxxxx@alfasp.com ICQ#: 56570367
> > > Alfa File Monitor - File monitoring library for Win32 developers.
> > > Alfa File Protector - File protection and hiding library for Win32
> > > developers.
> > > Alfa Registry Monitor - Registry monitoring library for Win32
> > > developers.
> > > Alfa Registry Protector - Registry protection library for Win32
> > > developers.
> > >
> > >
> > >
> > >
> > >
> > > —
> > > You are currently subscribed to ntfsd as: xxxxx@secretseal.com
> > > To unsubscribe send a blank email to
leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> >
> >
> >
> > —
> > You are currently subscribed to ntfsd as: xxxxx@acm.org
> > To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> >
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@secretseal.com
> To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

> More to the point, the WinDK driver library

(http://www.bsquare.com/products/devtools/windk/) generates C++ kernel
drivers and supports exceptions. Product >manual is a free download.
As far as I understand it is not “true” C++ exception but some sort of it’s
“imitation”. You can’t throw anything you want - only error code plus
message. That will be catched on regular _except hander. Anyway it is much
better than nothing :wink:

Vladimir


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

> You could download my c++ kernel runtime library (source included.) It

covers global new and delete and initialization (ctor/dtor calling) of
global objects.

Thanks, where from?

However I have a major problem with “I can get away from exceptions by
just commenting out…”. You can’t. These are error paths that have to
be handled. You have to re-write the library to be exception free.

Not really. The exception aren’t used in the encryption parts, and
plus
EVERY class that uses them has a bThrowException parameter, which if
FALSE
makes the components NOT throw exceptions, but return errors (so, I just
comment out the if(bThrowException) throw ExceptionCode)


Kind regards, Dejan M. www.alfasp.com
E-mail: xxxxx@alfasp.com ICQ#: 56570367
Alfa File Monitor - File monitoring library for Win32 developers.
Alfa File Protector - File protection and hiding library for Win32
developers.
Alfa Registry Monitor - Registry monitoring library for Win32
developers.
Alfa Registry Protector - Registry protection library for Win32
developers.


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Looks like you’re right. In fact, after reveiwing the doc, I see that the only exception support is from device object constructor (CDevice::ThrowStatusExceptionFromConstructor). And the WinDK CString implementation doesn’t throw exceptions on out-of-memory conditions, but requires caller to check IsEmpty(). I agree that exception support isn’t there, but I still think that other C++ features (encapsulation, inlining, overloading, delayed declaration, etc.) are very useful.

– CCP

----- Original Message -----
From: “Vladimir Ignatov” <100xCD@100xCD.com>
To: “File Systems Developers”
Sent: Friday, February 01, 2002 11:54 AM
Subject: [ntfsd] RE: Using C++ in drivers

> > More to the point, the WinDK driver library
> >(http://www.bsquare.com/products/devtools/windk/) generates C++ kernel
> drivers and supports exceptions. Product >manual is a free download.
> As far as I understand it is not “true” C++ exception but some sort of it’s
> “imitation”. You can’t throw anything you want - only error code plus
> message. That will be catched on regular _except hander. Anyway it is much
> better than nothing :wink:
>
> Vladimir
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@acm.org
> To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

I agree that error checking defeats the goal (convenience) of light-weight utility classes like your example. My point is only that C++ adds lots of value even without exceptions or operator overloading.

BTW, Vladimir Ignatov pointed out that WinDK only has limited exception support (CDevice ctor), though it does correctly unwind stack (including stack-bound objects). Since I opened my big mouth, let me suggest a solution for your CString problem.

Add a CString member variable to track error state, set error whenever memory allocation fails, check error state on all methods, and OR in the error state from rval CString args in overloaded boolean operators. Thus the error state would propogate, and you would only need test the final result after a series of operations. Something like this:

class CString {
bool _err;
PWCHAR buf;
public:
CString() : _err(false), buf(NULL) {;}
CString& operator=(const CString& rval) {
_err |= rval.err;
if (_err) return *this;
// …
}
bool is_valid() const {return !err;}
};

CString s1, s2(“foo”), s3(“bar”);

s1 = s2 + “whatever” + s3;

if (!s1.is_valid())
return out_of_mem;

This adds a little overhead to string operations, but probably no worse than exception frame overhead. HTH…

– Chris

----- Original Message -----
From: “Nicholas Ryan”
To: “File Systems Developers”
Sent: Friday, February 01, 2002 10:42 AM
Subject: [ntfsd] RE: Using C++ in drivers

> > I don’t see this at all. Only uses (I can think of) where lack of
> > exceptions might feel inconvenient are for reporting errors from
> > constructors, destructors and overloaded operators (which of course
> have
> > no return code).
>
> Exactly. Part of the attraction of C++ for me was being able to write
> code like:
>
> CString s1, s2(“foo”), s3(“bar”);
>
> s1 = s2 + “whatever” + s3;
>
> Instead of like:
>
> CString s1, s2(“foo”), s3(“bar”);
>
> if (!s2.is_valid())
> return s2.get_error();
>
> if (!s3.is_valid())
> return s3.get_error();
>
> s1 = s2;
>
> if (!s1.is_valid())
> return s1.get_error();
>
> and so on…
>
> But if your library can support kernel-mode C++ exceptions, more power
> to you.
>
> Constructor failure is easily handled by defining an
> > is_valid() method which caller must test. (And I would generally
> avoid
> > copy constructors in drivers, to prevent “surprise” creation of
> temporary
> > objects.) Destructors are typically written so as not to fail (so
> that
> > invalid or partially constructed objects can be discarded). And
> operator
> > overloads generally don’t belong in drivers (but, if needed, can be
> > written to fail “gracefully”).
> >
> > More to the point, the WinDK driver library
> > (http://www.bsquare.com/products/devtools/windk/) generates C++ kernel
> > drivers and supports exceptions. Product manual is a free download.
> >
> > – Chris
> >
> > ----- Original Message -----
> > From: “Nicholas Ryan”
> > To: “File Systems Developers”
> > Sent: Thursday, January 31, 2002 6:54 PM
> > Subject: [ntfsd] RE: Using C++ in drivers
> >
> >
> > > I use .cpp files in my driver, but only for the benefit of basic C++
> > > features such as enhanced type-checking and inline functions. I’ve
> > > written drivers in the past that made extensive use of C++ classes,
> but
> > > came to the conclusion that C++ classes aren’t very convenient
> without
> > > C++ exceptions (which you cannot use in drivers without some serious
> > > hacking). If you insist on going this route anyways, there are
> various
> > > newsgroup postings describing how to code up all of the weird
> directives
> > > and library functions that you’ll need.
> > >
> > > - Nicholas Ryan
> > >
> > > > -----Original Message-----
> > > > From: xxxxx@lists.osr.com [mailto:bounce-ntfsd-
> > > > xxxxx@lists.osr.com] On Behalf Of Dejan Maksimovic
> > > > Sent: Thursday, January 31, 2002 6:41 PM
> > > > To: File Systems Developers
> > > > Subject: [ntfsd] Using C++ in drivers
> > > >
> > > >
> > > > Little OT, but I think it’s appropriate.
> > > >
> > > > I’m implementing transparent encryption filter, and would like
> to
> > > > use a C++ crypto library (Crypto++ namely).
> > > > Has anyone used C++ in their drivers before? I ask this,
> because I
> > > a
> > > > few unresolved external errors (namely CxxFrameHandler and
> similar),
> > > > that are C++ specific, and I don’t know how to use these in Kernel
> > > mode.
> > > >
> > > > CrtDll.lib exports these, but this is a UM library (if I try
> to
> > > link
> > > > with it, I get unresolved external for Sleep and GetVersion
> APIs:-)
> > > > I’d rather not use some 3rd party library, but I’m open for
> > > > suggestions.
> > > >
> > > > –
> > > > Kind regards, Dejan M. www.alfasp.com
> > > > E-mail: xxxxx@alfasp.com ICQ#: 56570367
> > > > Alfa File Monitor - File monitoring library for Win32 developers.
> > > > Alfa File Protector - File protection and hiding library for Win32
> > > > developers.
> > > > Alfa Registry Monitor - Registry monitoring library for Win32
> > > > developers.
> > > > Alfa Registry Protector - Registry protection library for Win32
> > > > developers.
> > > >


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

> You could download my c++ kernel runtime library (source included.) It

covers global new and delete and initialization (ctor/dtor calling) of

global objects.

Thanks, where from?

I guess I should have been more explicit.

=====================
Mark Roddy
Windows XP/2000/NT Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com <====================== DOWNLOAD FROM HERE
xxxxx@hollistech.com
For Windows Device Driver Training: see www.azius.com


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

> Thanks, where from?

I guess I should have been more explicit.

Sorry - figured later:-)


Kind regards, Dejan M. www.alfasp.com
E-mail: xxxxx@alfasp.com ICQ#: 56570367
Alfa File Monitor - File monitoring library for Win32 developers.
Alfa File Protector - File protection and hiding library for Win32
developers.
Alfa Registry Monitor - Registry monitoring library for Win32
developers.
Alfa Registry Protector - Registry protection library for Win32
developers.


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

> Exactly. Part of the attraction of C++ for me was being able to write

code like:

CString s1, s2(“foo”), s3(“bar”);

s1 = s2 + “whatever” + s3;

Now imagine pool fragmentation from this.

Max


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

In MSJ magazine there was an article and example of C++ “Device Driver
wrapper class library” written by two Intel engineers. They used Visual C++
4.1, so you could find something useful there. Here is the link
www.microsoft.com/msj/backissues96.asp and the MSJ issue was “MSJ September
1996 Vol. 11 No.9”
Wbr Primoz

-----Original Message-----
From: Dejan Maksimovic [mailto:xxxxx@alfasp.com]
Sent: Friday, February 01, 2002 3:41 AM
To: File Systems Developers
Subject: [ntfsd] Using C++ in drivers

Little OT, but I think it’s appropriate.

I’m implementing transparent encryption filter, and would like to
use a C++ crypto library (Crypto++ namely).
Has anyone used C++ in their drivers before? I ask this, because I a
few unresolved external errors (namely CxxFrameHandler and similar),
that are C++ specific, and I don’t know how to use these in Kernel mode.

CrtDll.lib exports these, but this is a UM library (if I try to link
with it, I get unresolved external for Sleep and GetVersion APIs:-)
I’d rather not use some 3rd party library, but I’m open for
suggestions.


Kind regards, Dejan M. www.alfasp.com
E-mail: xxxxx@alfasp.com ICQ#: 56570367
Alfa File Monitor - File monitoring library for Win32 developers.
Alfa File Protector - File protection and hiding library for Win32
developers.
Alfa Registry Monitor - Registry monitoring library for Win32
developers.
Alfa Registry Protector - Registry protection library for Win32
developers.


You are currently subscribed to ntfsd as: xxxxx@hermes.si
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com