I have a C# program that at some point calls 2 functions from an unmanaged dll using p/invoke. Everything works fine when I'm running in a console app. When I compile the same program as a windows service and run it, it crashes.
The console app and service should be identical as far as my code is concerned... all either program does is create an object from another assembly of mine and run a Start() method on it.
I have used VS2010 to debug the managed and unmanaged code, and when I step through the Console app everything looks great. When I attach the debugger to the service, i can step through the first function in the unmanaged
code, control returns to the managed code, and then later when it comes to the point where it calls the second unmanaged function, the process terminates immediately before the debugger steps into the first line of unmanaged code. There are no exceptions
that I can see, and the only thing written to the event log is the generic "service terminated unexpectedly" message. Running "sc query" on the command line lets me know the win32_exit_code is 1067.
Im running everything in .net 4, on winxp 32bit. The serivce is running as Local System ideally, but the same behavior exists when I run it under my user account.
View Complete Post