Click here to Skip to main content
15,894,630 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My development tool is VS2010, development language is C#, and operating system is WINDOWS7 64-bit. I need to call interface functions of COM service (OPC DA Automation Wrapper 2.02) in my windows service application, while the COM service and windows service are on the same computer. It turns out that calling some of the COM interface functions successes, but some have errors(System.Runtime.InteropServices.COMException was caught).

errors is:
System.Runtime.InteropServices.COMException was caught
Message=Exception from HRESULT: 0xC0040007
Source=GWOPC.NET
ErrorCode=-1073479673


I created a normal application(not a windows service program) to call the COM service, there was no problem. So I think the problem is due to using of windows service, and I suspect are some permission setting problem of windows service. Then I tried these steps:
1. I log in my computer using an administrator account.
2. In the windows service properties -> Log On tab, select "Local System account" by default.
3. Run my windows service application to call COM interface functions, error exists.
4. In the windows service properties -> Log On tab, select "This Account" and enter a user name and password (the user is an administrator).
5. Run my windows service application to call COM interface functions, the error still exists.

Same code, the general application(e.g. EXE) call, there will be no errors. Only in the service call, will have errors.
Posted
Updated 24-Jun-11 15:11pm
v7
Comments
JV9999 23-Jun-11 7:07am    
I would rephrase your question, because after reading it 10 times I still don't get it what you want from us...
Richard MacCutchan 24-Jun-11 4:59am    
What is the exception you receive? without that information it will be quite difficult to figure out your problem.
szbc99 24-Jun-11 6:12am    
errors is:
System.Runtime.InteropServices.COMException was caught
Message=Exception from HRESULT: 0xC0040007
Source=GWOPC.NET
ErrorCode=-1073479673
Richard MacCutchan 24-Jun-11 8:55am    
http://msdn.microsoft.com/en-us/library/dd542643(VS.85).aspx

CO_E_INIT_SHARED_ALLOCATOR
0x80004007
Get shared memory allocator failure
szbc99 24-Jun-11 21:10pm    
Same code, the general application(e.g. EXE) call, there will be no errors. Only in the service call, will have errors.

1 solution

It sounds like you are attempting to call some COM functionality from within a windows service. By default, the service will run in a highly locked down account - what you need to do is create an account (with a strong password), for the service to run in. Give it appropriate privileges (such as access the registry), and it should be able to work.
 
Share this answer
 
Comments
fjdiewornncalwe 23-Jun-11 10:24am    
Agreed, but as an addition: If the code is capable of executing some of the COM methods, but not others, then it could be that his call arguments are not being formatted correctly in the calls. (Assuming that the COM methods work at all).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900