Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
End Users
Pocket PCActiveSyncMultimediaEBooksWirelessSmartPhones
Developers
Windows MobileSmartPhonesWinCE ProgrammingVB for WinCEVC++ for WinCEPlatform BuilderTest Tools
PocketPC DirectoryFree SoftwareWeb Resources
Related Topics
PalmMobile PhonesMore Topics ...

Pocket PC Forum / Developers / VC++ for WinCE / October 2008

Tip: Looking for answers? Try searching our database.

(Re)throwing from a catch block across dll boundaries

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hansjoergp - 29 Sep 2008 11:57 GMT
Hello there,

I am using VS 2008, SP1 in order to create applications for WM 5.0 +. The
applications are written in C++, no MFC is used.
I have a function in a dll that throws an exception of type class CEx. It
catches a reference to this exception, does some cleanup work and then
rethrows the exception. When calling this function from a different dll or
the main executable the application will crash, saying that the exception is
unhandled although the function call is properly enclosed in a try/catch
block.
Some additional points:
* If the called function does not catch and rethrow, the behaviour is as
expected (i.e. the application remains stable)
* If the thrown exception has a simple type like int, the behaviour is as
excpected
* If I move the called function into the calling dll or exe, the behaviour
is as expected
* If new is used to allocate the exception object and pointers to the
exception are caught, the application crashes as well
* If I explicitly rethrow the reference to the exception in the throwing
function then it works well, however a second call and throw makes the
application 'hang' and the debugger says that it cannot stop the debugging
session in the emulator

Steps to reproduce (platform: WM 5.0 or 6.0):
1) Create a WIN32 smart device console application
2) Create a WIN32 smart device dll, checking 'export symbols'. This will
create an exported class and an exported function in the dll
3) Add the member int  m_nCode to the created class and change the
constructor so that the code can be passed and set on construction
4) Throw an object of the class from the exported function, enclosing the
throw in a try/catch block. catch a reference to the exception (but without a
variable name) and do a rethrow
5) include the dll's header file into the application file
6) from _tmain call the exported function, enclosed in a try/catch block
7) make the application dependent on the dll
8) build and run in the emulator
9) the application crashes

Can anybody confirm this? What could be the reason?
The test solution can be supplied if necessary.
Many thanks
Leonard Mosescu [MS] - 30 Sep 2008 18:17 GMT
I can't reproduce the issue, see the attached fiels (dll.cpp will compile to
dll.dll, test.cpp to test.exe, test.h is common). Please try this sample and
let me know if you're still seeing the issues. The full command lines I
used, for reference, are:

1. cl -Zi -LD -EHsc dll.cpp -link -nodefaultlib corelibc.lib
coredll.lib -subsystem:windowsce -entry:_DllMainCRTStartup
2. cl -Zi -EHsc test.cpp dll.lib -link -nodefaultlib corelibc.lib
coredll.lib -subsystem:windowsce -entry:mainCRTStartup

If you can reproduce the problems, even if you have to change the attached
files please let me know.

Also, exposing C++ interfaces across module boundaries is not a good idea in
general, I'd suggest exposing a C or COM based interface from your DLL.

Thank you,
Leonard.

> Hello there,
>
[quoted text clipped - 40 lines]
> The test solution can be supplied if necessary.
> Many thanks
hansjoergp - 01 Oct 2008 09:01 GMT
Hi Leonard,

thank you for the answer. Unfortunately I do not know how to get the
attached files. It seems to me that I would not be able to attach files
either. Is there an alternative channel to do this?

Thank you

Hansjoerg

> I can't reproduce the issue, see the attached fiels (dll.cpp will compile to
> dll.dll, test.cpp to test.exe, test.h is common). Please try this sample and
[quoted text clipped - 59 lines]
> > The test solution can be supplied if necessary.
> > Many thanks
Paul G. Tobey [eMVP] - 01 Oct 2008 16:46 GMT
If you have a 'real' NNTP newsreader, even Outlook Express, you'll see the
attachments, just as you would if he sent you an email.

Paul T.

> Hi Leonard,
>
[quoted text clipped - 86 lines]
>> > The test solution can be supplied if necessary.
>> > Many thanks
Leonard Mosescu [MS] - 02 Oct 2008 16:12 GMT
Please try a different newsreader client like Paul suggested, or send me an
email directly if that's not going to work for you.

> Hi Leonard,
>
[quoted text clipped - 86 lines]
>> > The test solution can be supplied if necessary.
>> > Many thanks
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.